假设我有一个非最终的具体类,最后一个方法如下.
public class ABC { public final String myMethod(){ return "test test"; } }
使用powermockito在junit中调用myMethod()可以返回别的东西吗?谢谢
解决方法
这样做:
@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()); } }