jeudi 9 juillet 2020

NullpointerException mocking the test

I have a problem mocking the test, everything goes correct till this point of the code/test which i get a nullpointerexception, this is the main code where launchs the null pointer.

ResponseSrvAddDto responseSrvAdd = kjidR048.executeAddDocuments(requestAdd);
        
String returnCode = responseSrvAdd.getReturnCode();
if (returnCode != null && "00".equals(returnCode)){
ERROR! java.lang.NullPointerException

I have this in the test

ResponseSrvAddDto responseSrvAdd = mock(ResponseSrvAddDto.class);

Mockito.when(kjidR048.executeAddDocuments(requestAdd)).thenReturn(responseSrvAdd); (this goes correct)
String code = "00";
Mockito.when(responseSrvAdd.getReturnCode()).thenReturn(code); 

(but this looks like ignores the mock)

I dont know why having the mock in the responseSrvAdd.getReturnCode() launchs a null pointer but i have this already mocked.

Aucun commentaire:

Enregistrer un commentaire