Reputation: 22041
Is there an easy way to do something like that with EasyMock?
Object a, b, c;
expect(a.getB("string1")).andReturn(a).anyTimes();
expect(a.getB("string2")).andReturn(b).anyTimes();
expect(a.getB(<ANYTHING_ELSE>)).andReturn(c).anyTimes();
Or should I implement my own implementation of IArgumentMatcher
?
Upvotes: 0
Views: 142
Reputation: 61148
You can use the andAnswer
method of expect
:
expect(a.getB((String)anyObject())).andAnswer(new IAnswer<MyClass>() {
public MyClass answer() {
String in = (String) getCurrentArguments()[0];
switch(in) {
case: "string1":
return a;
case: "string2":
return b;
default:
return c;
}
}
});
N.B: Switch on String
requires Java 7.
Upvotes: 1