繁体   English   中英

PowerMockito在超类静态方法上提供InvalidUseOfMatchersException

[英]PowerMockito gives InvalidUseOfMatchersException on superclass static method

我正在尝试模拟此静态方法:

public abstract class Model {
   public static <Type> Type find(Class<Type> modelClass, Object id) {
     // some code
   }
}

从其扩展类中调用

public static class Post extends Model {
}

通过使用这个测试用例

@PrepareForTest(Post.class)
@RunWith(PowerMockRunner.class)
public class PostEditorControllerTest {
  mockStatic(Post.class);
  when(Post.find(eq(Post.class), eq(99))).thenReturn(this.post);
}

测试失败,并出现org.mockito.exceptions.misusing.InvalidUseOfMatchersException ,但是我猜匹配器是正确的。

有什么建议么?

它应该是

mockStatic(Model.class);
when(Post.find(eq(Post.class), eq(99))).thenReturn(this.post);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM