java - Mockito: stubbing a method with a class argument, not behaving as expected -
i have class delegates http call third party library:
public class httpservice { gson gson = new gson(); public <t> t fromjson(string json, class<t> classoft) { return gson.fromjson(json, classoft); } }
i trying stub fromjson method, so:
exampleobject exampleobject = new exampleobject("value1", "value2"); httpservice _testhttpservice = mockito.mock(httpservice.class); mockito.when(_testhttpservice.fromjson(matchers.anystring(), matchers.eq(exampleobject.class))).thenreturn(exampleobject);
now when call fromjson method mocked httpservice object so...
exampleobject obj = _testhttpservice.fromjson("blahblahblah" , exampleobject.class);
...a value of null assigned obj. why this? trying exampleobject returned. have tried several different matcher methods send in class argument mocked constructor (i.e. in addition matchers.eq(), have tried matchers.same(), , few others). insight appreciated!
Comments
Post a Comment