I use mockito as a mocking structure. I have a scenerio here, mine when (abc.method ()). ThenReturn (value) does not return a value, instead returns null.
This is what my class and test look like.
public class foo(){
public boolean method(String userName) throws Exception {
ClassA request = new ClassA();
request.setAbc(userName);
ClassB response = new ClassB();
try {
response = stub.callingmethod(request);
} catch (Exception e) {
}
boolean returnVal = response.isXXX();
return returnVal;
}
Now the next test is
@Test
public void testmethod() throws Exception{
String userName = "UserName";
ClassA request = new ClassA();
ClassB response = new ClassB();
response.setXXX(true);
when(stub.callingmethod(request)).thenReturn(response);
boolean result = fooinstance.lockLogin(userName);
assertTrue(result);
}
stub mocks using mockito using @Mock. The test throws a NullPointerException in the foo class near boolean retrunVal = response.isXXX ();
source
share