File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Easy Mock Test Case

 
kri shan
Ranch Hand
Posts: 1453
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got folowing EasyMock exception.

[testng] java.lang.IllegalStateException: matcher calls were used outside expectations
[testng] at org.easymock.internal.RecordState.replay(RecordState.java:84)
[testng] at org.easymock.internal.MocksControl.replay(MocksControl.java:97)
[testng] at org.easymock.EasyMock.replay(EasyMock.java:1540)
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you have a specific question about this? IllegalStateException usually means you need to ensure certain pre-conditions exist before calling a method on an object. Go to the JavaDocs for the class/method that's throwing the exception to see what those pre-conditions are.
 
tom kalafut
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception is reported on the call to replay(), but it's caused by a matcher outside of an expectation. How can I determine where the problem is?

I re-read my code several times to make sure that every void return method called on a mock object with matchers is followed by an expectLastCall(). Example:

payment.setAuthKey(eq(42));
expectLastCall();
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic