It's not a secret anymore!*
The moose likes Testing and the fly likes Easy Mock Test Case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Easy Mock Test Case" Watch "Easy Mock Test Case" New topic
Author

Easy Mock Test Case

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1372
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

Joined: Feb 26, 2001
Posts: 4458
    
    6

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.


Junilu - [How to Ask Questions] [How to Answer Questions]
tom kalafut
Greenhorn

Joined: Dec 03, 2012
Posts: 1
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.
 
subject: Easy Mock Test Case