|
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 @@ 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 |
|
@@ -226,6 +238,13 @@ int method(String firstParam) {
|
226 | 238 | @ResponseStatus(HttpStatus.I_AM_A_TEAPOT)
|
227 | 239 | static class CustomException extends RuntimeException {
|
228 | 240 |
|
| 241 | + CustomException() { |
| 242 | + } |
| 243 | + |
| 244 | + CustomException(String message) { |
| 245 | + super(message); |
| 246 | + } |
| 247 | + |
229 | 248 | }
|
230 | 249 |
|
231 | 250 | @ResponseStatus(value = HttpStatus.I_AM_A_TEAPOT, reason = "Nope!")
|
|
0 commit comments