Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. public class RestControllerTest {
  2.  
  3. //It is used in restController
  4. @Mock
  5. protected Service service;
  6.  
  7. @InjectMocks
  8. protected RestController restController;
  9.  
  10.  
  11. @Test
  12. protected void testMe() throws Exception {
  13. MockMvc mockMVC = MockMvcBuilders.standaloneSetup(restController) .build();
  14. doThrow(new IOException()).when(service).methodCalled();
  15.  
  16.  
  17. mockMvc.perform(post("/something")
  18. .param("val", "test"))
  19. .andExpect(status().isBadRequest());
  20. }
  21.  
  22. }
  23.  
  24. @ControllerAdvice
  25. public class MyControllerAdvice {
  26.  
  27. @ResponseStatus(value = HttpStatus.CONFLICT)
  28. // 409
  29. @ExceptionHandler(IOException.class)
  30. public void ioException(final IOException e) {
  31. log.error("Request raised an IOException", e);
  32. }
  33. }
  34.  
  35. @ResponseStatus(HttpStatus.BAD_REQUEST)
  36. public class MyException extends RuntimeException {}
  37.  
  38. 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