Given the following
class Event{
}
class SpecialEvent extends Event{
}
class OtherEvent extends Event{
}
class EventPublisher{
public publish(Event e){
}
}
@test
testBlah{
myService = new MyService();
mockEvent = createMock(EventPublisher)
mySercice.setEventPublisher(mockEvent);
mockEvent.publish(anyObject(SpecialEvent.class));
expectLastCall.once();
replay(mockEvent);
myServce.doSomethingThatCauesesSpecialEventToBePublished();
verify(mockEvent);
}
If myService.doSomething…. Publishes an event that is NOT SpecialEvent.class it does not fail the test as long as the event extends from Event. Is there a way to ensure that this fails?
anyObjectwill match any object – the class just changes the return type. I suspect you wantisA: