From: Kai Moritz Date: Fri, 19 Jun 2026 08:24:11 +0000 (+0000) Subject: WIP:Code-Listings von Hand nachkorrigiert X-Git-Url: https://juplo.de/gitweb/?a=commitdiff_plain;h=c9ece988a67c96419d4f21d90c70b42c98511e90;p=website WIP:Code-Listings von Hand nachkorrigiert --- diff --git a/src/content/blog/2020/testing-exception-handling-in-spring-mvc.md b/src/content/blog/2020/testing-exception-handling-in-spring-mvc.md index 96ee6272..e59a4da2 100644 --- a/src/content/blog/2020/testing-exception-handling-in-spring-mvc.md +++ b/src/content/blog/2020/testing-exception-handling-in-spring-mvc.md @@ -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.