是否可以模拟超类的方法?(不被覆盖)
public class FooBarTest {
@Test
public void test() {
Bar bar = Mockito.spy(new Bar());
Mockito.doReturn("Mock!").when((Foo) bar).test();
String actual = bar.test(); // returns only "Mock!"
assertEquals("Mock! Bar!", actual);
}
public static class Foo {
public String test(){
return "Foo!";
}
}
public static class Bar extends Foo {
@Override
public String test(){
return super.test()+" Bar!";
}
}
}
Off:如何在此处突出显示代码?