Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RestControllerTest {
- //It is used in restController
- @Mock
- protected Service service;
- @InjectMocks
- protected RestController restController;
- @Test
- protected void testMe() throws Exception {
- MockMvc mockMVC = MockMvcBuilders.standaloneSetup(restController) .build();
- doThrow(new IOException()).when(service).methodCalled();
- mockMvc.perform(post("/something")
- .param("val", "test"))
- .andExpect(status().isBadRequest());
- }
- }
- @ControllerAdvice
- public class MyControllerAdvice {
- @ResponseStatus(value = HttpStatus.CONFLICT)
- // 409
- @ExceptionHandler(IOException.class)
- public void ioException(final IOException e) {
- log.error("Request raised an IOException", e);
- }
- }
- @ResponseStatus(HttpStatus.BAD_REQUEST)
- public class MyException extends RuntimeException {}
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Method is required
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement