EasyMock Not making a distinction between subclasses
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.p开发者_JAVA技巧ublish(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?
anyObject
will match any object - the class just changes the return type. I suspect you want isA
:
mockEvent.publish(isA(SpecialEvent.class));
精彩评论