Skip to content

Commit

Permalink
Add tests for exeptions ignored by Bugsnag
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Mende committed Jul 21, 2021
1 parent cc9a548 commit 2ac8f75
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
24 changes: 24 additions & 0 deletions bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.bugsnag.testapp.springboot;

public class TestCustomException extends RuntimeException {
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}

0 comments on commit 2ac8f75

Please sign in to comment.