• Register
0 votes

Problem :

I am getting bellow error while executing JUNIT code
java.lang.illegalstateexception no last call on a mock available
6 5 3
6,930 points

Please log in or register to answer this question.

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.

9 7 4
38,600 points

Related questions

0 votes
1 answer 17 views
Any ideas on what could be causing this would be great.
asked Jan 24 TeamScript 13.5k points
0 votes
2 answers 5K 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 1.5K 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, 2020 jwilliam 3.9k points
0 votes
1 answer 3 views
Problem: invalid setup on a non-virtual (overridable in vb) member.
asked 1 day ago Dan phillip 1.8k points
0 votes
1 answer 7 views
problem java.lang.illegalstateexception: already managing a googleapiclient with id 0
asked Feb 9 charles mathews 3.8k points
0 votes
1 answer 68 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 7 views
Problem: I google the error message getOutputStream() has already been called for this response and many people said it is because of the space or newline after <% or %>, but in my code , there is no a space or a newline. I am using tomcat6 on linux.
asked 6 days ago Ali 4.3k points
0 votes
1 answer 10 views
Problem: public int getRecordsCount() { String countQuery = "SELECT * FROM " + TABLE_LOGIN; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); if(cursor != null && !cursor.isClosed()){ cursor.close(); } / ... with java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT * FROM login)
asked Feb 8 ahmedadel9090 2.6k points
0 votes
1 answer 7 views
The mess is with the second part of the program.
asked Feb 8 TeamScript 13.5k points
0 votes
1 answer 64 views
i got this error and was unable to solve it. Please help me with this.  //// Exception in thread "main" java.util.NoSuchElementException       at java.util.Scanner.throwFor(Scanner.java:862)       at java.util.Scanner.next( ...                     }                 }             }             System.out.println("The first distribution for students among the available sections");           }
asked Oct 2, 2020 sara s 120 points