From 2575c26020ebec0af71d2d646194c9ca4d4877e1 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 11 Mar 2018 13:44:27 +0100 Subject: [PATCH] Clean up warnings and dead code in spring-webflux module --- .../AbstractMessageWriterResultHandler.java | 2 +- .../adapter/TomcatWebSocketSession.java | 3 +- .../HeaderContentTypeResolverTests.java | 13 +--- .../DelegatingWebFluxConfigurationTests.java | 4 +- .../WebFluxConfigurationSupportTests.java | 4 +- .../function/BodyExtractorsTests.java | 2 +- .../function/MultipartIntegrationTests.java | 6 +- .../client/DefaultClientResponseTests.java | 22 +++--- .../DefaultEntityResponseBuilderTests.java | 17 ----- .../server/DefaultServerRequestTests.java | 17 ++--- .../support/RouterFunctionMappingTests.java | 43 +----------- .../handler/SimpleUrlHandlerMappingTests.java | 7 +- .../resource/ResourceUrlProviderTests.java | 4 +- .../ProducesRequestConditionTests.java | 3 +- ...ookieValueMethodArgumentResolverTests.java | 3 +- ...ssionValueMethodArgumentResolverTests.java | 1 + .../HttpEntityArgumentResolverTests.java | 4 +- ...lAttributeMethodArgumentResolverTests.java | 1 + .../annotation/ModelInitializerTests.java | 7 +- ...tAttributeMethodArgumentResolverTests.java | 3 +- .../RequestBodyArgumentResolverTests.java | 4 +- ...uestHeaderMethodArgumentResolverTests.java | 3 +- ...pingExceptionHandlingIntegrationTests.java | 4 +- ...nAttributeMethodArgumentResolverTests.java | 3 +- .../result/view/AbstractViewTests.java | 68 +++++++++---------- 25 files changed, 86 insertions(+), 162 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java index fa9d758dc3..42b7436807 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java @@ -110,7 +110,7 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa * @return indicates completion or error * @since 5.0.2 */ - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) protected Mono writeBody(@Nullable Object body, MethodParameter bodyParameter, @Nullable MethodParameter actualParameter, ServerWebExchange exchange) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/TomcatWebSocketSession.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/TomcatWebSocketSession.java index c966300d8d..2a78124015 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/TomcatWebSocketSession.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/TomcatWebSocketSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +38,7 @@ public class TomcatWebSocketSession extends StandardWebSocketSession { private static final AtomicIntegerFieldUpdater SUSPENDED = AtomicIntegerFieldUpdater.newUpdater(TomcatWebSocketSession.class, "suspended"); + @SuppressWarnings("unused") private volatile int suspended; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/accept/HeaderContentTypeResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/accept/HeaderContentTypeResolverTests.java index 2bca2494df..fd1eb3703c 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/accept/HeaderContentTypeResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/accept/HeaderContentTypeResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,18 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.accept; import java.util.List; -import org.junit.Before; import org.junit.Test; import org.springframework.http.MediaType; import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; import org.springframework.mock.web.test.server.MockServerWebExchange; import org.springframework.web.server.NotAcceptableStatusException; -import org.springframework.web.server.ServerWebExchange; import static org.junit.Assert.assertEquals; @@ -35,13 +34,7 @@ import static org.junit.Assert.assertEquals; */ public class HeaderContentTypeResolverTests { - private HeaderContentTypeResolver resolver; - - - @Before - public void setup() { - this.resolver = new HeaderContentTypeResolver(); - } + private final HeaderContentTypeResolver resolver = new HeaderContentTypeResolver(); @Test diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/config/DelegatingWebFluxConfigurationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/config/DelegatingWebFluxConfigurationTests.java index 37d5099e80..941b948fde 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/config/DelegatingWebFluxConfigurationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/config/DelegatingWebFluxConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,14 +27,12 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.context.support.StaticApplicationContext; -import org.springframework.core.convert.ConversionService; import org.springframework.format.FormatterRegistry; import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder; -import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter; import static org.junit.Assert.*; import static org.mockito.BDDMockito.*; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java index 37340a720d..182b7e8bb4 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -305,7 +305,7 @@ public class WebFluxConfigurationSupportTests { @Override protected void configureHttpMessageCodecs(ServerCodecConfigurer configurer) { configurer.registerDefaults(false); - configurer.customCodecs().decoder(StringDecoder.textPlainOnly(true)); + configurer.customCodecs().decoder(StringDecoder.textPlainOnly()); configurer.customCodecs().decoder(new Jaxb2XmlDecoder()); configurer.customCodecs().encoder(CharSequenceEncoder.textPlainOnly()); configurer.customCodecs().encoder(new Jaxb2XmlEncoder()); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java index fb1c45a8a0..cc04abfb5d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java @@ -76,7 +76,7 @@ public class BodyExtractorsTests { public void createContext() { final List> messageReaders = new ArrayList<>(); messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); - messageReaders.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + messageReaders.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); messageReaders.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder())); messageReaders.add(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder())); messageReaders.add(new FormHttpMessageReader()); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java index 2f183d7520..340ab32f59 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,16 +23,12 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.client.MultipartBodyBuilder; import org.springframework.http.codec.multipart.FilePart; import org.springframework.http.codec.multipart.FormFieldPart; import org.springframework.http.codec.multipart.Part; -import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.WebClient; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java index 06b89ca9f7..913cc368aa 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java @@ -127,7 +127,7 @@ public class DefaultClientResponseTests { when(mockResponse.getBody()).thenReturn(body); List> messageReaders = Collections - .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Mono resultMono = defaultClientResponse.body(toMono(String.class)); @@ -148,7 +148,7 @@ public class DefaultClientResponseTests { when(mockResponse.getBody()).thenReturn(body); List> messageReaders = Collections - .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Mono resultMono = defaultClientResponse.bodyToMono(String.class); @@ -169,7 +169,7 @@ public class DefaultClientResponseTests { when(mockResponse.getBody()).thenReturn(body); List> messageReaders = Collections - .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Mono resultMono = @@ -192,7 +192,7 @@ public class DefaultClientResponseTests { when(mockResponse.getBody()).thenReturn(body); List> messageReaders = Collections - .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Flux resultFlux = defaultClientResponse.bodyToFlux(String.class); @@ -214,7 +214,7 @@ public class DefaultClientResponseTests { when(mockResponse.getBody()).thenReturn(body); List> messageReaders = Collections - .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Flux resultFlux = @@ -238,7 +238,7 @@ public class DefaultClientResponseTests { when(mockResponse.getBody()).thenReturn(body); List> messageReaders = Collections - .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity result = defaultClientResponse.toEntity(String.class).block(); @@ -261,7 +261,7 @@ public class DefaultClientResponseTests { when(mockResponse.getBody()).thenReturn(body); List> messageReaders = Collections - .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity result = defaultClientResponse.toEntity( @@ -286,7 +286,7 @@ public class DefaultClientResponseTests { when(mockResponse.getBody()).thenReturn(body); List> messageReaders = Collections - .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity> result = defaultClientResponse.toEntityList(String.class).block(); @@ -309,7 +309,7 @@ public class DefaultClientResponseTests { when(mockResponse.getBody()).thenReturn(body); List> messageReaders = Collections - .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity> result = defaultClientResponse.toEntityList( @@ -331,7 +331,7 @@ public class DefaultClientResponseTests { when(mockResponse.getBody()).thenReturn(body.flux()); List> messageReaders = Collections - .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); StepVerifier.create(defaultClientResponse.bodyToMono(Void.class)) @@ -356,7 +356,7 @@ public class DefaultClientResponseTests { when(mockResponse.getBody()).thenReturn(body.flux()); List> messageReaders = Collections - .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); StepVerifier.create(defaultClientResponse.bodyToMono(Void.class)) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilderTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilderTests.java index d3e5715006..412cc30e09 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilderTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilderTests.java @@ -16,7 +16,6 @@ package org.springframework.web.reactive.function.server; -import java.nio.ByteBuffer; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; @@ -24,7 +23,6 @@ import java.util.Collections; import java.util.EnumSet; import java.util.List; import java.util.Set; -import java.util.function.BiFunction; import org.junit.Test; import org.reactivestreams.Publisher; @@ -34,8 +32,6 @@ import reactor.test.StepVerifier; import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.codec.CharSequenceEncoder; -import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.CacheControl; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -44,16 +40,13 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseCookie; import org.springframework.http.codec.EncoderHttpMessageWriter; import org.springframework.http.codec.HttpMessageWriter; -import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse; import org.springframework.mock.web.test.server.MockServerWebExchange; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.result.view.ViewResolver; -import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.*; /** @@ -135,7 +128,6 @@ public class DefaultEntityResponseBuilderTests { .verify(); } - @Test public void lastModified() throws Exception { ZonedDateTime now = ZonedDateTime.now(); @@ -197,14 +189,6 @@ public class DefaultEntityResponseBuilderTests { public void bodyInserter() throws Exception { String body = "foo"; Publisher publisher = Mono.just(body); - BiFunction> writer = - (response, strategies) -> { - byte[] bodyBytes = body.getBytes(UTF_8); - ByteBuffer byteBuffer = ByteBuffer.wrap(bodyBytes); - DataBuffer buffer = new DefaultDataBufferFactory().wrap(byteBuffer); - - return response.writeWith(Mono.just(buffer)); - }; Mono>> result = EntityResponse.fromPublisher(publisher, String.class).build(); @@ -257,7 +241,6 @@ public class DefaultEntityResponseBuilderTests { .verify(); } - @Test public void notModifiedLastModified() { ZonedDateTime now = ZonedDateTime.now(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java index cb37fc93c3..2551621bdd 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import java.util.Map; import java.util.Optional; import java.util.OptionalLong; -import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -59,14 +58,8 @@ import static org.springframework.web.reactive.function.BodyExtractors.toMono; */ public class DefaultServerRequestTests { - List> messageReaders; - - - @Before - public void createMocks() { - this.messageReaders = Collections.singletonList( - new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); - } + private final List> messageReaders = Collections.singletonList( + new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); @Test @@ -335,12 +328,12 @@ public class DefaultServerRequestTests { .method(HttpMethod.GET, "http://example.com?foo=bar") .headers(httpHeaders) .body(body); - this.messageReaders = Collections.emptyList(); - DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders); + DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList()); Flux resultFlux = request.bodyToFlux(String.class); StepVerifier.create(resultFlux) .expectError(UnsupportedMediaTypeStatusException.class) .verify(); } + } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/RouterFunctionMappingTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/RouterFunctionMappingTests.java index 8e3a1f7c54..6f12fa721f 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/RouterFunctionMappingTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/RouterFunctionMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,26 +16,15 @@ package org.springframework.web.reactive.function.server.support; -import java.util.Collections; -import java.util.List; - -import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.codec.ByteBufferDecoder; -import org.springframework.http.codec.DecoderHttpMessageReader; -import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; import org.springframework.mock.web.test.server.MockServerWebExchange; -import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.function.server.HandlerFunction; -import org.springframework.web.reactive.function.server.RequestPredicates; import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; import org.springframework.web.server.ServerWebExchange; @@ -44,20 +33,10 @@ import org.springframework.web.server.ServerWebExchange; */ public class RouterFunctionMappingTests { + private final ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/match")); - private List> messageReaders; - - private ServerWebExchange exchange; - - private ServerCodecConfigurer codecConfigurer; + private final ServerCodecConfigurer codecConfigurer = ServerCodecConfigurer.create(); - @Before - public void setUp() { - this.messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); - this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/match")); - codecConfigurer = ServerCodecConfigurer.create(); - - } @Test public void normal() { @@ -88,20 +67,4 @@ public class RouterFunctionMappingTests { .verify(); } - @Configuration - @EnableWebFlux - private static class TestConfig { - - public RouterFunction match() { - HandlerFunction handlerFunction = request -> ServerResponse.ok().build(); - return RouterFunctions.route(RequestPredicates.GET("/match"), handlerFunction); - } - - public RouterFunction noMatch() { - HandlerFunction handlerFunction = request -> ServerResponse.ok().build(); - RouterFunction routerFunction = request -> Mono.empty(); - return RouterFunctions.route(RequestPredicates.GET("/no-match"), handlerFunction); - } - - } } \ No newline at end of file diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java index 6d561b6603..db9114d911 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.handler; import java.net.URI; @@ -44,6 +45,7 @@ import static org.springframework.web.reactive.HandlerMapping.PATH_WITHIN_HANDLE public class SimpleUrlHandlerMappingTests { @Test + @SuppressWarnings("resource") public void handlerMappingJavaConfig() throws Exception { AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); wac.register(WebConfig.class); @@ -61,6 +63,7 @@ public class SimpleUrlHandlerMappingTests { } @Test + @SuppressWarnings("resource") public void handlerMappingXmlConfig() throws Exception { ClassPathXmlApplicationContext wac = new ClassPathXmlApplicationContext("map.xml", getClass()); wac.refresh(); @@ -118,7 +121,7 @@ public class SimpleUrlHandlerMappingTests { @Configuration static class WebConfig { - + @Bean @SuppressWarnings("unused") public SimpleUrlHandlerMapping handlerMapping() { SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceUrlProviderTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceUrlProviderTests.java index 53892258ea..cf22e263a0 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceUrlProviderTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceUrlProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,6 @@ import org.springframework.web.util.pattern.PathPattern; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; - /** * Unit tests for {@link ResourceUrlProvider}. * @@ -133,6 +132,7 @@ public class ResourceUrlProviderTests { } @Test // SPR-12592 + @SuppressWarnings("resource") public void initializeOnce() throws Exception { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(new MockServletContext()); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/ProducesRequestConditionTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/ProducesRequestConditionTests.java index c37ef8a459..d56e411e50 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/ProducesRequestConditionTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/ProducesRequestConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.util.Collections; import org.junit.Test; -import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; import org.springframework.mock.web.test.server.MockServerWebExchange; import org.springframework.web.server.ServerWebExchange; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolverTests.java index f845bf35ca..815e601854 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,6 +58,7 @@ public class CookieValueMethodArgumentResolverTests { @Before + @SuppressWarnings("resource") public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java index 696f0e6523..cdfbc31197 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java @@ -53,6 +53,7 @@ public class ExpressionValueMethodArgumentResolverTests { @Before + @SuppressWarnings("resource") public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolverTests.java index fbd5233bf9..894d414a55 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolverTests.java @@ -62,14 +62,14 @@ import static org.springframework.mock.http.server.reactive.test.MockServerHttpR */ public class HttpEntityArgumentResolverTests { - private HttpEntityArgumentResolver resolver = createResolver(); + private final HttpEntityArgumentResolver resolver = createResolver(); private final ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build(); private HttpEntityArgumentResolver createResolver() { List> readers = new ArrayList<>(); - readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); return new HttpEntityArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance()); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java index b04c7a2c6e..917ed7f43f 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java @@ -361,6 +361,7 @@ public class ModelAttributeMethodArgumentResolverTests { } + @SuppressWarnings("unused") private static class Bar { private final String name; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java index 0438026340..a4c3f23d0f 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; import org.springframework.web.bind.support.WebBindingInitializer; @@ -61,6 +60,7 @@ import static org.mockito.Mockito.mock; /** * Unit tests for {@link ModelInitializer}. + * * @author Rossen Stoyanchev */ public class ModelInitializerTests { @@ -298,7 +298,4 @@ public class ModelInitializerTests { private static final ReflectionUtils.MethodFilter BINDER_METHODS = method -> AnnotationUtils.findAnnotation(method, InitBinder.class) != null; - private static final ReflectionUtils.MethodFilter ATTRIBUTE_METHODS = method -> - (AnnotationUtils.findAnnotation(method, RequestMapping.class) == null) && - (AnnotationUtils.findAnnotation(method, ModelAttribute.class) != null); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolverTests.java index 3404c38926..c1b34265da 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,6 +61,7 @@ public class RequestAttributeMethodArgumentResolverTests { @Before + @SuppressWarnings("resource") public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java index 3346c649c1..771ec969ee 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,7 +69,7 @@ public class RequestBodyArgumentResolverTests { @Before public void setup() { List> readers = new ArrayList<>(); - readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); + readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); this.resolver = new RequestBodyArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance()); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolverTests.java index 06c42237a9..346088e65d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,6 +70,7 @@ public class RequestHeaderMethodArgumentResolverTests { @Before + @SuppressWarnings("resource") public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java index 9f3bfb3a98..04c081e058 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package org.springframework.web.reactive.result.method.annotation; import java.io.IOException; -import org.junit.Assume; import org.junit.Test; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -30,7 +29,6 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; -import org.springframework.http.server.reactive.bootstrap.ReactorHttpServer; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SessionAttributeMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SessionAttributeMethodArgumentResolverTests.java index 99b02212a8..b8314cb6c2 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SessionAttributeMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SessionAttributeMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,6 +72,7 @@ public class SessionAttributeMethodArgumentResolverTests { @Before + @SuppressWarnings("resource") public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/AbstractViewTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/AbstractViewTests.java index e484679c38..bf8de0d9ec 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/AbstractViewTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/AbstractViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import java.util.Map; import io.reactivex.Observable; import io.reactivex.Single; -import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -45,52 +44,47 @@ import static org.junit.Assert.assertNull; */ public class AbstractViewTests { - private MockServerWebExchange exchange; + private MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); - @Before - public void setup() { - this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); - } - @SuppressWarnings("unchecked") - @Test - public void resolveAsyncAttributes() { + @Test + @SuppressWarnings("unchecked") + public void resolveAsyncAttributes() { - TestBean testBean1 = new TestBean("Bean1"); - TestBean testBean2 = new TestBean("Bean2"); - Map attributes = new HashMap<>(); - attributes.put("attr1", Mono.just(testBean1)); - attributes.put("attr2", Flux.just(testBean1, testBean2)); - attributes.put("attr3", Single.just(testBean2)); - attributes.put("attr4", Observable.just(testBean1, testBean2)); - attributes.put("attr5", Mono.empty()); + TestBean testBean1 = new TestBean("Bean1"); + TestBean testBean2 = new TestBean("Bean2"); + Map attributes = new HashMap<>(); + attributes.put("attr1", Mono.just(testBean1)); + attributes.put("attr2", Flux.just(testBean1, testBean2)); + attributes.put("attr3", Single.just(testBean2)); + attributes.put("attr4", Observable.just(testBean1, testBean2)); + attributes.put("attr5", Mono.empty()); - TestView view = new TestView(); - StepVerifier.create(view.render(attributes, null, this.exchange)).verifyComplete(); + TestView view = new TestView(); + StepVerifier.create( + view.render(attributes, null, this.exchange)).verifyComplete(); Map actual = view.attributes; assertEquals(testBean1, actual.get("attr1")); - assertArrayEquals(new TestBean[] {testBean1, testBean2}, ((List) actual.get("attr2")).toArray()); - assertEquals(testBean2, actual.get("attr3")); - assertArrayEquals(new TestBean[] {testBean1, testBean2}, ((List) actual.get("attr4")).toArray()); - assertNull(actual.get("attr5")); - } + assertArrayEquals(new TestBean[] { testBean1, testBean2 }, + ((List) actual.get("attr2")).toArray()); + assertEquals(testBean2, actual.get("attr3")); + assertArrayEquals(new TestBean[] { testBean1, testBean2 }, + ((List) actual.get("attr4")).toArray()); + assertNull(actual.get("attr5")); + } + private static class TestView extends AbstractView { - private static class TestView extends AbstractView { + private Map attributes; - private Map attributes; - - @Override - protected Mono renderInternal(Map renderAttributes, + @Override + protected Mono renderInternal(Map renderAttributes, MediaType contentType, ServerWebExchange exchange) { - this.attributes = renderAttributes; - return Mono.empty(); - } + this.attributes = renderAttributes; + return Mono.empty(); + } + } - public Map getAttributes() { - return this.attributes; - } - } } -- GitLab