EasyMock provides the following possiblity to gain access to these arguments:
@Test
public void checkThePassedObject(){
SomeEJB someEjb = createMock(SomeEJB.class);
someEjb.timeSomething(anyObject(Timer.class));
public void checkThePassedObject(){
SomeEJB someEjb = createMock(SomeEJB.class);
someEjb.timeSomething(anyObject(Timer.class));
expectLastCall().andAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
passedTimer = (Timer) getCurrentArguments()[0];
return null;
}
});
replay(someEjb);
classUT.setSomeEjb(someEjb);
classUT.createSpecialTimer();
Assert.assertNotNull(passedTimer);
verify(someEjb);
}
public Object answer() throws Throwable {
passedTimer = (Timer) getCurrentArguments()[0];
return null;
}
});
replay(someEjb);
classUT.setSomeEjb(someEjb);
classUT.createSpecialTimer();
Assert.assertNotNull(passedTimer);
verify(someEjb);
}
However, if you do not care about your mock behavior at all, how often it is called, what parameters are passed or if it is even called, you can use the andStubReturn method:
SomeEJB someEjb = createMock(SomeEJB.class);
expect(someEjb.removeDigits(not(eq("")))).andStubReturn("no_digits");In this case, whenever the method is called with a not empty string the mock will return "no_digits".
No comments:
Post a Comment