junit - java.lang.IllegalStateException: no last call on a mock available with 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.illegalstateexception: no last call on mock available     @ org.easymock.easymock.getcontrolforlastcall(easymock.java:559)     @ org.easymock.easymock.expect(easymock.java:537) 

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?

you mixing lot of things here. first, easymock , mockito 2 different things. powermock (which used easymock) , powermockito (which used mockito). i'll stick easymock here.

from there, when using powermock, create, replace , verify done powermock. reason passing class it, not , object. easymock won't that.

here working code:

@runwith(powermockrunner.class) @preparefortest( { math.class }) public class mathtest {      @test     public void test2(){         powermock.mockstatic(math.class);         easymock.expect(math.abs(-123)).andreturn(1);         powermock.replay(math.class);         long returns = math.abs(-123);         powermock.verify(math.class);         assertequals(1, returns);     } } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -