EasyMock : java.lang.IllegalStateException: 1 matchers expected, 2 recorded -


i having problem easymock 2.5.2 , junit 4.8.2 (running through eclipse). have read similar posts here have not found answer. have class containing 2 tests test same method. using matchers.

  1. each test passes when run alone.
  2. the first test passes - true if switch order of tests in file.

here simplified version of test code:

private xthing mockxthing; private mainthing mainthing;  @before public void setup() {     mockxthing = easymock.createmock(xthing.class);     mainthing = new mainthing();     mainthing.setxthing(mockxthing); }  @after public void cleanup() {     easymock.reset(mockxthing); }  @test public void testtwo() {     string abc = "abc";     easymock.expect(mockxthing.doxthing((string) easymock.anyobject())).andreturn(abc);     easymock.replay(mockxthing);     string testresult = mainthing.testcallingxthing((long) easymock.anyobject());     assertequals("abc", testresult);     easymock.verify(mockxthing); }  @test public void testone() {     string xyz = "xyz";     easymock.expect(mockxthing.doxthing((string) easymock.anyobject())).andreturn(xyz);     easymock.replay(mockxthing);     string testresult = mainthing.testcallingxthing((long) easymock.anyobject());     assertequals("xyz", testresult);     easymock.verify(mockxthing); } 

the second (or last) test fails following error:

java.lang.illegalstateexception: 1 matchers expected, 2 recorded 

any insight appreciated.

thanks, anne

i haven't looked meticulously closely yet, looks suspect:

string testresult = mainthing.testcallingxthing((long) easymock.anyobject()); 

anyobject() matcher , you're calling after replay. it's not used produce object. it's used instruct easymock allow object. easymock detecting matcher not harmful until second test. @ point, number of matchers easymock has recorded hasn't yet used (2) doesn't line number of parameters expected second doxthing call (1).

you should passing in real parameters testcallingxthing (or mock in replay mode). try passing in null directly, or real value 2.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -