• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes

Problem :

I am getting bellow error while executing JUNIT code
java.lang.illegalstateexception no last call on a mock available
by (6.9k points)  

1 Answer

0 votes

Solution :

Did you annotate the test class with @RunWith(PowerMockRunner.class) and @PrepareForTest(CommandLineOptionProcessor.class)? 

@RunWith(PowerMockRunner.class) @PrepareForTest(CommandLineOptionProcessor.class) public class TestClass { 

 @Test public void testRun()


Pease note you will need the @PrepareForTest(CommandLineOptionProcessor.class) at the test class level.

Use the @PrepareForTest(ClassThatContainsStaticMethod.class) annotation at the class-level of the test case.

Also please ensure that the required libraries are on the test classpath.

In your case the javassist library is missing. 

Please put it on the classpath. 

If you get

java.lang.IllegalArgumentException: Not a mock: java.lang.Class

then you must be using EasyMock.replay(), 

but you must use PowerMock.replay()

After following all above mentioned steps my issue got resolved.

by (36.1k points)