0

我是 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'.

请问你能帮帮我吗?

4

1 回答 1

0

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

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

有关详细信息和示例,请参阅此页面

于 2012-11-26T21:42:47.187 回答