mav.addObject("exception", e);
return mav;
}
-}`
+}
+```
The exception-handler resolves the exception as `400: Bad Request` and renders the specialized error-view `400`.
With the help of `@WebMvcTest`, we can easily mock away the actual implementation of the business-logic and concentrate on the code under test:
our specialized exception-handler.
-`@WebMvcTest(ExampleController.class)
+```
+@WebMvcTest(ExampleController.class)
class ExceptionHandlingApplicationTests
{
@MockBean ExampleService service;
.andExpect(status().isBadRequest());
verify(service, times(1)).checkAnswer(anyInt());
}
-}`
+}
+```
We preform a `GET` with the help of the provided `MockMvc` and check, that the status of the response fullfills our expectations, if we tell our mocked business-logic to throw the `IllegalArgumentException`, that is resolved by our exception-handler.