我正在读一个我没写过的代码.我偶然发现了以下声明:
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()));
}
});
Run Code Online (Sandbox Code Playgroud)
据我所知,第二种方法中的方法{ ... }是Expectations方法.
{ ... }?它是一个匿名类,其中包含一个实例初始化程序块.所以将两者分开:
// 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) {}
}
Run Code Online (Sandbox Code Playgroud)
一个实例初始化是隐式调用,同时为实例变量初始化,在文本顺序,任何构造函数体前.
| 归档时间: |
|
| 查看次数: |
116 次 |
| 最近记录: |