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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -