Hi Johan!
Thank you for your reply. It did work with the EasyMock.isA() method! Great!
-Jan
Hi again!
I just had a more advanced use case for that problem, actually it was a constructor that takes two arguments.
When I tried
String name = “Foo”;
expectNew(ClassA.class, name, isA(ClassB.class)).andReturn(someMock);
I’ll get an IllegalStateException saying “2 matchers expected, 1 recorded.”. What does it actually mean? I assumed, that it can either only take normal parameters or only matchers. Is that correct?
Cause when I changed it to
expectNew(ClassA.class, isA(String.class), isA(ClassB.class)).andReturn(someMock);
it works!
Is that correct or is there any chance to mix up params and machers?
/Jan
Von: Johan Haleby
[mailto:johan....@gmail.com]
Gesendet: Dienstag, 27. April 2010 22:10
An: powe...@googlegroups.com
Betreff: Re: How to use expectNew when constructor is called with
"this"?
Hi,
Oh, I wasn’t aware of that when I asked! You’re right. I read the EasyMock docs but couldn’t find an answer to my question if you can mix up matchers an objects but I guess the answer is no. At least I found EasyMock.same() to which I can pass the String “name” in my example and use it as a substitution.
String name = “Foo”;
expectNew(ClassA.class, same(name), isA(ClassB.class)).andReturn(someMock);
And it works.