Polishing in ErrorResponse
See gh-30566
This commit is contained in:
@@ -161,33 +161,31 @@ public class ResponseEntityExceptionHandlerTests {
|
||||
|
||||
@Test
|
||||
public void errorResponseProblemDetailViaMessageSource() {
|
||||
|
||||
Locale locale = Locale.UK;
|
||||
LocaleContextHolder.setLocale(locale);
|
||||
|
||||
String type = "https://example.com/probs/unsupported-content";
|
||||
String title = "Media type is not valid or not supported";
|
||||
|
||||
try {
|
||||
StaticMessageSource messageSource = new StaticMessageSource();
|
||||
messageSource.addMessage(
|
||||
ErrorResponse.getDefaultDetailMessageCode(HttpMediaTypeNotSupportedException.class, null), locale,
|
||||
"Content-Type {0} not supported. Supported: {1}");
|
||||
messageSource.addMessage(
|
||||
ErrorResponse.getDefaultTitleMessageCode(HttpMediaTypeNotSupportedException.class), locale, title);
|
||||
messageSource.addMessage(
|
||||
ErrorResponse.getDefaultTypeMessageCode(HttpMediaTypeNotSupportedException.class), locale, type);
|
||||
Locale locale = Locale.UK;
|
||||
LocaleContextHolder.setLocale(locale);
|
||||
|
||||
this.exceptionHandler.setMessageSource(messageSource);
|
||||
String type = "https://example.com/probs/unsupported-content";
|
||||
String title = "Media type is not valid or not supported";
|
||||
Class<HttpMediaTypeNotSupportedException> exceptionType = HttpMediaTypeNotSupportedException.class;
|
||||
|
||||
StaticMessageSource source = new StaticMessageSource();
|
||||
source.addMessage(ErrorResponse.getDefaultTypeMessageCode(exceptionType), locale, type);
|
||||
source.addMessage(ErrorResponse.getDefaultTitleMessageCode(exceptionType), locale, title);
|
||||
source.addMessage(ErrorResponse.getDefaultDetailMessageCode(exceptionType, null), locale,
|
||||
"Content-Type {0} not supported. Supported: {1}");
|
||||
|
||||
this.exceptionHandler.setMessageSource(source);
|
||||
|
||||
ResponseEntity<?> entity = testException(new HttpMediaTypeNotSupportedException(
|
||||
MediaType.APPLICATION_JSON, List.of(MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_XML)));
|
||||
|
||||
ProblemDetail body = (ProblemDetail) entity.getBody();
|
||||
assertThat(body.getDetail()).isEqualTo(
|
||||
ProblemDetail problem = (ProblemDetail) entity.getBody();
|
||||
assertThat(problem).isNotNull();
|
||||
assertThat(problem.getType()).isEqualTo(URI.create(type));
|
||||
assertThat(problem.getTitle()).isEqualTo(title);
|
||||
assertThat(problem.getDetail()).isEqualTo(
|
||||
"Content-Type application/json not supported. Supported: [application/atom+xml, application/xml]");
|
||||
assertThat(body.getTitle()).isEqualTo(title);
|
||||
assertThat(body.getType()).isEqualTo(URI.create(type));
|
||||
}
|
||||
finally {
|
||||
LocaleContextHolder.resetLocaleContext();
|
||||
|
||||
Reference in New Issue
Block a user