Added expectations according the result of the request exception-handling-simple
authorKai Moritz <kai@juplo.de>
Sat, 3 Oct 2020 15:07:00 +0000 (17:07 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 3 Oct 2020 15:07:00 +0000 (17:07 +0200)
src/test/java/de/juplo/demo/ExceptionHandlingApplicationTests.java

index 77eb7f6..67a9e76 100644 (file)
@@ -5,9 +5,11 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
 import org.springframework.boot.test.mock.mockito.MockBean;
 import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.MvcResult;
 
 import java.net.URI;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.Mockito.*;
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -27,9 +29,13 @@ class ExceptionHandlingApplicationTests {
        void test400ForExceptionInBusinessLogic() throws Exception {
                when(service.checkAnswer(anyInt())).thenThrow(new IllegalArgumentException("FOO!"));
 
-               mvc
+               MvcResult result = mvc
                                .perform(get(URI.create("http://FOO/?answer=1234")))
-                               .andExpect(status().isBadRequest());
+                               .andExpect(status().isBadRequest())
+                               .andReturn();
+
+               assertThat(result.getModelAndView().getViewName()).isEqualTo("400");
+               assertThat(result.getResolvedException()).isInstanceOf(IllegalArgumentException.class);
 
                verify(service, times(1)).checkAnswer(anyInt());
        }