2014-09-30 83 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);