]> juplo.de Git - website/commitdiff
WIP:Code-Listings von Hand nachkorrigiert
authorKai Moritz <kai.milan.moritz@googlemail.com>
Fri, 19 Jun 2026 08:24:11 +0000 (08:24 +0000)
committerKai Moritz <kai.milan.moritz@googlemail.com>
Fri, 19 Jun 2026 08:24:11 +0000 (08:24 +0000)
src/content/blog/2020/testing-exception-handling-in-spring-mvc.md

index 96ee62727aca4c78be17572a1eea3fcfe715b804..e59a4da26ed9c2dbc0217886e4aa0fc10c3e9ae3 100644 (file)
@@ -67,14 +67,16 @@ public class ExampleController
     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;
@@ -88,6 +90,7 @@ class ExceptionHandlingApplicationTests
       .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.