This is my class:
public class Service {
@Autowired
Class1 class1;
public String method1 (){
Class2 class2= class1.anotherMethod(s1, s2) //Both String. **Error Line**
//Do something
return result //Returns a string based on something
}
}
I have mocked it in my TestClass like:
Class2 class2= new Class2();
Class1 class1 = new Class1();
Class1 class1Spy = PowerMockito.spy(class1);
PowerMockito.doReturn(class2).when(class1Spy, "anotherMethod", Mockito.anyString(), Mockito.anyString());
Now when I call method1 it is throwing NullPointerException in the line mentioned as 'Error Line'. Can anyone help me? I guess I am passing the parameters in Powermockito.doReturn in a wrong way.
Aucun commentaire:
Enregistrer un commentaire