|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -89,6 +89,18 @@ public void annotatedResponseStatusCode() {
|
89 | 89 | Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, error),
|
90 | 90 | false);
|
91 | 91 | assertThat(attributes.get("error")).isEqualTo(HttpStatus.I_AM_A_TEAPOT.getReasonPhrase());
|
| 92 | + assertThat(attributes.get("message")).isEqualTo(""); |
| 93 | + assertThat(attributes.get("status")).isEqualTo(HttpStatus.I_AM_A_TEAPOT.value()); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + void annotatedResponseStatusCodeWithExceptionMessage() { |
| 98 | + Exception error = new CustomException("Test Message"); |
| 99 | + MockServerHttpRequest request = MockServerHttpRequest.get("/test").build(); |
| 100 | + Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, error), |
| 101 | + false); |
| 102 | + assertThat(attributes.get("error")).isEqualTo(HttpStatus.I_AM_A_TEAPOT.getReasonPhrase()); |
| 103 | + assertThat(attributes.get("message")).isEqualTo("Test Message"); |
92 | 104 | assertThat(attributes.get("status")).isEqualTo(HttpStatus.I_AM_A_TEAPOT.value());
|
93 | 105 | }
|
94 | 106 |
|
@@ -218,6 +230,13 @@ public int method(String firstParam) {
|
218 | 230 | @ResponseStatus(HttpStatus.I_AM_A_TEAPOT)
|
219 | 231 | private static class CustomException extends RuntimeException {
|
220 | 232 |
|
| 233 | + CustomException() { |
| 234 | + } |
| 235 | + |
| 236 | + CustomException(String message) { |
| 237 | + super(message); |
| 238 | + } |
| 239 | + |
221 | 240 | }
|
222 | 241 |
|
223 | 242 | @ResponseStatus(value = HttpStatus.I_AM_A_TEAPOT, reason = "Nope!")
|
|
0 commit comments