开发者

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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜