【发布时间】:2015-04-13 13:15:40
【问题描述】:
我一直认为 Mockito 可以使用某种代理或类似的东西。但现在我发现,Mockito 允许我做类似的事情
class A {
public String m1() {
return m2();
}
public String m2() {
return "Hello";
}
}
class TestA {
public testM1() {
A a = Mockito.spy(A.class);
when(a.m2()).thenReturn("Bye");
Assert.assertEquals(a.m1(), "Bye");
}
}
这不适用于代理。它是如何做到的? 可以使用该技术来允许调用内部 AOP 方法吗? (见Spring AOP not working for method call inside another method)
【问题讨论】: