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
This commit is contained in:
Stephane Nicoll
2015-07-30 10:51:56 +02:00
parent 4a327dc08b
commit d9648a36fe

View File

@@ -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);
}
}
}
}