junit - java.lang.IllegalArgumentException: Not a mock: java.lang.Class on PowerMock and EasyMock -
i have test case using powermock test on static method math, as
@runwith(powermockrunner.class) @preparefortest( { math.class }) public class test{ @test public void test2(){ powermockito.mockstatic(math.class); easymock.expect(math.abs(-123)).andreturn(1); easymock.replay(math.class); long returns = math.abs(-123); easymock.verify(math.class); org.junit.assert.assertequals(1,returns); } }
my pom.xml looks as
<dependency> <groupid>org.mockito</groupid> <artifactid>mockito-all</artifactid> <version>${mockito.version}</version> <scope>test</scope> </dependency> <dependency> <groupid>org.easymock</groupid> <artifactid>easymock</artifactid> <version>3.3.1</version> </dependency> <dependency> <groupid>org.powermock</groupid> <artifactid>powermock-api-mockito</artifactid> <version>1.6.2</version> <scope>test</scope> </dependency> <dependency> <groupid>org.powermock</groupid> <artifactid>powermock-module-junit4</artifactid> <version>1.6.2</version> <scope>test</scope> </dependency>
and got error as
java.lang.illegalargumentexception: not mock: java.lang.class @ org.easymock.internal.mockscontrol.getcontrol(mockscontrol.java:175) @ org.easymock.easymock.getcontrol(easymock.java:2130) @ org.easymock.easymock.replay(easymock.java:2032)
this first time i'm using powermock, want try test static method, , choose java math class test. think have done parts in instructions https://code.google.com/p/powermock/wiki/mockstatic
what's wrong test case?
instead of using easymock, use mockito replace it, code as
powermockito.mockstatic(math.class); mockito.when(math.abs(-123)).thenreturn(1); int returns = math.abs(-123);
this code working fine me in java 7, in java 8, fails
Comments
Post a Comment