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
spring-boot rest-assured spring-boot-test


source to share


No one has answered this question yet

Check out similar questions:

five
Spring Security OAuth2 Redirect Loop
4
Spring security and ExceptionHandler: allowAll path exception always returns 401 on Tomcat server
2
REST load validation error response
1
@ControllerAdvice does not handle exceptions
1
Maven build fails with spring-cloud-contract-verify
1
Spring request object error validation cannot find message in @ControllerAdvice
0
Is there a simpler exception handling technology for Spring?
0
Rest Assured + Mock MVC @ControllerAdvice
0
dependency error with Spring Framework 4.2.4 and spring-security-config
0
@ExceptionHandler doesn't work with @EnableWebMvc, HttpMediaTypeNotAcceptableException (406) is returned for ResponseEntity



All Articles
Loading...
X
Show
Funny
Dev
Pics