gpt4 book ai didi

java - org.mockito.exceptions.misusing.MissingMethodInitationException

转载 作者:行者123 更新时间:2023-12-01 09:52:23 25 4
gpt4 key购买 nike

Junit 测试代码:

    @Test
public void validscheduleRecordingPriority() throws Exception{
//check the code

RequestBuilder requestBuilder = mock(RequestBuilder.class);
RecordingSchedulesPriorityResponse prioritySchedules = new RecordingSchedulesPriorityResponse();
List<BigInteger> list = new ArrayList<BigInteger>();
AMSRequest request = new AMSRequest();
when(RequestBuilder.buildSeriesPriorityRequest(DEVICE_ID, list)).thenReturn(request); //here is the error
AMSResponse response = new AMSResponse();
Result result = new Result();
result.setStatusCode(0);
List<Result> listResult = new ArrayList<Result>();
listResult.add(result);
response.setResult(listResult);
when(AMSClient.postAMS("http://localhost:8080/ams/DVR", request)).thenReturn(response);
ScheduleRecordingResponse response2 = dvrService.scheduleRecordingPriority(DEVICE_ID, prioritySchedules);
assertEquals(response2.getDescription(),"Update Series Priority successful");
}

我将 RequestBuilder 制作为模拟,但仍然遇到相同的错误

当我运行上面的代码时,它给出以下错误@firstwhen()。

org.mockito.exceptions.misusing.MissingMethodInvocationException: 
when() requires an argument which has to be 'a method call on a mock'.
For example:
when(mock.getArticles()).thenReturn(articles);

Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
2. inside when() you don't call method on mock but on some other object.
3. the parent of the mocked class is not public.
It is a limitation of the mock engine.

最佳答案

您似乎正在尝试在调用静态方法时使用 when,即 not supported by Mockito 。正如错误消息所示,参数必须是“模拟上的方法调用”,并且我在您的代码中看不到任何表明 RequestBuilder 是模拟的内容。

关于java - org.mockito.exceptions.misusing.MissingMethodInitationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37524356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com