Powermockito可以在非最终具体类中模拟最终方法吗?

假设我有一个非最终的具体类,其最终方法如下所示。

public class ABC { public final String myMethod(){ return "test test"; } } 

是否可以模拟myMethod()在使用Powermockitojunit调用时返回其他内容? 谢谢

这有效:

 @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()); } }