spring - Mockito with static methods in util classes -
i tried find couldnt looking for. possible following in mockito?
when(testserviceutil.gettestitem()).thenreturn(someitem);
in pom.xml, add following dependencies:
<dependency> <groupid>org.powermock</groupid> <artifactid>powermock-module-junit4</artifactid> <version>1.5.6</version> <scope>test</scope> </dependency> <dependency> <groupid>org.powermock</groupid> <artifactid>powermock-api-mockito</artifactid> <version>1.5.6</version> <scope>test</scope> </dependency>
above test class: @runwith(powermockrunner.class) public class yourclassname
[...] @before public void beforetest() throws sqlexception { powermockito.mockstatic(testserviceutil.class);
now can use (as had it): when(testserviceutil.gettestitem()).thenreturn(someitem);
last words - don't overuse powermockito. focus on clean, object oriented code.
Comments
Post a Comment