Я новичок в Mockito. Я пытаюсь написать тестовый пример для следующего метода restcontroller.
@ResponseBody
@RequestMapping(value = Constants.PATH_NAME, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseData abc(@RequestBody RequestData requestData, HttpServletRequest request)
throws Exception
request.setAttribute("req", requestData);
if (Validation.numberValiadtion(requestData.getNumber())) { // where Validation is the static class of external jar
LOGGER.info("Number validated successfully--");
} else {
String errorMessage = Constants.INVALID_NUMBER;
throw new NumberNotFoundException(errorMessage);
}
ResponseData reponseData = service.getScheduleData(requestData); //service is autowired
return reponseData;
}
, а мой тестовый пример -
@RunWith(MockitoJUnitRunner.Silent.class)
public class ApplicationTest {
@Mock
AbcService service;
@Mock
HttpServletRequest httpReq;
@Test
public void abcSuccess() throws Exception {
SampleController restController = Mockito.mock(SampleController.class);
Validation validation = Mockito.mock(Validation.class);
RequestData req = new RequestData();
ResponseData respData = new ResponseData();
Mockito.when(restController.abc(req, httpReq)).thenReturn(respData);
Mockito.when(validation.numberValiadtion("467")).thenReturn(true); --err line
Mockito.when(service.getData(req)).thenReturn(respData);
}
}
И errortrace-
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.
Mocking methods declared on non-public parent classes is not supported.
2. inside when() you don't call method on mock but on some other object.
Не могли бы вы помогите мне решить проблему. Calss проверки - это класс stati c (во внешнем Jar)