Oracle ADF中的模拟方法

时间:2012-11-22 18:00:57

标签: oracle mockito powermock

我是Mockito的新手。 我想在Oracle ADF中嘲笑这段代码。

else {
     FacesContext.getCurrentInstance().addMessage(null,                                                         new FacesMessage(FacesMessage.SEVERITY_INFO,
             "No Cases found in Queue",null));
        }

这是我的模仿:

    FacesMessage facesMessageMock = mock(FacesMessage.class);
    PowerMockito.mockStatic(FacesContext.class);
    PowerMockito.when(FacesContext.getCurrentInstance()).thenReturn(facesContextMock);

但我有这个错误:

org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.

你能帮我吗?

1 个答案:

答案 0 :(得分:0)

您需要在测试类上添加以下注释:

@RunWith(PowerMockRunner.class)
@PrepareForTest(FacesContext.class)
public class YourTest {
...
}

有关详情和示例,请参阅this page