jeudi 6 août 2020

Mockito spy: Trying to use doReturn in spy class method but is using original method

I have a class EvaluationUtil.java.

I have a method

protected List<LoanDemandList> someMethod(List<String> argList, String data);

now in unit test, I want to return a particular value when this method is called.

so i did:

doReturn(loanDemandDetails)
       .when(evaluationUtil)
       .someMethod(ArgumentMatchers.<String>anyList(), anyString());

i mocked evaluation util like this

evaluationUtil = spy(new EvaluationOperationUtil());

but whenever i call this method , it goes inside the method and it crashes, shouldnt it just return loanDemandDetails and not look inside the method???

Aucun commentaire:

Enregistrer un commentaire