public class MyService {
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getData(@QueryParam("job") String job, @QueryParam("name") String name)
{
//Some Validations
JsonData jsonData = MyStaticClass.doValidate(request, value);
//Other Block of Code
}
}
I don't want to make a call to MyStaticClass.doValidate(request,value); but I want to call getData Method and when it encounters doValidate call it has to just return a custom object, as intended below in the test...
@PrepareForTest({MyService.class,MyStaticClass.class})
@RunWith(PowerMockRunner.class)
public class MyServiceTest {
JsonData data = null;
@Before
public void setUp() throws Exception {
data = new JsonData();
data.setBatch_label("My_Batch_Label");
//Other setters are called
}
@Test
public void test(){
MyService service = new MyService();
PowerMockito.mockStatic(MyStaticClass.class);
Mockito.when(MyStaticClass.doValidate(Mockito.any(Request.class), Mockito.anyString())).thenReturn(data);
PowerMockito.verifyStatic();
Response response = service.getData("My_Job", "My_Name");
}
When I run the test I get Wanted but not invoked xxxxx
Actually, there were zero interactions with this mock.
at org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl.performIntercept(MockitoMethodInvocationControl.java:262)
at org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl.invoke(MockitoMethodInvocationControl.java:190)
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:124)
at org.powermock.core.MockGateway.methodCall(MockGateway.java:63)
Any Help would really appreciate.
Thanks,
Tam
Likely need to change “Mockito.when” to “PowerMockito.when”.
Also, you posted this to the Mockito mailing list. Although PowerMock is compatible with Mockito, this is a PowerMock question. Questions about PowerMock should be directed to the PowerMock mailing list.
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mockito/ab4f82e9-204d-44fc-a911-129c3a9efd5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.