【发布时间】:2014-04-02 09:39:49
【问题描述】:
我有一些这样的 Java 东西:
public interface EventBus{
void fireEvent(GwtEvent<?> event);
}
public class SaveCommentEvent extends GwtEvent<?>{
private finalComment oldComment;
private final Comment newComment;
public SaveCommentEvent(Comment oldComment,Comment newComment){
this.oldComment=oldComment;
this.newComment=newComment;
}
public Comment getOldComment(){...}
public Comment getNewComment(){...}
}
并像这样测试代码:
def "...."(){
EventBus eventBus=Mock()
Comment oldComment=Mock()
Comment newCommnet=Mock()
when:
eventBus.fireEvent(new SaveCommentEvent(oldComment,newComment))
then:
1*eventBus.fireEvent(
{
it.source.getClass()==SaveCommentEvent;
it.oldComment==oldComment;
it.newComment==newComment
}
)
}
我想验证eventBus.fireEvent(..) 是否被调用一次,事件类型为SaveCommentEvent,构造参数为oldComment 和newComment。
代码运行没有错误,但问题是:
从
更改关闭内容后{
it.source.getClass()==SaveCommentEvent;
it.oldComment==oldComment; //old==old
it.newComment==newComment //new==new
}
到
{
it.source.getClass()==Other_Class_Literal;
it.oldComment==newComment; //old==new
it.newComment==oldComment //new==old
}
仍然,代码运行没有错误?显然闭包没有做我想要的,所以问题是:如何进行参数捕获?
【问题讨论】:
标签: spock