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;
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());
}