Polish 'Ignore quality value when removing MediaType.ALL'

See gh-25778
This commit is contained in:
Phillip Webb 2021-03-24 12:31:23 -07:00
parent 3090a3a71f
commit 88b74097ba
2 changed files with 6 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -237,7 +237,7 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
return (serverRequest) -> { return (serverRequest) -> {
try { try {
List<MediaType> acceptedMediaTypes = serverRequest.headers().accept(); List<MediaType> acceptedMediaTypes = serverRequest.headers().accept();
acceptedMediaTypes.removeIf((mediaType) -> MediaType.ALL.equalsTypeAndSubtype(mediaType)); acceptedMediaTypes.removeIf(MediaType.ALL::equalsTypeAndSubtype);
MediaType.sortBySpecificityAndQuality(acceptedMediaTypes); MediaType.sortBySpecificityAndQuality(acceptedMediaTypes);
return acceptedMediaTypes.stream().anyMatch(MediaType.TEXT_HTML::isCompatibleWith); return acceptedMediaTypes.stream().anyMatch(MediaType.TEXT_HTML::isCompatibleWith);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -46,7 +46,7 @@ import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
/** /**
* Tests for {@link AbstractErrorWebExceptionHandler}. * Tests for {@link DefaultErrorWebExceptionHandler}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Madhura Bhave * @author Madhura Bhave
@ -66,10 +66,10 @@ class DefaultErrorWebExceptionHandlerTests {
@Test @Test
void nonStandardErrorStatusCodeShouldNotFail() { void nonStandardErrorStatusCodeShouldNotFail() {
ErrorAttributes errorAttributes = mock(ErrorAttributes.class); ErrorAttributes errorAttributes = mock(ErrorAttributes.class);
given(errorAttributes.getErrorAttributes(any(), any())).willReturn(getErrorAttributes());
ResourceProperties resourceProperties = new ResourceProperties(); ResourceProperties resourceProperties = new ResourceProperties();
ErrorProperties errorProperties = new ErrorProperties(); ErrorProperties errorProperties = new ErrorProperties();
ApplicationContext context = new AnnotationConfigReactiveWebApplicationContext(); ApplicationContext context = new AnnotationConfigReactiveWebApplicationContext();
given(errorAttributes.getErrorAttributes(any(), any())).willReturn(getErrorAttributes());
DefaultErrorWebExceptionHandler exceptionHandler = new DefaultErrorWebExceptionHandler(errorAttributes, DefaultErrorWebExceptionHandler exceptionHandler = new DefaultErrorWebExceptionHandler(errorAttributes,
resourceProperties, errorProperties, context); resourceProperties, errorProperties, context);
setupViewResolver(exceptionHandler); setupViewResolver(exceptionHandler);
@ -103,8 +103,7 @@ class DefaultErrorWebExceptionHandlerTests {
.from(MockServerHttpRequest.get("/test").accept(allWithQuality)); .from(MockServerHttpRequest.get("/test").accept(allWithQuality));
List<HttpMessageReader<?>> readers = ServerCodecConfigurer.create().getReaders(); List<HttpMessageReader<?>> readers = ServerCodecConfigurer.create().getReaders();
ServerRequest request = ServerRequest.create(exchange, readers); ServerRequest request = ServerRequest.create(exchange, readers);
boolean accepts = exceptionHandler.acceptsTextHtml().test(request); assertThat(exceptionHandler.acceptsTextHtml().test(request)).isFalse();
assertThat(accepts).isFalse();
} }
} }