在JUNIT测试中,我使用JMOCK。在一些样品中,我看到类似下面的代码片段:JMock期望中的第二组括号
mock.checking(new Expectations(){
{
allowing(tmp).assign(
with(any(String.class)),
with(any(String.class)),
with(any(Integer.class)),
with(any(Boolean.class)));
will(returnValue("BLAH"));
}
});
我明白tmp
是JMock的嘲笑的一类,它会从分配返回"BLAH"
。
但是,为什么有两组花括号?为什么新的Expectations(){}?它们没有外部定义嵌套。
这是为什么这样?
这只是一个带有实例初始值设定项的匿名内部类。 – 2013-04-09 21:38:03