With PowerMock, you can mock designers. See example
I'm not with an IDE right now, but there will be something like this:
UserQueries userQueries = PowerMockito.mock(UserQueries.class); PowerMockito.whenNew(UserQueries.class).withArguments(Mockito.any(CrudService.class)).thenReturn(userQueries);
You need to run the test using PowerMockRunner (add these annotations to the test class):
@RunWith(PowerMockRunner.class) @PrepareForTest(UserQueries .class)
If you cannot use PowerMock, you need to enter factory as it says @Briggo's answer.
Hope this helps
source share