2014-09-30 81 views
0

我想嘲笑这个静态方法:PowerMockito给InvalidUseOfMatchersException在超静态方法

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,但我认为匹配器是正确的。

有什么建议吗?

回答

1

应该

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