I need your assistance please:
I have this method:
public class MyTestClass {
protected void foo(JSONObject result, String text){
String userId = result.optString("name");
mApi.sendInfo(userId, text, mListener);
}
}
In Mockito I do:
@Test
public void whenFooIsCalledThenSendInfoGetsCalled(){
MyTestClass testClassSpy = spy(mMyTestClass);
JSONObject jsonOb = mock(JSONObject.class);
when(jsonOb.optString("name")).thenReturn("something");
testClassSpy.foo(eq(jsonOb), anyString());
....
some verification....
The problem is, the when the foo method gets called, JSONObject result is null. I can't seem to get this to work. I thought that if I mock the object and make it return a String once optString("name") is called, would solve this issue but it seems NPE is all I get. What am I doing wrong?
Thanks you