[英]Can Powermockito mock final method in non-final concrete class?
假设我有一个非最终的具体类,其最终方法如下所示。
public class ABC {
public final String myMethod(){
return "test test";
}
}
是否可以模拟myMethod()
在使用Powermockito
在junit
调用时返回其他内容? 谢谢
这有效:
@RunWith(PowerMockRunner.class)
@PrepareForTest(ABC.class)
public class ABCTest {
@Test
public void finalCouldBeMock() {
final ABC abc = PowerMockito.mock(ABC.class);
PowerMockito.when(abc.myMethod()).thenReturn("toto");
assertEquals("toto", abc.myMethod());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.