ControllerAdvice to work with guaranteed rest
I have a controller tip:
@ControllerAdvice
public class MyExceptionHandler {
@ExceptionHandler(Exception.class)
public void handleException(Exception ex) {
...
}
}
And when tested, the exception handler doesn't work:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {TestConfiguration.class})
public class MyTest {
@Autowired
private WebApplicationContext context;
@Before
public void setUp() throws Exception {
RestAssuredMockMvc.webAppContextSetup(context);
}
@Test
public myTestMethod() throws Exception {
when().get("/controller").then().status(INTERNAL_SERVER_ERROR.value());
}
@After
public void tearDown() throws Exception {
RestAssuredMockMvc.reset();
}
}
It just throws an exception and the controller advice never caught it.
How can I make it work with confidence with the ControllerAdvice in the whole context setting situation.
+3
source to share
No one has answered this question yet
Check out similar questions: