EasyMock 不区分子类
给出以下
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.... 发布一个不是 SpecialEvent.class 的事件,只要该事件从 Event 扩展,测试就不会失败。有没有办法确保此操作失败?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
anyObject
将匹配任何对象 - 该类只是更改返回类型。我怀疑你想要isA
:anyObject
will match any object - the class just changes the return type. I suspect you wantisA
: