From d9648a36fe079a5a21e6c3f01b099d873c685964 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 30 Jul 2015 10:51:56 +0200 Subject: [PATCH] Add more specific test Add an error controller test that translates a ResponseStatus annotated exception that does not contain a reason attribute. See gh-3623 --- .../BasicErrorControllerIntegrationTests.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java index 36fd63a2bb..55b1e19328 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java @@ -92,6 +92,18 @@ public class BasicErrorControllerIntegrationTests { + "message=Expected!, " + "path=/annotated}")); } + @Test + public void testErrorForAnnotatedNoReasonException() throws Exception { + ResponseEntity entity = new TestRestTemplate().getForEntity( + "http://localhost:" + this.port + "/annotatedNoReason", Object.class); + assertThat( + entity.getBody().toString(), + endsWith("status=406, " + + "error=Not Acceptable, " + + "exception=org.springframework.boot.autoconfigure.web.BasicErrorControllerIntegrationTests$TestConfiguration$Errors$NoReasonExpectedException, " + + "message=Expected message, " + "path=/annotatedNoReason}")); + } + @Test @SuppressWarnings("rawtypes") public void testBindingExceptionForMachineClient() throws Exception { @@ -144,6 +156,11 @@ public class BasicErrorControllerIntegrationTests { throw new ExpectedException(); } + @RequestMapping("/annotatedNoReason") + public String annotatedNoReason() { + throw new NoReasonExpectedException("Expected message"); + } + @RequestMapping("/bind") public String bind(HttpServletRequest request) throws Exception { BindException error = new BindException(this, "test"); @@ -157,6 +174,15 @@ public class BasicErrorControllerIntegrationTests { } + @ResponseStatus(value = HttpStatus.NOT_ACCEPTABLE) + @SuppressWarnings("serial") + private static class NoReasonExpectedException extends RuntimeException { + + public NoReasonExpectedException(String message) { + super(message); + } + } + } }