powermockito - Wanted but not invoked: There were zero interactions with this mock -
i stuck issue whole day. tried many resources , debug features no luck.
can guys please me.
public class data{ datadriver datadriver; // datadriver different class have injected. connector connector; // connector different class injecting in data class. // constructor , setter methods public void read(){ closeablehttpclient client = httpclients.createdefault(); hashmap<string, string> credentials = datadriver.run(new date()); httpget = connector.execute(client,credentials); } }
for test class, using powermockito, httclients.createdefault()
static method.
@contextconfiguration(locations = { "classpath:/xxx.xml" }) @runwith(powermockrunner.class) public class datatest { data mockeddata; @mock connector mockedconnector; @mock datadriver mockeddatadriver; @mock closeablehttpclient mockedclient; @before public void setup() { mockitoannotations.initmocks(data.class); mockeddata =new data(); powermockito.mockstatic(httpclients.class); mockeddata.setconnector(mockedconnector); mockeddata.setdatadriver(mockeddatadriver); } @test @preparefortest({ httpclients.class }) public void testread(){ hashmap<string, string> credentials = new hashmap<string, string>(); powermockito.when(httpclients.createdefault()).thenreturn(mockedclient); powermockito.when(mockeddatadriver.run(newdate())).thenreturn(credentials); powermockito.when(mockedconnector.execute(mockedclient,credentials)).thenreturn(new httpget()); verify(mockedconnector, atleastonce()).execute(mockedclient, credentials); } }
it says 0 interactions connector mock. not complaining on datadriver mock. tried debugging , able see both mock objects in data class. not going execute funtion of connector.
any advise on doing wrong?
thank you
Comments
Post a Comment