Skip to content

Commit 2ac8f75

Browse files
author
Tobias Mende
committed
Add tests for exeptions ignored by Bugsnag
1 parent cc9a548 commit 2ac8f75

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ public void springVersionSetCorrectly() {
171171
assertEquals(SpringBootVersion.getVersion(), runtimeVersions.get("springBoot"));
172172
}
173173

174+
@Test
175+
public void noBugsnagNotifyOnResponseStatusException() {
176+
callResponseStatusExceptionEndpoint();
177+
178+
verifyNoReport();
179+
}
180+
181+
@Test
182+
public void noBugsnagNotifyOnExceptionHandledByExceptionHandlerException() {
183+
callResponseStatusExceptionEndpoint();
184+
185+
verifyNoReport();
186+
}
187+
174188
@Test
175189
public void unhandledTypeMismatchExceptionSeverityInfo() {
176190
callUnhandledTypeMismatchExceptionEndpoint();
@@ -242,6 +256,16 @@ private void callUnhandledTypeMismatchExceptionEndpoint() {
242256
"/throw-type-mismatch-exception", String.class);
243257
}
244258

259+
private void callResponseStatusExceptionEndpoint() {
260+
this.restTemplate.getForEntity(
261+
"/throw-response-status-exception", String.class);
262+
}
263+
264+
private void callCustomExceptionEndpoint() {
265+
this.restTemplate.getForEntity(
266+
"/throw-custom-exception", String.class);
267+
}
268+
245269
private void callHandledTypeMismatchExceptionUserSeverityEndpoint() {
246270
this.restTemplate.getForEntity(
247271
"/handled-type-mismatch-exception-user-severity", String.class);

bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ public void throwTypeMismatchException() {
3333
throw new TypeMismatchException("Test", String.class);
3434
}
3535

36+
/**
37+
* Throw an exception with @ResponseStatus
38+
*/
39+
@RequestMapping("/throw-response-status-exception")
40+
public void throwResponseStatusException() {
41+
throw new TestResponseStatusException();
42+
}
43+
44+
/**
45+
* Throw an exception that is handled by @ExceptionHandler
46+
*/
47+
@RequestMapping("/throw-custom-exception")
48+
public void throwCustomException() {
49+
throw new TestCustomException();
50+
}
51+
3652
/**
3753
* Report a handled exception where the severity reason is exceptionClass
3854
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.bugsnag.testapp.springboot;
2+
3+
public class TestCustomException extends RuntimeException {
4+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.bugsnag.testapp.springboot;
2+
3+
import org.springframework.http.ResponseEntity;
4+
import org.springframework.web.bind.annotation.ControllerAdvice;
5+
import org.springframework.web.bind.annotation.ExceptionHandler;
6+
7+
@ControllerAdvice
8+
public class TestExceptionHandler {
9+
@ExceptionHandler(TestCustomException.class)
10+
public ResponseEntity handleTestCustomException(TestCustomException ignored) {
11+
return ResponseEntity.ok(TestCustomException.class.getSimpleName());
12+
}
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.bugsnag.testapp.springboot;
2+
3+
import static org.springframework.http.HttpStatus.I_AM_A_TEAPOT;
4+
5+
import org.springframework.web.bind.annotation.ResponseStatus;
6+
7+
@ResponseStatus(I_AM_A_TEAPOT)
8+
public class TestResponseStatusException extends RuntimeException {
9+
}

0 commit comments

Comments
 (0)