tag:blogger.com,1999:blog-2664528635822406543.post6592617893489658911..comments2023-05-17T19:00:04.398+10:00Comments on IMHO: EasyMock2 quirk...Alex Weihttp://www.blogger.com/profile/16196507572911120081noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-2664528635822406543.post-13724838754781196552012-05-15T08:09:43.144+10:002012-05-15T08:09:43.144+10:00This has to do with using an argument matcher outs...This has to do with using an argument matcher outside of EasyMock context<br /><br />http://jira.codehaus.org/browse/EASYMOCK-38Cartahttps://www.blogger.com/profile/00817169630811524549noreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-83623867796095548282011-01-06T02:59:57.583+11:002011-01-06T02:59:57.583+11:00i have a similar unsolved problem.
my mock statem...i have a similar unsolved problem.<br /> my mock statement is :<br />EasyMock.expect(slotManager.addSlotPageletBinding(EasyMock.isA(String.class), EasyMock.isA(String.class), EasyMock.isA(helloWorld.class))).andReturn(true);<br /><br />this causes:<br />3 matchers expected, 4 recorded.<br /><br />Not able find the problem.<br /> before this statement i have the mock for the overloaded method as:<br />EasyMock.expect(slotManager.addSlotPageletBinding(EasyMock.isA(String.class),EasyMock.isA(String.class))).andReturn(true).anyTimes();Jameshttps://www.blogger.com/profile/07699642086472503703noreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-13266632242481142442010-09-21T17:54:02.249+10:002010-09-21T17:54:02.249+10:00Thanks! Just ran into this issue.Thanks! Just ran into this issue.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-83986573427290739712010-04-30T20:23:16.077+10:002010-04-30T20:23:16.077+10:00After so long, your solution is still helping! Tha...After so long, your solution is still helping! Thanks very much!!!Ramónhttp://www.myspace.com/killemdrumsnoreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-70929393064906156312009-02-05T20:13:00.000+11:002009-02-05T20:13:00.000+11:00This comment has been removed by a blog administrator.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-27719250287545564002008-09-30T01:13:00.000+10:002008-09-30T01:13:00.000+10:00Tomas, trymock.methodName((MyOtherObject)isNull(),...Tomas, try<BR/><BR/>mock.methodName((MyOtherObject)isNull(), isA(MyObject.class));<BR/><BR/>All, <BR/><BR/>I also have the same problem as the poster that has more recorded matchers than expected. the method i'm mocking has no arguments and returns a boolean, but if i debug the EasyMock code two instanceOf(Long.class) matchers have been recorded! I think this is a threading issue.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-53775228164825013712008-08-29T23:40:00.000+10:002008-08-29T23:40:00.000+10:00Hi Tomas,Thanks for sharing your experience and yo...Hi Tomas,<BR/>Thanks for sharing your experience and your solution!<BR/>AlexAlex Weihttps://www.blogger.com/profile/16196507572911120081noreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-78506632565090583872008-08-29T23:28:00.000+10:002008-08-29T23:28:00.000+10:00Let me give you a even stranger quirk:Suppose you ...Let me give you a even stranger quirk:<BR/><BR/>Suppose you want to expect a call with two params, where you must use isA, but the other parameter is null.<BR/>Suppose the signature looks like this:<BR/>methodName(MyOtherObject moo, MyObject mo);<BR/>Then the mock should look like this:<BR/>mock.methodName(null, isA(MyObject.class));<BR/><BR/>But that isn't supported as if you use a matcher, all arguments must use matcher. Ah, then this should work:<BR/>mock.methodName(isNull(), isA(MyObject.class));<BR/><BR/>But no, this doesn't compile unless the signature of methodName use Object as first parameter, which it seldom does.<BR/><BR/>So, heres the extremely ugly workaraound I found:<BR/>mock.methodName(not(isA(MyOtherObject.class)), isA(MyObject.class));<BR/><BR/>If someone has a neater solution, I'd be thrilled.Unknownhttps://www.blogger.com/profile/14161440223165157166noreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-6611301005851639652008-07-10T15:03:00.000+10:002008-07-10T15:03:00.000+10:00Thanks Alex. I had the same problem and spend quit...Thanks Alex. <BR/>I had the same problem and spend quite some time before I found your blog.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-42757448642550969602008-02-07T05:06:00.000+11:002008-02-07T05:06:00.000+11:00Great man,you solved my problems!!!Thanks,V.Great man,<BR/><BR/>you solved my problems!!!<BR/><BR/><BR/><BR/>Thanks,<BR/>V.Vincenzo Vitalehttps://www.blogger.com/profile/12529329214698162607noreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-32117263689622586902008-01-09T07:32:00.000+11:002008-01-09T07:32:00.000+11:00Excellent. What a strange quirk. Thank you.Excellent. What a strange quirk. Thank you.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-80608820997117919502007-12-30T19:52:00.000+11:002007-12-30T19:52:00.000+11:00Thanks so much for making this information availab...Thanks so much for making this information available -- it helped me to quickly get past a problem which had me really stumped, and I can only guess how many hours it would have taken me to figure this out on my own. Kudos!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-1800070009379490802007-10-28T00:00:00.000+10:002007-10-28T00:00:00.000+10:00Hi anon, unfortunately I have never encountered th...Hi anon, unfortunately I have never encountered the situation where the number of recorded matchers is greater than that of expected matchers. Without more code from your test case and the class under test, it is virtually impossible to figure out the cause of this problem...Alex Weihttps://www.blogger.com/profile/16196507572911120081noreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-25391325406736933772007-10-25T04:22:00.000+10:002007-10-25T04:22:00.000+10:00hi, I removed same method call expect(someMock....hi, I removed same method call<BR/><BR/> expect(someMock.someMethod(isA(SomeObject.class))).andStubAnswer(new IAnswer<List<SomeReturnObject>>() {<BR/> public List<SomeReturnObject> answer() throws Throwable {<BR/> Object args[] = getCurrentArguments();<BR/> SomeObject ca = (SomeObject)args[0];<BR/> return new ArrayList<SomeReturnObject>(ca.getSomeReturnObjects());<BR/> }<BR/> });<BR/><BR/><BR/><BR/>java.lang.IllegalStateException: 1 matchers expected, 2 recorded.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-31056402269998293132007-10-25T04:18:00.000+10:002007-10-25T04:18:00.000+10:00hi I am facing some similar kind of Exception, but...hi I am facing some similar kind of Exception, but in my case there is only parameter for the mocked method<BR/><BR/> expect(someMock.someMethod(isA(SomeObject.class))).andStubAnswer(same(new IAnswer<List<SomeReturnObject>>() {<BR/> public List<SomeReturnObject> answer() throws Throwable {<BR/> Object args[] = getCurrentArguments();<BR/> SomeObject ca = (SomeObject)args[0];<BR/> return new ArrayList<SomeReturnObject>(ca.getSomeReturnObjects());<BR/> }<BR/> }));<BR/><BR/>java.lang.IllegalStateException: 1 matchers expected, 2 recorded.<BR/> at org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:41)<BR/><BR/><BR/>any ideas?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-36408424277106068202007-08-09T13:47:00.000+10:002007-08-09T13:47:00.000+10:00This tip was really useful. Thanks.This tip was really useful. Thanks.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-82940303141190453722007-08-09T01:25:00.000+10:002007-08-09T01:25:00.000+10:00Thanks Matt. I'm glad that this post helped.Thanks Matt. I'm glad that this post helped.Alex Weihttps://www.blogger.com/profile/16196507572911120081noreply@blogger.comtag:blogger.com,1999:blog-2664528635822406543.post-22783361848602226392007-08-08T00:45:00.000+10:002007-08-08T00:45:00.000+10:00Thanks Alex. That was precisely the issue I was fa...Thanks Alex. That was precisely the issue I was facing today. Is a shame these quirks are not listed as part of the EasyMock documentation.Unknownhttps://www.blogger.com/profile/15511879010045612055noreply@blogger.com