• Register
Log In
0 votes

Problem :

I am getting bellow error while executing JUNIT code
java.lang.illegalstateexception no last call on a mock available
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.

36.1k points

Related questions

0 votes
2 answers 491 views
Problem : When I try to run my Maven Spring project as JUnit i get bellow error java.lang.illegalstateexception: failed to load applicationcontext
asked Nov 2, 2019 peterlaw 6.9k points
0 votes
1 answer 419 views
Problem : I am trying to pass the values from the servlet to jsp page But when I run the page I am facing below error: Error as below : java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed org.apache.catalina.connector. ... getRequestDispatcher("usertaskpage.jsp"); dd.forward(request, response); But still I got a same error. How can I fix above error?
asked Feb 3 jwilliam 3.9k points
0 votes
1 answer 39 views
Problem : I am trying to run Java Applet and getting bellow error. java.lang.illegalstateexception: failed to create a child event loop
asked Oct 31, 2019 peterlaw 6.9k points
0 votes
1 answer 130 views
Problem : I am trying to learn Android programming also I am trying to develop a very basic weather app. My code works perfectly if I try to enter any valid city name. But I want to use the toast and it shows me the error and also to the ... .nextCleanInternal(JSONTokener.java:116) at org.json.JSONTokener.nextValue(JSONTokener.java:94) at org.json.JSONObject. How can I fix the above error?
asked Feb 14 mphil 2.3k points
0 votes
1 answer 23 views
Problem : Now a days I am learning Android Programming. I am facing below error message while trying to implement the logout functionality for the Google Sign-In for the Android: “Caused by: java.lang.IllegalStateException: GoogleApiClient is not ... .getInstance().getClient(); Auth.GoogleSignInApi.signOut(myGoogleApiClient); } I am struggling to find solution on it since yesterday.
asked Feb 27 mphil 2.3k points