Junit Test Code :
@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");
}
I made RequestBuilder as mock but still getting the same error
when I run the above code, it is giving the following error @ first when().
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.