我在读一段我没有写的代码。我无意中发现了以下声明:
context.checking(new org.jmock.Expectations() {
{
allowing(habilitationManager).hasRole(RoleDtoEnum.ROLE_NEWS);
will(returnValue(true));
allowing(habilitationManager).hasRole(RoleDtoEnum.ROLE_STAT);
will(returnValue(true));
allowing(habilitationManager).getUser();
will(returnValue(getUserMock()));
oneOf(parametreService).getParametre(PPP);
will(returnValue(getMockPPP()));
}
});我理解在第二个{ ... }中调用的方法是Expectations方法。
{ ... }?发布于 2013-10-28 17:21:35
它是一个匿名类,其中包含一个实例初始化器块。因此,要将两者分开:
// This is an anonymous class
Expectations expectations = new Expectations() {
// Class body here
};
class Foo {
// This is an instance initializer block in a normal class
{
System.out.println("You'll see this via either constructor");
}
Foo(int x) {}
Foo(String y) {}
}在任何构造函数的主体之前,都会同时隐式地调用实例变量初始化器,并按文本顺序调用http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.6。
https://stackoverflow.com/questions/19641103
复制相似问题