diff --git a/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java b/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java index 694bb98b..24857a5e 100644 --- a/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java +++ b/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java @@ -171,6 +171,20 @@ public void springVersionSetCorrectly() { assertEquals(SpringBootVersion.getVersion(), runtimeVersions.get("springBoot")); } + @Test + public void noBugsnagNotifyOnResponseStatusException() { + callResponseStatusExceptionEndpoint(); + + verifyNoReport(); + } + + @Test + public void noBugsnagNotifyOnExceptionHandledByExceptionHandlerException() { + callResponseStatusExceptionEndpoint(); + + verifyNoReport(); + } + @Test public void unhandledTypeMismatchExceptionSeverityInfo() { callUnhandledTypeMismatchExceptionEndpoint(); @@ -242,6 +256,16 @@ private void callUnhandledTypeMismatchExceptionEndpoint() { "/throw-type-mismatch-exception", String.class); } + private void callResponseStatusExceptionEndpoint() { + this.restTemplate.getForEntity( + "/throw-response-status-exception", String.class); + } + + private void callCustomExceptionEndpoint() { + this.restTemplate.getForEntity( + "/throw-custom-exception", String.class); + } + private void callHandledTypeMismatchExceptionUserSeverityEndpoint() { this.restTemplate.getForEntity( "/handled-type-mismatch-exception-user-severity", String.class); diff --git a/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java index 86e064bf..27c38781 100644 --- a/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java +++ b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java @@ -33,6 +33,22 @@ public void throwTypeMismatchException() { throw new TypeMismatchException("Test", String.class); } + /** + * Throw an exception with @ResponseStatus + */ + @RequestMapping("/throw-response-status-exception") + public void throwResponseStatusException() { + throw new TestResponseStatusException(); + } + + /** + * Throw an exception that is handled by @ExceptionHandler + */ + @RequestMapping("/throw-custom-exception") + public void throwCustomException() { + throw new TestCustomException(); + } + /** * Report a handled exception where the severity reason is exceptionClass */ diff --git a/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestCustomException.java b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestCustomException.java new file mode 100644 index 00000000..d4799660 --- /dev/null +++ b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestCustomException.java @@ -0,0 +1,4 @@ +package com.bugsnag.testapp.springboot; + +public class TestCustomException extends RuntimeException { +} diff --git a/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestExceptionHandler.java b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestExceptionHandler.java new file mode 100644 index 00000000..8eacf031 --- /dev/null +++ b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestExceptionHandler.java @@ -0,0 +1,13 @@ +package com.bugsnag.testapp.springboot; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class TestExceptionHandler { + @ExceptionHandler(TestCustomException.class) + public ResponseEntity handleTestCustomException(TestCustomException ignored) { + return ResponseEntity.ok(TestCustomException.class.getSimpleName()); + } +} diff --git a/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestResponseStatusException.java b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestResponseStatusException.java new file mode 100644 index 00000000..3d48ef59 --- /dev/null +++ b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestResponseStatusException.java @@ -0,0 +1,9 @@ +package com.bugsnag.testapp.springboot; + +import static org.springframework.http.HttpStatus.I_AM_A_TEAPOT; + +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(I_AM_A_TEAPOT) +public class TestResponseStatusException extends RuntimeException { +}