From 73493bc490f4cf2010cb5583a286f94678514f64 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 20 Feb 2017 23:00:20 +0100 Subject: [PATCH] Revised imports in tests (org.jetbrains.annotations.NotNull etc) --- .../reactive/bootstrap/ReactorHttpServer.java | 10 +- .../reactive/bootstrap/RxNettyHttpServer.java | 11 +- .../reactive/DefaultCorsProcessorTests.java | 14 +- ...erverWebExchangeCheckNotModifiedTests.java | 13 +- .../adapter/WebHttpHandlerBuilderTests.java | 14 +- .../ResponseStatusExceptionHandlerTests.java | 10 +- .../function/client/DefaultWebClient.java | 38 ++---- .../reactive/DispatcherHandlerErrorTests.java | 16 +-- .../reactive/config/CorsRegistryTests.java | 13 +- .../DelegatingWebFluxConfigurationTests.java | 2 +- .../config/ResourceHandlerRegistryTests.java | 12 +- .../config/ViewResolverRegistryTests.java | 5 +- .../WebFluxConfigurationSupportTests.java | 25 ++-- .../client/DefaultWebClientTests.java | 2 +- .../client/WebClientIntegrationTests.java | 2 +- .../CachingResourceResolverTests.java | 6 +- .../CssLinkResourceTransformerTests.java | 5 +- .../resource/GzipResourceResolverTests.java | 22 ++- .../ResourceTransformerSupportTests.java | 11 +- .../resource/ResourceUrlProviderTests.java | 16 +-- .../resource/ResourceWebHandlerTests.java | 18 +-- .../result/HandlerResultHandlerTests.java | 23 ++-- .../CompositeRequestConditionTests.java | 9 +- .../RequestConditionHolderTests.java | 2 +- .../condition/RequestMappingInfoTests.java | 16 +-- .../method/HandlerMethodMappingTests.java | 9 +- .../method/InvocableHandlerMethodTests.java | 2 +- ...RequestMappingInfoHandlerMappingTests.java | 39 +++--- .../BindingContextFactoryTests.java | 4 +- .../ContextPathIntegrationTests.java | 12 +- ...ookieValueMethodArgumentResolverTests.java | 18 ++- .../ErrorsArgumentResolverTests.java | 12 +- ...ssionValueMethodArgumentResolverTests.java | 8 +- .../HttpEntityArgumentResolverTests.java | 22 +-- .../InitBinderBindingContextTests.java | 19 +-- .../MessageReaderArgumentResolverTests.java | 14 +- .../MessageWriterResultHandlerTests.java | 10 +- ...lAttributeMethodArgumentResolverTests.java | 41 +++--- ...ariableMapMethodArgumentResolverTests.java | 4 +- ...thVariableMethodArgumentResolverTests.java | 4 +- ...tAttributeMethodArgumentResolverTests.java | 12 +- .../RequestBodyArgumentResolverTests.java | 24 ++-- ...tHeaderMapMethodArgumentResolverTests.java | 33 ++--- ...uestHeaderMethodArgumentResolverTests.java | 35 +++-- .../RequestMappingHandlerMappingTests.java | 16 +-- ...stParamMapMethodArgumentResolverTests.java | 5 +- ...questParamMethodArgumentResolverTests.java | 12 +- .../ResponseBodyResultHandlerTests.java | 59 +++----- .../ResponseEntityResultHandlerTests.java | 15 +-- ...erverWebExchangeArgumentResolverTests.java | 18 +-- ...nAttributeMethodArgumentResolverTests.java | 17 +-- .../result/view/RedirectViewTests.java | 7 +- .../view/UrlBasedViewResolverTests.java | 10 +- .../ViewResolutionResultHandlerTests.java | 20 +-- .../view/freemarker/FreeMarkerViewTests.java | 10 +- .../AbstractWebSocketIntegrationTests.java | 39 +++--- .../mvc/WebContentInterceptorTests.java | 32 ++--- ...RequestMappingInfoHandlerMappingTests.java | 4 +- ...equestAttributesArgumentResolverTests.java | 6 +- .../method/annotation/CrossOriginTests.java | 6 +- ...DeferredResultReturnValueHandlerTests.java | 7 +- .../HttpEntityMethodProcessorMockTests.java | 24 ++-- .../HttpEntityMethodProcessorTests.java | 25 ++-- ...riablesMapMethodArgumentResolverTests.java | 30 ++--- ...xVariablesMethodArgumentResolverTests.java | 30 ++--- ...lAndViewMethodReturnValueHandlerTests.java | 4 +- ...ResolverMethodReturnValueHandlerTests.java | 6 +- .../MvcUriComponentsBuilderTests.java | 40 +++--- ...ariableMapMethodArgumentResolverTests.java | 25 ++-- ...thVariableMethodArgumentResolverTests.java | 24 ++-- .../RequestPartIntegrationTests.java | 4 +- ...equestPartMethodArgumentResolverTests.java | 49 ++++--- ...tResponseBodyMethodProcessorMockTests.java | 39 +++--- ...questResponseBodyMethodProcessorTests.java | 41 +++--- ...nseBodyEmitterReturnValueHandlerTests.java | 20 +-- ...ookieValueMethodArgumentResolverTests.java | 16 +-- ...letModelAttributeMethodProcessorTests.java | 126 ++++++++---------- ...etResponseMethodArgumentResolverTests.java | 13 +- ...ngResponseBodyReturnValueHandlerTests.java | 2 +- ...ntsBuilderMethodArgumentResolverTests.java | 19 +-- .../ViewMethodReturnValueHandlerTests.java | 7 +- ...ViewNameMethodReturnValueHandlerTests.java | 8 +- .../DefaultHandlerExceptionResolverTests.java | 18 ++- .../ParameterizableViewControllerTests.java | 17 +-- 84 files changed, 646 insertions(+), 861 deletions(-) diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/ReactorHttpServer.java b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/ReactorHttpServer.java index eb7e818ddc..24beffa238 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/ReactorHttpServer.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/ReactorHttpServer.java @@ -1,11 +1,11 @@ /* - * Copyright (c) 2011-2016 Pivotal Software Inc, All Rights Reserved. + * Copyright 2002-2017 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,7 +18,6 @@ package org.springframework.http.server.reactive.bootstrap; import java.util.concurrent.atomic.AtomicReference; -import org.jetbrains.annotations.NotNull; import reactor.core.Loopback; import reactor.ipc.netty.NettyContext; @@ -42,11 +41,10 @@ public class ReactorHttpServer extends AbstractHttpServer implements Loopback { this.reactorServer = reactor.ipc.netty.http.server.HttpServer.create(getHost(), getPort()); } - @NotNull private ReactorHttpHandlerAdapter createHttpHandlerAdapter() { - return getHttpHandlerMap() != null ? + return (getHttpHandlerMap() != null ? new ReactorHttpHandlerAdapter(getHttpHandlerMap()) : - new ReactorHttpHandlerAdapter(getHttpHandler()); + new ReactorHttpHandlerAdapter(getHttpHandler())); } @Override diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/RxNettyHttpServer.java b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/RxNettyHttpServer.java index 3a5bb86e71..96b4ab6253 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/RxNettyHttpServer.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/RxNettyHttpServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,14 +16,10 @@ package org.springframework.http.server.reactive.bootstrap; -import java.net.InetSocketAddress; - import io.netty.buffer.ByteBuf; -import org.jetbrains.annotations.NotNull; import org.springframework.http.server.reactive.RxNettyHttpHandlerAdapter; - /** * @author Rossen Stoyanchev */ @@ -40,11 +36,10 @@ public class RxNettyHttpServer extends AbstractHttpServer { this.rxNettyServer = io.reactivex.netty.protocol.http.server.HttpServer.newServer(getPort()); } - @NotNull private RxNettyHttpHandlerAdapter createHttpHandlerAdapter() { - return getHttpHandlerMap() != null ? + return (getHttpHandlerMap() != null ? new RxNettyHttpHandlerAdapter(getHttpHandlerMap()) : - new RxNettyHttpHandlerAdapter(getHttpHandler()); + new RxNettyHttpHandlerAdapter(getHttpHandler())); } diff --git a/spring-web/src/test/java/org/springframework/web/cors/reactive/DefaultCorsProcessorTests.java b/spring-web/src/test/java/org/springframework/web/cors/reactive/DefaultCorsProcessorTests.java index f7d5e6e6d7..348ff2d272 100644 --- a/spring-web/src/test/java/org/springframework/web/cors/reactive/DefaultCorsProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/web/cors/reactive/DefaultCorsProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,7 +16,6 @@ package org.springframework.web.cors.reactive; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; @@ -28,13 +27,8 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS; -import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN; -import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS; -import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD; +import static org.junit.Assert.*; +import static org.springframework.http.HttpHeaders.*; /** * {@link DefaultCorsProcessor} tests with simple or pre-flight CORS request. @@ -329,6 +323,7 @@ public class DefaultCorsProcessorTests { assertEquals(HttpStatus.FORBIDDEN, this.response.getStatusCode()); } + private MockServerHttpRequest.BaseBuilder actualRequest() { return corsRequest(HttpMethod.GET); } @@ -343,7 +338,6 @@ public class DefaultCorsProcessorTests { .header(HttpHeaders.ORIGIN, "http://domain2.com"); } - @NotNull private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, this.response); } diff --git a/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeCheckNotModifiedTests.java b/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeCheckNotModifiedTests.java index 4f14ca8f49..2c47ff1bf2 100644 --- a/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeCheckNotModifiedTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeCheckNotModifiedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.Locale; import java.util.TimeZone; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,10 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * "checkNotModified" unit tests for {@link DefaultServerWebExchange}. @@ -74,7 +70,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests { @Before - public void setUp() throws URISyntaxException { + public void setup() throws URISyntaxException { this.currentDate = Instant.now().truncatedTo(ChronoUnit.SECONDS); this.dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); this.dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); @@ -319,12 +315,11 @@ public class DefaultServerWebExchangeCheckNotModifiedTests { assertEquals(-1, response.getHeaders().getLastModified()); } - @NotNull + private MockServerHttpRequest.BaseBuilder request() { return MockServerHttpRequest.get("http://example.org"); } - @NotNull private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, this.response); } diff --git a/spring-web/src/test/java/org/springframework/web/server/adapter/WebHttpHandlerBuilderTests.java b/spring-web/src/test/java/org/springframework/web/server/adapter/WebHttpHandlerBuilderTests.java index 44a3f896dc..68efd6e8ae 100644 --- a/spring-web/src/test/java/org/springframework/web/server/adapter/WebHttpHandlerBuilderTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/adapter/WebHttpHandlerBuilderTests.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.server.adapter; import java.nio.charset.StandardCharsets; -import org.jetbrains.annotations.NotNull; import org.junit.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -36,16 +36,16 @@ import org.springframework.web.server.WebExceptionHandler; import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebHandler; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * Unit tests for {@link WebHttpHandlerBuilder}. + * * @author Rossen Stoyanchev */ public class WebHttpHandlerBuilderTests { - - @Test // SPR-15074 + @Test // SPR-15074 public void orderedWebFilterBeans() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(OrderedWebFilterBeanConfig.class); @@ -60,7 +60,7 @@ public class WebHttpHandlerBuilderTests { assertEquals("FilterB::FilterA", response.getBodyAsString().blockMillis(5000)); } - @Test // SPR-15074 + @Test // SPR-15074 public void orderedWebExceptionHandlerBeans() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(OrderedExceptionHandlerBeanConfig.class); @@ -90,6 +90,7 @@ public class WebHttpHandlerBuilderTests { assertEquals("handled", response.getBodyAsString().blockMillis(5000)); } + private static Mono writeToResponse(ServerWebExchange exchange, String value) { byte[] bytes = value.getBytes(StandardCharsets.UTF_8); DataBuffer buffer = new DefaultDataBufferFactory().wrap(bytes); @@ -113,7 +114,6 @@ public class WebHttpHandlerBuilderTests { return createFilter("FilterB"); } - @NotNull private WebFilter createFilter(String name) { return (exchange, chain) -> { String value = exchange.getAttribute(ATTRIBUTE).map(v -> v + "::" + name).orElse(name); @@ -131,6 +131,7 @@ public class WebHttpHandlerBuilderTests { } } + @Configuration @SuppressWarnings("unused") static class OrderedExceptionHandlerBeanConfig { @@ -153,6 +154,7 @@ public class WebHttpHandlerBuilderTests { } } + @Configuration @SuppressWarnings("unused") static class NoFilterConfig { diff --git a/spring-web/src/test/java/org/springframework/web/server/handler/ResponseStatusExceptionHandlerTests.java b/spring-web/src/test/java/org/springframework/web/server/handler/ResponseStatusExceptionHandlerTests.java index 0e44abf893..d2ca452c54 100644 --- a/spring-web/src/test/java/org/springframework/web/server/handler/ResponseStatusExceptionHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/handler/ResponseStatusExceptionHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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.server.handler; import java.time.Duration; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Mono; @@ -30,8 +29,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; /** * Unit tests for {@link ResponseStatusExceptionHandler}. @@ -48,7 +46,7 @@ public class ResponseStatusExceptionHandlerTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.handler = new ResponseStatusExceptionHandler(); this.request = MockServerHttpRequest.get("/").build(); this.response = new MockServerHttpResponse(); @@ -69,7 +67,7 @@ public class ResponseStatusExceptionHandlerTests { StepVerifier.create(mono).consumeErrorWith(actual -> assertSame(expected, actual)).verify(); } - @NotNull + private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, this.response); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java index d4ce012edd..00922bc7cd 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java @@ -25,7 +25,6 @@ import java.util.Arrays; import java.util.Map; import java.util.function.Function; -import org.jetbrains.annotations.NotNull; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -41,7 +40,6 @@ import org.springframework.web.util.DefaultUriBuilderFactory; import org.springframework.web.util.UriBuilder; import org.springframework.web.util.UriBuilderFactory; - /** * Default implementation of {@link WebClient}. * @@ -64,21 +62,10 @@ class DefaultWebClient implements WebClient { this.exchangeFunction = exchangeFunction; this.uriBuilderFactory = (factory != null ? factory : new DefaultUriBuilderFactory()); - - this.defaultHeaders = defaultHeaders != null ? - HttpHeaders.readOnlyHttpHeaders(defaultHeaders) : null; - - this.defaultCookies = defaultCookies != null ? - CollectionUtils.unmodifiableMultiValueMap(defaultCookies) : null; - } - - - private ExchangeFunction getExchangeFunction() { - return this.exchangeFunction; - } - - private UriBuilderFactory getUriBuilderFactory() { - return this.uriBuilderFactory; + this.defaultHeaders = (defaultHeaders != null ? + HttpHeaders.readOnlyHttpHeaders(defaultHeaders) : null); + this.defaultCookies = (defaultCookies != null ? + CollectionUtils.unmodifiableMultiValueMap(defaultCookies) : null); } @@ -117,12 +104,10 @@ class DefaultWebClient implements WebClient { return method(HttpMethod.OPTIONS); } - @NotNull private UriSpec method(HttpMethod httpMethod) { return new DefaultUriSpec(httpMethod); } - @Override public WebClient filter(ExchangeFilterFunction filterFunction) { ExchangeFunction filteredExchangeFunction = this.exchangeFunction.filter(filterFunction); @@ -142,17 +127,17 @@ class DefaultWebClient implements WebClient { @Override public HeaderSpec uri(String uriTemplate, Object... uriVariables) { - return uri(getUriBuilderFactory().expand(uriTemplate, uriVariables)); + return uri(uriBuilderFactory.expand(uriTemplate, uriVariables)); } @Override public HeaderSpec uri(String uriTemplate, Map uriVariables) { - return uri(getUriBuilderFactory().expand(uriTemplate, uriVariables)); + return uri(uriBuilderFactory.expand(uriTemplate, uriVariables)); } @Override public HeaderSpec uri(Function uriFunction) { - return uri(uriFunction.apply(getUriBuilderFactory().builder())); + return uri(uriFunction.apply(uriBuilderFactory.builder())); } @Override @@ -161,6 +146,7 @@ class DefaultWebClient implements WebClient { } } + private class DefaultHeaderSpec implements HeaderSpec { private final HttpMethod httpMethod; @@ -171,13 +157,11 @@ class DefaultWebClient implements WebClient { private MultiValueMap cookies; - DefaultHeaderSpec(HttpMethod httpMethod, URI uri) { this.httpMethod = httpMethod; this.uri = uri; } - private HttpHeaders getHeaders() { if (this.headers == null) { this.headers = new HttpHeaders(); @@ -263,19 +247,19 @@ class DefaultWebClient implements WebClient { @Override public Mono exchange() { ClientRequest request = this.initRequestBuilder().build(); - return getExchangeFunction().exchange(request); + return exchangeFunction.exchange(request); } @Override public Mono exchange(BodyInserter inserter) { ClientRequest request = this.initRequestBuilder().body(inserter).build(); - return getExchangeFunction().exchange(request); + return exchangeFunction.exchange(request); } @Override public > Mono exchange(S publisher, Class elementClass) { ClientRequest request = initRequestBuilder().headers(this.headers).body(publisher, elementClass).build(); - return getExchangeFunction().exchange(request); + return exchangeFunction.exchange(request); } private ClientRequest.Builder initRequestBuilder() { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java index f610f83109..d9a13e30ce 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -19,7 +19,6 @@ package org.springframework.web.reactive; import java.time.Duration; import java.util.Collections; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; import org.reactivestreams.Publisher; @@ -54,10 +53,8 @@ import org.springframework.web.server.handler.ExceptionHandlingWebHandler; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.junit.Assert.*; +import static org.springframework.http.MediaType.*; /** @@ -78,7 +75,7 @@ public class DispatcherHandlerErrorTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { AnnotationConfigApplicationContext appContext = new AnnotationConfigApplicationContext(); appContext.register(TestConfig.class); appContext.refresh(); @@ -168,7 +165,7 @@ public class DispatcherHandlerErrorTests { assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, exchange.getResponse().getStatusCode()); } - @NotNull + private ServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } @@ -201,6 +198,7 @@ public class DispatcherHandlerErrorTests { } } + @Controller @SuppressWarnings("unused") private static class TestController { @@ -228,9 +226,11 @@ public class DispatcherHandlerErrorTests { } } + private static class Foo { } + private static class ServerError500ExceptionHandler implements WebExceptionHandler { @Override diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/config/CorsRegistryTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/config/CorsRegistryTests.java index c131c28b02..db091a59e5 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/config/CorsRegistryTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/config/CorsRegistryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 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. @@ -19,13 +19,12 @@ package org.springframework.web.reactive.config; import java.util.Arrays; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import org.junit.Before; import org.junit.Test; import org.springframework.web.cors.CorsConfiguration; +import static org.junit.Assert.*; + /** * Test fixture with a {@link CorsRegistry}. * @@ -33,12 +32,8 @@ import org.springframework.web.cors.CorsConfiguration; */ public class CorsRegistryTests { - private CorsRegistry registry; + private final CorsRegistry registry = new CorsRegistry(); - @Before - public void setUp() { - this.registry = new CorsRegistry(); - } @Test public void noMapping() { 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 f7e9c0db04..d419578c66 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 @@ -68,7 +68,7 @@ public class DelegatingWebFluxConfigurationTests { @Before - public void setUp() { + public void setup() { MockitoAnnotations.initMocks(this); delegatingConfig = new DelegatingWebFluxConfiguration(); delegatingConfig.setApplicationContext(new StaticApplicationContext()); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/config/ResourceHandlerRegistryTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/config/ResourceHandlerRegistryTests.java index 7dfdff8d54..e08c7e203b 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/config/ResourceHandlerRegistryTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/config/ResourceHandlerRegistryTests.java @@ -47,11 +47,7 @@ import org.springframework.web.reactive.resource.WebJarsResourceResolver; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Unit tests for {@link ResourceHandlerRegistry}. @@ -70,7 +66,7 @@ public class ResourceHandlerRegistryTests { @Before - public void setUp() { + public void setup() { this.registry = new ResourceHandlerRegistry(new GenericApplicationContext()); this.registration = this.registry.addResourceHandler("/resources/**"); this.registration.addResourceLocations("classpath:org/springframework/web/reactive/config/"); @@ -104,8 +100,7 @@ public class ResourceHandlerRegistryTests { @Test public void cacheControl() { - assertThat(getHandler("/resources/**").getCacheControl(), - Matchers.nullValue()); + assertThat(getHandler("/resources/**").getCacheControl(), Matchers.nullValue()); this.registration.setCacheControl(CacheControl.noCache().cachePrivate()); assertThat(getHandler("/resources/**").getCacheControl().getHeaderValue(), @@ -221,6 +216,7 @@ public class ResourceHandlerRegistryTests { assertThat(transformers.get(2), Matchers.sameInstance(cssLinkTransformer)); } + private ResourceWebHandler getHandler(String pathPattern) { SimpleUrlHandlerMapping mapping = (SimpleUrlHandlerMapping) this.registry.getHandlerMapping(); return (ResourceWebHandler) mapping.getUrlMap().get(pathPattern); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/config/ViewResolverRegistryTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/config/ViewResolverRegistryTests.java index c645c7108a..e7a0d82b40 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/config/ViewResolverRegistryTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/config/ViewResolverRegistryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -39,12 +39,13 @@ public class ViewResolverRegistryTests { @Before - public void setUp() { + public void setup() { StaticWebApplicationContext context = new StaticWebApplicationContext(); context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class); this.registry = new ViewResolverRegistry(context); } + @Test public void order() { assertEquals(Ordered.LOWEST_PRECEDENCE, this.registry.getOrder()); 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 cd03137c0e..c6e09cd954 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 @@ -21,7 +21,6 @@ import java.util.Collections; import java.util.List; import javax.xml.bind.annotation.XmlRootElement; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; @@ -66,16 +65,8 @@ import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewRes import org.springframework.web.server.WebHandler; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM; -import static org.springframework.http.MediaType.APPLICATION_XML; -import static org.springframework.http.MediaType.IMAGE_PNG; -import static org.springframework.http.MediaType.TEXT_PLAIN; +import static org.junit.Assert.*; +import static org.springframework.http.MediaType.*; /** * Unit tests for {@link WebFluxConfigurationSupport}. @@ -87,7 +78,7 @@ public class WebFluxConfigurationSupportTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.request = MockServerHttpRequest.get("/").build(); } @@ -269,12 +260,11 @@ public class WebFluxConfigurationSupportTests { assertNotNull(webHandler); } - @NotNull + private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } - private void assertHasMessageReader(List> readers, Class clazz, MediaType mediaType) { ResolvableType type = ResolvableType.forClass(clazz); assertTrue(readers.stream() @@ -298,10 +288,12 @@ public class WebFluxConfigurationSupportTests { return context; } + @EnableWebFlux static class WebFluxConfig { } + @Configuration static class CustomPatchMatchConfig extends WebFluxConfigurationSupport { @@ -312,6 +304,7 @@ public class WebFluxConfigurationSupportTests { } } + @Configuration static class CustomMessageConverterConfig extends WebFluxConfigurationSupport { @@ -336,6 +329,7 @@ public class WebFluxConfigurationSupportTests { } } + @Configuration @SuppressWarnings("unused") static class CustomViewResolverConfig extends WebFluxConfigurationSupport { @@ -350,9 +344,9 @@ public class WebFluxConfigurationSupportTests { public FreeMarkerConfigurer freeMarkerConfig() { return new FreeMarkerConfigurer(); } - } + @Configuration static class CustomResourceHandlingConfig extends WebFluxConfigurationSupport { @@ -366,4 +360,5 @@ public class WebFluxConfigurationSupportTests { @XmlRootElement static class TestBean { } + } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java index 4cbf6e11fc..6a34acfcd9 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java @@ -47,7 +47,7 @@ public class DefaultWebClientTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { MockitoAnnotations.initMocks(this); this.exchangeFunction = mock(ExchangeFunction.class); when(this.exchangeFunction.exchange(captor.capture())).thenReturn(Mono.empty()); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java index 3bc0055013..1715635275 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java @@ -60,7 +60,7 @@ public class WebClientIntegrationTests { } @After - public void tearDown() throws Exception { + public void shutdown() throws Exception { this.server.shutdown(); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/CachingResourceResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/CachingResourceResolverTests.java index b4f470623d..e86306ee4f 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/CachingResourceResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/CachingResourceResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -19,7 +19,6 @@ package org.springframework.web.reactive.resource; import java.util.ArrayList; import java.util.List; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -38,6 +37,7 @@ import static org.junit.Assert.assertSame; /** * Unit tests for {@link CachingResourceResolver}. + * * @author Rossen Stoyanchev */ public class CachingResourceResolverTests { @@ -153,7 +153,7 @@ public class CachingResourceResolverTests { assertSame(gzResource, this.chain.resolveResource(createExchange(), file, this.locations).blockMillis(5000)); } - @NotNull + private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/CssLinkResourceTransformerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/CssLinkResourceTransformerTests.java index e3239f1ffe..9866be8ca8 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/CssLinkResourceTransformerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/CssLinkResourceTransformerTests.java @@ -40,8 +40,7 @@ import org.springframework.util.StringUtils; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; /** * Unit tests for {@link CssLinkResourceTransformer}. @@ -53,7 +52,7 @@ public class CssLinkResourceTransformerTests { @Before - public void setUp() { + public void setup() { ClassPathResource allowedLocation = new ClassPathResource("test/", getClass()); ResourceWebHandler resourceHandler = new ResourceWebHandler(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipResourceResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipResourceResolverTests.java index e7d32074e7..7839f3f208 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipResourceResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipResourceResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -28,7 +28,6 @@ import java.util.List; import java.util.Map; import java.util.zip.GZIPOutputStream; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -43,13 +42,12 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse import org.springframework.util.FileCopyUtils; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Unit tests for {@link GzipResourceResolver}. + * * @author Rossen Stoyanchev */ public class GzipResourceResolverTests { @@ -58,8 +56,6 @@ public class GzipResourceResolverTests { private List locations; - private Cache cache; - private MockServerHttpRequest request; @@ -80,9 +76,10 @@ public class GzipResourceResolverTests { gzFile.deleteOnExit(); } + @Before - public void setUp() { - this.cache = new ConcurrentMapCache("resourceCache"); + public void setup() { + Cache cache = new ConcurrentMapCache("resourceCache"); Map versionStrategyMap = new HashMap<>(); versionStrategyMap.put("/**", new ContentVersionStrategy()); @@ -90,7 +87,7 @@ public class GzipResourceResolverTests { versionResolver.setStrategyMap(versionStrategyMap); List resolvers = new ArrayList<>(); - resolvers.add(new CachingResourceResolver(this.cache)); + resolvers.add(new CachingResourceResolver(cache)); resolvers.add(new GzipResourceResolver()); resolvers.add(versionResolver); resolvers.add(new PathResourceResolver()); @@ -160,7 +157,7 @@ public class GzipResourceResolverTests { resolved instanceof HttpResource); } - @Test // SPR-13149 + @Test // SPR-13149 public void resolveWithNullRequest() throws IOException { String file = "js/foo.js"; Resource resolved = this.resolver.resolveResource(null, file, this.locations).blockMillis(5000); @@ -173,8 +170,9 @@ public class GzipResourceResolverTests { resolved instanceof HttpResource); } - @NotNull + private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } + } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceTransformerSupportTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceTransformerSupportTests.java index 89300883e7..f6541c2698 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceTransformerSupportTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceTransformerSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.resource; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Mono; @@ -31,7 +31,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * Unit tests for {@code ResourceTransformerSupport}. @@ -49,7 +49,7 @@ public class ResourceTransformerSupportTests { @Before - public void setUp() { + public void setup() { VersionResourceResolver versionResolver = new VersionResourceResolver(); versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy())); PathResourceResolver pathResolver = new PathResourceResolver(); @@ -63,7 +63,6 @@ public class ResourceTransformerSupportTests { this.request = MockServerHttpRequest.get("").build(); } - private ResourceUrlProvider createResourceUrlProvider(List resolvers) { ResourceWebHandler handler = new ResourceWebHandler(); handler.setLocations(Collections.singletonList(new ClassPathResource("test/", getClass()))); @@ -104,7 +103,7 @@ public class ResourceTransformerSupportTests { assertEquals("../bar-11e16cf79faee7ac698c805cf28248d2.css", actual); } - @NotNull + private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } 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 8e841ce004..8f97273923 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-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -36,12 +36,8 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import org.springframework.web.server.session.DefaultWebSessionManager; -import org.springframework.web.server.session.WebSessionManager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; /** @@ -61,7 +57,7 @@ public class ResourceUrlProviderTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.locations.add(new ClassPathResource("test/", getClass())); this.locations.add(new ClassPathResource("testalternatepath/", getClass())); this.handler.setLocations(locations); @@ -77,7 +73,7 @@ public class ResourceUrlProviderTests { assertEquals("/resources/foo.css", url); } - @Test // SPR-13374 + @Test // SPR-13374 public void getStaticResourceUrlRequestWithQueryOrHash() { MockServerHttpRequest request = MockServerHttpRequest.get("/").build(); MockServerHttpResponse response = new MockServerHttpResponse(); @@ -108,7 +104,7 @@ public class ResourceUrlProviderTests { assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url); } - @Test // SPR-12647 + @Test // SPR-12647 public void bestPatternMatch() throws Exception { ResourceWebHandler otherHandler = new ResourceWebHandler(); otherHandler.setLocations(this.locations); @@ -129,7 +125,7 @@ public class ResourceUrlProviderTests { assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url); } - @Test // SPR-12592 + @Test // SPR-12592 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/resource/ResourceWebHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java index 28b2719844..5593dc70f2 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Flux; @@ -47,18 +46,14 @@ import org.springframework.http.MediaType; import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse; import org.springframework.util.StringUtils; +import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.accept.CompositeContentTypeResolver; import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder; import org.springframework.web.server.MethodNotAllowedException; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.springframework.web.reactive.HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE; +import static org.junit.Assert.*; /** * Unit tests for {@link ResourceWebHandler}. @@ -77,7 +72,7 @@ public class ResourceWebHandlerTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { List paths = new ArrayList<>(2); paths.add(new ClassPathResource("test/", getClass())); paths.add(new ClassPathResource("testalternatepath/", getClass())); @@ -579,14 +574,13 @@ public class ResourceWebHandlerTests { assertEquals("max-age=3600", this.response.getHeaders().getCacheControl()); } - @NotNull + private ServerWebExchange createExchange(String path) { ServerWebExchange exchange = new DefaultServerWebExchange(this.request, this.response); - exchange.getAttributes().put(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, path); + exchange.getAttributes().put(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, path); return exchange; } - private long resourceLastModified(String resourceName) throws IOException { return new ClassPathResource(resourceName, getClass()).getFile().lastModified(); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/HandlerResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/HandlerResultHandlerTests.java index b0c5580bee..63b45ec893 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/HandlerResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/HandlerResultHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,34 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.result; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.jetbrains.annotations.NotNull; 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.http.server.reactive.test.MockServerHttpResponse; +import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.accept.FixedContentTypeResolver; import org.springframework.web.reactive.accept.HeaderContentTypeResolver; import org.springframework.web.reactive.accept.RequestedContentTypeResolver; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.springframework.http.MediaType.ALL; -import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8; -import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM; -import static org.springframework.http.MediaType.IMAGE_GIF; -import static org.springframework.http.MediaType.IMAGE_JPEG; -import static org.springframework.http.MediaType.IMAGE_PNG; -import static org.springframework.http.MediaType.TEXT_PLAIN; -import static org.springframework.web.reactive.HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE; +import static org.junit.Assert.*; +import static org.springframework.http.MediaType.*; /** * Unit tests for {@link AbstractHandlerResultHandler}. @@ -54,7 +48,7 @@ public class HandlerResultHandlerTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.resultHandler = new TestResultHandler(); this.request = MockServerHttpRequest.get("/path").build(); } @@ -72,7 +66,8 @@ public class HandlerResultHandlerTests { @Test public void producibleMediaTypesRequestAttribute() throws Exception { ServerWebExchange exchange = exchange(); - exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(IMAGE_GIF)); + exchange.getAttributes().put( + HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(IMAGE_GIF)); List mediaTypes = Arrays.asList(IMAGE_JPEG, IMAGE_GIF, IMAGE_PNG); MediaType actual = resultHandler.selectMediaType(exchange, () -> mediaTypes); @@ -110,7 +105,7 @@ public class HandlerResultHandlerTests { assertEquals(APPLICATION_OCTET_STREAM, actual); } - @NotNull + private DefaultServerWebExchange exchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/CompositeRequestConditionTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/CompositeRequestConditionTests.java index 80027e589f..8f47cb6be8 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/CompositeRequestConditionTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/CompositeRequestConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,7 +16,6 @@ package org.springframework.web.reactive.result.condition; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; @@ -27,9 +26,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; /** * Unit tests for {@link CompositeRequestCondition}. @@ -142,7 +139,7 @@ public class CompositeRequestConditionTests { cond1.compareTo(cond2, createExchange()); } - @NotNull + private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestConditionHolderTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestConditionHolderTests.java index c89d1d7c44..61390fffea 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestConditionHolderTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestConditionHolderTests.java @@ -42,7 +42,7 @@ public class RequestConditionHolderTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { ServerHttpRequest request = MockServerHttpRequest.get("/").build(); MockServerHttpResponse response = new MockServerHttpResponse(); this.exchange = new DefaultServerWebExchange(request, response); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestMappingInfoTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestMappingInfoTests.java index 521c5ee096..1d5f466b8e 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestMappingInfoTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestMappingInfoTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -20,7 +20,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -37,12 +36,8 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange; import org.springframework.web.server.session.MockWebSessionManager; import org.springframework.web.server.session.WebSessionManager; -import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static java.util.Arrays.*; +import static org.junit.Assert.*; /** * Unit tests for {@link RequestMappingInfo}. @@ -57,10 +52,11 @@ public class RequestMappingInfoTests { // TODO: CORS pre-flight (see @Ignored) @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.request = MockServerHttpRequest.get("/foo").build(); } + @Test public void createEmpty() { RequestMappingInfo info = new RequestMappingInfo(null, null, null, null, null, null, null); @@ -345,7 +341,7 @@ public class RequestMappingInfoTests { assertNull("Pre-flight should match the ACCESS_CONTROL_REQUEST_METHOD", match); } - @NotNull + private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/HandlerMethodMappingTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/HandlerMethodMappingTests.java index f28d1a23bf..40d3db48d7 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/HandlerMethodMappingTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/HandlerMethodMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,12 +42,11 @@ import org.springframework.web.server.session.MockWebSessionManager; import org.springframework.web.server.session.WebSessionManager; import org.springframework.web.util.ParsingPathMatcher; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; /** * Unit tests for {@link AbstractHandlerMethodMapping}. + * * @author Rossen Stoyanchev */ public class HandlerMethodMappingTests { @@ -62,7 +61,7 @@ public class HandlerMethodMappingTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.mapping = new MyHandlerMethodMapping(); this.handler = new MyHandler(); this.method1 = handler.getClass().getMethod("handlerMethod1"); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java index 21828b3c40..f91ea23320 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java @@ -54,7 +54,7 @@ public class InvocableHandlerMethodTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.exchange = new DefaultServerWebExchange( MockServerHttpRequest.get("http://localhost:8080/path").build(), new MockServerHttpResponse(), diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java index 3147d015f9..89e2e17255 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -51,7 +51,7 @@ import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.HandlerResult; import org.springframework.web.reactive.result.ResolvableMethod; -import org.springframework.web.reactive.result.method.RequestMappingInfo.BuilderConfiguration; +import org.springframework.web.reactive.result.method.RequestMappingInfo.*; import org.springframework.web.server.MethodNotAllowedException; import org.springframework.web.server.NotAcceptableStatusException; import org.springframework.web.server.ServerWebExchange; @@ -60,19 +60,14 @@ import org.springframework.web.server.UnsupportedMediaTypeStatusException; import org.springframework.web.server.adapter.DefaultServerWebExchange; import org.springframework.web.server.support.HttpRequestPathHelper; -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.springframework.web.bind.annotation.RequestMethod.GET; -import static org.springframework.web.bind.annotation.RequestMethod.HEAD; -import static org.springframework.web.bind.annotation.RequestMethod.OPTIONS; -import static org.springframework.web.reactive.result.method.RequestMappingInfo.paths; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; +import static org.springframework.web.bind.annotation.RequestMethod.*; +import static org.springframework.web.reactive.result.method.RequestMappingInfo.*; /** * Unit tests for {@link RequestMappingInfoHandlerMapping}. + * * @author Rossen Stoyanchev */ public class RequestMappingInfoHandlerMappingTests { @@ -83,7 +78,7 @@ public class RequestMappingInfoHandlerMappingTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.handlerMapping = new TestRequestMappingInfoHandlerMapping(); this.handlerMapping.registerHandler(new TestController()); } @@ -157,7 +152,7 @@ public class RequestMappingInfoHandlerMappingTests { ex -> assertEquals(new HashSet<>(Arrays.asList("GET", "HEAD")), ex.getSupportedMethods())); } - @Test // SPR-9603 + @Test // SPR-9603 public void getHandlerRequestMethodMatchFalsePositive() throws Exception { this.request = MockServerHttpRequest.get("/users").accept(MediaType.APPLICATION_XML).build(); this.handlerMapping.registerHandler(new UserController()); @@ -168,7 +163,7 @@ public class RequestMappingInfoHandlerMappingTests { .verify(); } - @Test // SPR-8462 + @Test // SPR-8462 public void getHandlerMediaTypeNotSupported() throws Exception { testHttpMediaTypeNotSupportedException("/person/1"); testHttpMediaTypeNotSupportedException("/person/1/"); @@ -186,14 +181,14 @@ public class RequestMappingInfoHandlerMappingTests { ex.getMessage())); } - @Test // SPR-8462 + @Test // SPR-8462 public void getHandlerTestMediaTypeNotAcceptable() throws Exception { testMediaTypeNotAcceptable("/persons"); testMediaTypeNotAcceptable("/persons/"); testMediaTypeNotAcceptable("/persons.json"); } - @Test // SPR-12854 + @Test // SPR-12854 public void getHandlerTestRequestParamMismatch() throws Exception { this.request = MockServerHttpRequest.get("/params").build(); Mono mono = this.handlerMapping.getHandler(createExchange()); @@ -228,7 +223,8 @@ public class RequestMappingInfoHandlerMappingTests { exchange.getAttributes().get(name)); } - @Test @SuppressWarnings("unchecked") + @Test + @SuppressWarnings("unchecked") public void handleMatchUriTemplateVariables() throws Exception { String lookupPath = "/1/2"; this.request = MockServerHttpRequest.get(lookupPath).build(); @@ -245,7 +241,7 @@ public class RequestMappingInfoHandlerMappingTests { assertEquals("2", uriVariables.get("path2")); } - @Test // SPR-9098 + @Test // SPR-9098 public void handleMatchUriTemplateVariablesDecode() throws Exception { RequestMappingInfo key = paths("/{group}/{identifier}").build(); this.request = MockServerHttpRequest.method(HttpMethod.GET, URI.create("/group/a%2Fb")).build(); @@ -352,12 +348,10 @@ public class RequestMappingInfoHandlerMappingTests { private ServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); - } @SuppressWarnings("unchecked") private void assertError(Mono mono, final Class exceptionClass, final Consumer consumer) { - StepVerifier.create(mono) .consumeErrorWith(error -> { assertEquals(exceptionClass, error.getClass()); @@ -367,7 +361,6 @@ public class RequestMappingInfoHandlerMappingTests { .verify(); } - private void testHttpMediaTypeNotSupportedException(String url) throws Exception { this.request = MockServerHttpRequest.put(url).contentType(MediaType.APPLICATION_JSON).build(); Mono mono = this.handlerMapping.getHandler(createExchange()); @@ -504,6 +497,7 @@ public class RequestMappingInfoHandlerMappingTests { } } + @SuppressWarnings("unused") @Controller private static class UserController { @@ -517,6 +511,7 @@ public class RequestMappingInfoHandlerMappingTests { } } + private static class TestRequestMappingInfoHandlerMapping extends RequestMappingInfoHandlerMapping { void registerHandler(Object handler) { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/BindingContextFactoryTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/BindingContextFactoryTests.java index 0b29aaa535..f09c2cdc78 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/BindingContextFactoryTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/BindingContextFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -57,7 +57,7 @@ public class BindingContextFactoryTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { WebFluxConfigurationSupport configurationSupport = new WebFluxConfigurationSupport(); configurationSupport.setApplicationContext(new StaticApplicationContext()); RequestMappingHandlerAdapter adapter = configurationSupport.requestMappingHandlerAdapter(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ContextPathIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ContextPathIntegrationTests.java index 2af587c1a4..bb7c0036b5 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ContextPathIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ContextPathIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -31,7 +31,7 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.DispatcherHandler; import org.springframework.web.reactive.config.EnableWebFlux; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * Integration tests that demonstrate running multiple applications under @@ -46,8 +46,7 @@ public class ContextPathIntegrationTests { @Before - public void setUp() throws Exception { - + public void setup() throws Exception { AnnotationConfigApplicationContext context1 = new AnnotationConfigApplicationContext(); context1.register(WebApp1Config.class); context1.refresh(); @@ -69,14 +68,13 @@ public class ContextPathIntegrationTests { } @After - public void tearDown() throws Exception { + public void shutdown() throws Exception { this.server.stop(); } @Test public void basic() throws Exception { - RestTemplate restTemplate = new RestTemplate(); String actual; @@ -102,6 +100,7 @@ public class ContextPathIntegrationTests { } } + @EnableWebFlux @Configuration static class WebApp2Config { @@ -112,6 +111,7 @@ public class ContextPathIntegrationTests { } } + @RestController static class TestController { 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 97f235efb8..797b5b8f57 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-2016 the original author or authors. + * Copyright 2002-2017 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.lang.reflect.Method; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Mono; @@ -36,9 +35,7 @@ import org.springframework.web.reactive.BindingContext; import org.springframework.web.server.ServerWebInputException; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Test fixture with {@link CookieValueMethodArgumentResolver}. @@ -51,20 +48,21 @@ public class CookieValueMethodArgumentResolverTests { private ServerHttpRequest request; + private BindingContext bindingContext; + private MethodParameter cookieParameter; private MethodParameter cookieStringParameter; private MethodParameter stringParameter; - private BindingContext bindingContext = new BindingContext(); - @Before - public void setUp() throws Exception { + public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); - this.resolver = new CookieValueMethodArgumentResolver(context.getBeanFactory()); + this.resolver = new CookieValueMethodArgumentResolver(context.getBeanFactory()); this.request = MockServerHttpRequest.get("/").build(); + this.bindingContext = new BindingContext(); Method method = getClass().getMethod("params", HttpCookie.class, String.class, String.class); this.cookieParameter = new SynthesizingMethodParameter(method, 0); @@ -120,7 +118,7 @@ public class CookieValueMethodArgumentResolverTests { .verify(); } - @NotNull + private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsArgumentResolverTests.java index bb075ba8e0..e85fc67b82 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -35,11 +35,8 @@ import org.springframework.web.reactive.result.ResolvableMethod; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static junit.framework.TestCase.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.springframework.core.ResolvableType.forClass; -import static org.springframework.core.ResolvableType.forClassWithGenerics; +import static org.junit.Assert.*; +import static org.springframework.core.ResolvableType.*; /** * Unit tests for {@link ErrorsMethodArgumentResolver}. @@ -60,7 +57,7 @@ public class ErrorsArgumentResolverTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.resolver = new ErrorsMethodArgumentResolver(new ReactiveAdapterRegistry()); MockServerHttpRequest request = MockServerHttpRequest.post("/path").build(); @@ -75,7 +72,6 @@ public class ErrorsArgumentResolverTests { @Test public void supports() throws Exception { - MethodParameter parameter = parameter(forClass(Errors.class)); assertTrue(this.resolver.supportsParameter(parameter)); 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 b750b27a5e..1357e8ed42 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -32,9 +32,7 @@ import org.springframework.web.reactive.BindingContext; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Unit tests for {@link ExpressionValueMethodArgumentResolver}. @@ -52,7 +50,7 @@ public class ExpressionValueMethodArgumentResolverTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); this.resolver = new ExpressionValueMethodArgumentResolver(context.getBeanFactory()); 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 dabb5c0eea..9fad32acc5 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,8 +16,6 @@ package org.springframework.web.reactive.result.method.annotation; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -38,8 +36,6 @@ import rx.Single; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.core.codec.StringDecoder; -import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpEntity; import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; @@ -53,12 +49,8 @@ import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebInputException; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.springframework.core.ResolvableType.forClassWithGenerics; +import static org.junit.Assert.*; +import static org.springframework.core.ResolvableType.*; /** * Unit tests for {@link HttpEntityArgumentResolver}.When adding a test also @@ -78,7 +70,7 @@ public class HttpEntityArgumentResolverTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.request = MockServerHttpRequest.post("/path").build(); } @@ -344,12 +336,6 @@ public class HttpEntityArgumentResolverTests { return (HttpEntity) httpEntity; } - private DataBuffer dataBuffer(String body) { - byte[] bytes = body.getBytes(StandardCharsets.UTF_8); - ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); - return new DefaultDataBufferFactory().wrap(byteBuffer); - } - @SuppressWarnings("unused") void handle( diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContextTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContextTests.java index b3020b89e1..43ef83ab34 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContextTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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.ArrayList; import java.util.Collections; import java.util.List; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; @@ -39,10 +38,7 @@ import org.springframework.web.reactive.result.method.SyncHandlerMethodArgumentR import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; /** * Unit tests for {@link InitBinderBindingContext}. @@ -58,7 +54,7 @@ public class InitBinderBindingContextTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.request = MockServerHttpRequest.get("/").build(); } @@ -125,14 +121,12 @@ public class InitBinderBindingContextTests { assertEquals("requestParam-22", dataBinder.getDisallowedFields()[0]); } - @NotNull + private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } - private BindingContext createBindingContext(String methodName, Class... parameterTypes) - throws Exception { - + private BindingContext createBindingContext(String methodName, Class... parameterTypes) throws Exception { Object handler = new InitBinderHandler(); Method method = handler.getClass().getMethod(methodName, parameterTypes); @@ -140,8 +134,7 @@ public class InitBinderBindingContextTests { handlerMethod.setArgumentResolvers(new ArrayList<>(this.argumentResolvers)); handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer()); - return new InitBinderBindingContext( - this.bindingInitializer, Collections.singletonList(handlerMethod)); + return new InitBinderBindingContext(this.bindingInitializer, Collections.singletonList(handlerMethod)); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java index f96ba7fbe7..c146fbcf88 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -30,7 +30,6 @@ import javax.xml.bind.annotation.XmlRootElement; import io.reactivex.Flowable; import io.reactivex.Maybe; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Flux; @@ -59,12 +58,8 @@ import org.springframework.web.server.ServerWebInputException; import org.springframework.web.server.UnsupportedMediaTypeStatusException; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.springframework.core.ResolvableType.forClass; -import static org.springframework.core.ResolvableType.forClassWithGenerics; +import static org.junit.Assert.*; +import static org.springframework.core.ResolvableType.*; /** * Unit tests for {@link AbstractMessageReaderArgumentResolver}. @@ -83,7 +78,7 @@ public class MessageReaderArgumentResolverTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.request = request().build(); ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setValidator(new TestBeanValidator()); @@ -314,7 +309,6 @@ public class MessageReaderArgumentResolverTests { return MockServerHttpRequest.post("/path"); } - @NotNull private DefaultServerWebExchange exchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java index 3ac2007a38..1a6bfff891 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -79,7 +79,7 @@ public class MessageWriterResultHandlerTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.resultHandler = createResultHandler(); ServerHttpRequest request = MockServerHttpRequest.get("/path").build(); this.exchange = new DefaultServerWebExchange(request, this.response); @@ -222,6 +222,7 @@ public class MessageWriterResultHandlerTests { } } + @JsonTypeName("foo") private static class Foo extends ParentClass { @@ -230,6 +231,7 @@ public class MessageWriterResultHandlerTests { } } + @JsonTypeName("bar") private static class Bar extends ParentClass { @@ -238,12 +240,14 @@ public class MessageWriterResultHandlerTests { } } + private interface Identifiable extends Serializable { @SuppressWarnings("unused") Long getId(); } + @SuppressWarnings({ "serial" }) private static class SimpleBean implements Identifiable { @@ -266,6 +270,7 @@ public class MessageWriterResultHandlerTests { } } + @SuppressWarnings("unused") private static class TestController { @@ -296,7 +301,6 @@ public class MessageWriterResultHandlerTests { Identifiable identifiable() { return null; } List listIdentifiable() { return null; } - } } 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 8387cc975d..04c14aed4e 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 @@ -60,7 +60,7 @@ public class ModelAttributeMethodArgumentResolverTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean(); validator.afterPropertiesSet(); ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); @@ -71,7 +71,6 @@ public class ModelAttributeMethodArgumentResolverTests { @Test public void supports() throws Exception { - ModelAttributeMethodArgumentResolver resolver = new ModelAttributeMethodArgumentResolver(new ReactiveAdapterRegistry(), false); @@ -90,7 +89,6 @@ public class ModelAttributeMethodArgumentResolverTests { @Test public void supportsWithDefaultResolution() throws Exception { - ModelAttributeMethodArgumentResolver resolver = new ModelAttributeMethodArgumentResolver(new ReactiveAdapterRegistry(), true); @@ -191,6 +189,24 @@ public class ModelAttributeMethodArgumentResolverTests { }); } + private void testBindFoo(ResolvableType type, Function valueExtractor) throws Exception { + Object value = createResolver() + .resolveArgument(parameter(type), this.bindContext, exchange("name=Robert&age=25")) + .blockMillis(0); + + Foo foo = valueExtractor.apply(value); + assertEquals("Robert", foo.getName()); + + String key = "foo"; + String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + key; + + Map map = bindContext.getModel().asMap(); + assertEquals(map.toString(), 2, map.size()); + assertSame(foo, map.get(key)); + assertNotNull(map.get(bindingResultKey)); + assertTrue(map.get(bindingResultKey) instanceof BindingResult); + } + @Test public void validationError() throws Exception { testValidationError(forClass(Foo.class), resolvedArgumentMono -> resolvedArgumentMono); @@ -220,25 +236,6 @@ public class ModelAttributeMethodArgumentResolverTests { }); } - - private void testBindFoo(ResolvableType type, Function valueExtractor) throws Exception { - Object value = createResolver() - .resolveArgument(parameter(type), this.bindContext, exchange("name=Robert&age=25")) - .blockMillis(0); - - Foo foo = valueExtractor.apply(value); - assertEquals("Robert", foo.getName()); - - String key = "foo"; - String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + key; - - Map map = bindContext.getModel().asMap(); - assertEquals(map.toString(), 2, map.size()); - assertSame(foo, map.get(key)); - assertNotNull(map.get(bindingResultKey)); - assertTrue(map.get(bindingResultKey) instanceof BindingResult); - } - private void testValidationError(ResolvableType type, Function, Mono> valueMonoExtractor) throws URISyntaxException { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMapMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMapMethodArgumentResolverTests.java index d64a6e9fe5..b5bf241d2b 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMapMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMapMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -56,7 +56,7 @@ public class PathVariableMapMethodArgumentResolverTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.resolver = new PathVariableMapMethodArgumentResolver(); ServerHttpRequest request = MockServerHttpRequest.get("/").build(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolverTests.java index 462964aa4d..f308bf3e0e 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -67,7 +67,7 @@ public class PathVariableMethodArgumentResolverTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.resolver = new PathVariableMethodArgumentResolver(null); ServerHttpRequest request = MockServerHttpRequest.get("/").build(); 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 341df6b12c..e9acc622cb 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-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -41,12 +41,7 @@ import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebInputException; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Unit tests for {@link RequestAttributeMethodArgumentResolver}. @@ -63,8 +58,7 @@ public class RequestAttributeMethodArgumentResolverTests { @Before - @SuppressWarnings("ConfusingArgumentToVarargsMethod") - public void setUp() throws Exception { + public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); this.resolver = new RequestAttributeMethodArgumentResolver(context.getBeanFactory()); 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 4de65e418c..54edcfd740 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-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -46,13 +46,8 @@ import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebInputException; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.springframework.core.ResolvableType.forClass; -import static org.springframework.core.ResolvableType.forClassWithGenerics; +import static org.junit.Assert.*; +import static org.springframework.core.ResolvableType.*; /** * Unit tests for {@link RequestBodyArgumentResolver}. When adding a test also @@ -63,19 +58,18 @@ import static org.springframework.core.ResolvableType.forClassWithGenerics; */ public class RequestBodyArgumentResolverTests { - private RequestBodyArgumentResolver resolver = resolver(); + private RequestBodyArgumentResolver resolver; - private ResolvableMethod testMethod = ResolvableMethod.onClass(this.getClass()).name("handle"); + private ResolvableMethod testMethod; @Before - public void setUp() throws Exception { - } - - private RequestBodyArgumentResolver resolver() { + public void setup() { List> readers = new ArrayList<>(); readers.add(new DecoderHttpMessageReader<>(new StringDecoder())); - return new RequestBodyArgumentResolver(readers); + this.resolver = new RequestBodyArgumentResolver(readers); + + this.testMethod = ResolvableMethod.onClass(getClass()).name("handle"); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java index 518f9d631a..f0fb9b771e 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -20,7 +20,6 @@ import java.lang.reflect.Method; import java.util.Collections; import java.util.Map; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Mono; @@ -34,12 +33,9 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Unit tests for {@link RequestHeaderMapMethodArgumentResolver}. @@ -50,25 +46,24 @@ public class RequestHeaderMapMethodArgumentResolverTests { private RequestHeaderMapMethodArgumentResolver resolver; + private ServerHttpRequest request; + private MethodParameter paramMap; private MethodParameter paramMultiValueMap; private MethodParameter paramHttpHeaders; private MethodParameter paramUnsupported; - private ServerHttpRequest request; - @Before - public void setUp() throws Exception { + public void setup() throws Exception { resolver = new RequestHeaderMapMethodArgumentResolver(); + request = MockServerHttpRequest.get("/").build(); Method method = getClass().getMethod("params", Map.class, MultiValueMap.class, HttpHeaders.class, Map.class); paramMap = new SynthesizingMethodParameter(method, 0); paramMultiValueMap = new SynthesizingMethodParameter(method, 1); paramHttpHeaders = new SynthesizingMethodParameter(method, 2); paramUnsupported = new SynthesizingMethodParameter(method, 3); - - this.request = MockServerHttpRequest.get("/").build(); } @@ -85,9 +80,9 @@ public class RequestHeaderMapMethodArgumentResolverTests { String name = "foo"; String value = "bar"; Map expected = Collections.singletonMap(name, value); - this.request = MockServerHttpRequest.get("/").header(name, value).build(); + request = MockServerHttpRequest.get("/").header(name, value).build(); - Mono mono = this.resolver.resolveArgument(paramMap, null, createExchange()); + Mono mono = resolver.resolveArgument(paramMap, null, createExchange()); Object result = mono.block(); assertTrue(result instanceof Map); @@ -99,13 +94,13 @@ public class RequestHeaderMapMethodArgumentResolverTests { String name = "foo"; String value1 = "bar"; String value2 = "baz"; - this.request = MockServerHttpRequest.get("/").header(name, value1, value2).build(); + request = MockServerHttpRequest.get("/").header(name, value1, value2).build(); MultiValueMap expected = new LinkedMultiValueMap<>(1); expected.add(name, value1); expected.add(name, value2); - Mono mono = this.resolver.resolveArgument(paramMultiValueMap, null, createExchange()); + Mono mono = resolver.resolveArgument(paramMultiValueMap, null, createExchange()); Object result = mono.block(); assertTrue(result instanceof MultiValueMap); @@ -117,22 +112,22 @@ public class RequestHeaderMapMethodArgumentResolverTests { String name = "foo"; String value1 = "bar"; String value2 = "baz"; - this.request = MockServerHttpRequest.get("/").header(name, value1, value2).build(); + request = MockServerHttpRequest.get("/").header(name, value1, value2).build(); HttpHeaders expected = new HttpHeaders(); expected.add(name, value1); expected.add(name, value2); - Mono mono = this.resolver.resolveArgument(paramHttpHeaders, null, createExchange()); + Mono mono = resolver.resolveArgument(paramHttpHeaders, null, createExchange()); Object result = mono.block(); assertTrue(result instanceof HttpHeaders); assertEquals("Invalid result", expected, result); } - @NotNull + private DefaultServerWebExchange createExchange() { - return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); + return new DefaultServerWebExchange(request, new MockServerHttpResponse()); } 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 93bdcb7a5d..e4d2215fa3 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-2016 the original author or authors. + * Copyright 2002-2017 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.time.format.DateTimeFormatter; import java.util.Date; import java.util.Map; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Mono; @@ -42,10 +41,7 @@ import org.springframework.web.reactive.BindingContext; import org.springframework.web.server.ServerWebInputException; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Unit tests for {@link RequestHeaderMethodArgumentResolver}. @@ -56,6 +52,10 @@ public class RequestHeaderMethodArgumentResolverTests { private RequestHeaderMethodArgumentResolver resolver; + private ServerHttpRequest request; + + private BindingContext bindingContext; + private MethodParameter paramNamedDefaultValueStringHeader; private MethodParameter paramNamedValueStringArray; private MethodParameter paramSystemProperty; @@ -65,18 +65,19 @@ public class RequestHeaderMethodArgumentResolverTests { private MethodParameter paramDate; private MethodParameter paramInstant; - private ServerHttpRequest request; - - private BindingContext bindingContext; - @Before - public void setUp() throws Exception { + public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); this.resolver = new RequestHeaderMethodArgumentResolver(context.getBeanFactory()); - @SuppressWarnings("ConfusingArgumentToVarargsMethod") + this.request = MockServerHttpRequest.get("/").build(); + + ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); + initializer.setConversionService(new DefaultFormattingConversionService()); + this.bindingContext = new BindingContext(initializer); + Method method = ReflectionUtils.findMethod(getClass(), "params", (Class[]) null); this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 0); this.paramNamedValueStringArray = new SynthesizingMethodParameter(method, 1); @@ -86,12 +87,6 @@ public class RequestHeaderMethodArgumentResolverTests { this.paramNamedValueMap = new SynthesizingMethodParameter(method, 5); this.paramDate = new SynthesizingMethodParameter(method, 6); this.paramInstant = new SynthesizingMethodParameter(method, 7); - - this.request = MockServerHttpRequest.get("/").build(); - - ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); - initializer.setConversionService(new DefaultFormattingConversionService()); - this.bindingContext = new BindingContext(initializer); } @@ -227,9 +222,9 @@ public class RequestHeaderMethodArgumentResolverTests { assertEquals(Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(rfc1123val)), result); } - @NotNull + private DefaultServerWebExchange createExchange() { - return new DefaultServerWebExchange(request, new MockServerHttpResponse()); + return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMappingTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMappingTests.java index 6f07210efb..b925a6e0ca 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMappingTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,13 +43,8 @@ import org.springframework.web.context.support.StaticWebApplicationContext; import org.springframework.web.reactive.accept.MappingContentTypeResolver; import org.springframework.web.reactive.result.method.RequestMappingInfo; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; /** * Unit tests for {@link RequestMappingHandlerMapping}. @@ -64,7 +59,7 @@ public class RequestMappingHandlerMappingTests { @Before - public void setUp() throws Exception { + public void setup() { this.handlerMapping.setApplicationContext(wac); } @@ -181,6 +176,7 @@ public class RequestMappingHandlerMappingTests { assertComposedAnnotationMapping(RequestMethod.PATCH); } + private RequestMappingInfo assertComposedAnnotationMapping(RequestMethod requestMethod) throws Exception { String methodName = requestMethod.name().toLowerCase(); String path = "/" + methodName; @@ -240,9 +236,9 @@ public class RequestMappingHandlerMappingTests { @PatchMapping("/patch") public void patch() { } - } + @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java index 574008c739..82fc522d17 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -53,9 +53,8 @@ public class RequestParamMapMethodArgumentResolverTests { private MethodParameter paramMapWithoutAnnot; - @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.resolver = new RequestParamMapMethodArgumentResolver(); Method method = getClass().getMethod("params", Map.class, MultiValueMap.class, Map.class, Map.class); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolverTests.java index 1066f31f49..52e09fbec5 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,11 +42,7 @@ import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebInputException; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Unit tests for {@link RequestParamMethodArgumentResolver}. @@ -69,8 +65,8 @@ public class RequestParamMethodArgumentResolverTests { private BindingContext bindContext; - @Before @SuppressWarnings("ConfusingArgumentToVarargsMethod") - public void setUp() throws Exception { + @Before + public void setup() throws Exception { this.resolver = new RequestParamMethodArgumentResolver(null, true); ParameterNameDiscoverer paramNameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandlerTests.java index 51a80bd1d5..2420201e9b 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -17,7 +17,6 @@ package org.springframework.web.reactive.result.method.annotation; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.junit.Before; @@ -34,22 +33,15 @@ import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.ResourceHttpMessageWriter; import org.springframework.http.codec.json.Jackson2JsonEncoder; import org.springframework.http.codec.xml.Jaxb2XmlEncoder; -import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; -import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse; import org.springframework.stereotype.Controller; -import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.method.HandlerMethod; import org.springframework.web.reactive.HandlerResult; import org.springframework.web.reactive.accept.RequestedContentTypeResolver; import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder; -import org.springframework.web.server.ServerWebExchange; -import org.springframework.web.server.adapter.DefaultServerWebExchange; - -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * Unit tests for {@link ResponseBodyResultHandler}.When adding a test also @@ -66,41 +58,20 @@ public class ResponseBodyResultHandlerTests { private ResponseBodyResultHandler resultHandler; - private MockServerHttpResponse response; - - private ServerWebExchange exchange; - @Before - public void setUp() throws Exception { - this.resultHandler = createHandler(); - initExchange(); - } - - private void initExchange() { - ServerHttpRequest request = MockServerHttpRequest.get("/").build(); - this.response = new MockServerHttpResponse(); - this.exchange = new DefaultServerWebExchange(request, this.response); - } - - - private ResponseBodyResultHandler createHandler(HttpMessageWriter... writers) { - List> writerList; - if (ObjectUtils.isEmpty(writers)) { - writerList = new ArrayList<>(); - writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder())); - writerList.add(new EncoderHttpMessageWriter<>(new CharSequenceEncoder())); - writerList.add(new ResourceHttpMessageWriter()); - writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder())); - writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())); - } - else { - writerList = Arrays.asList(writers); - } + public void setup() throws Exception { + List> writerList = new ArrayList<>(5); + writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder())); + writerList.add(new EncoderHttpMessageWriter<>(new CharSequenceEncoder())); + writerList.add(new ResourceHttpMessageWriter()); + writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder())); + writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())); RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build(); - return new ResponseBodyResultHandler(writerList, resolver); + this.resultHandler = new ResponseBodyResultHandler(writerList, resolver); } + @Test public void supports() throws NoSuchMethodException { Object controller = new TestController(); @@ -133,7 +104,8 @@ public class ResponseBodyResultHandlerTests { } - @RestController @SuppressWarnings("unused") + @RestController + @SuppressWarnings("unused") private static class TestRestController { public Mono handleToMonoVoid() { return null;} @@ -163,7 +135,9 @@ public class ResponseBodyResultHandlerTests { } } - @Controller @SuppressWarnings("unused") + + @Controller + @SuppressWarnings("unused") private static class TestController { @ResponseBody @@ -174,7 +148,6 @@ public class ResponseBodyResultHandlerTests { public String doWork() { return null; } - } } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java index a896d639e1..409317a1c7 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Mono; @@ -60,12 +59,9 @@ import org.springframework.web.reactive.result.ResolvableMethod; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.springframework.core.ResolvableType.forClassWithGenerics; -import static org.springframework.http.ResponseEntity.notFound; -import static org.springframework.http.ResponseEntity.ok; +import static org.junit.Assert.*; +import static org.springframework.core.ResolvableType.*; +import static org.springframework.http.ResponseEntity.*; /** * Unit tests for {@link ResponseEntityResultHandler}. When adding a test also @@ -86,7 +82,7 @@ public class ResponseEntityResultHandlerTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.resultHandler = createHandler(); initExchange(); } @@ -325,7 +321,6 @@ public class ResponseEntityResultHandlerTests { assertResponseBody("abc"); } - @NotNull private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, this.response); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolverTests.java index 99510ee152..252f0fd6d6 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -34,10 +34,8 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange; import org.springframework.web.server.session.MockWebSessionManager; import org.springframework.web.server.session.WebSessionManager; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; /** * Unit tests for {@link ServerWebExchangeArgumentResolver}. @@ -45,15 +43,15 @@ import static org.mockito.Mockito.mock; */ public class ServerWebExchangeArgumentResolverTests { - private ServerWebExchangeArgumentResolver resolver = new ServerWebExchangeArgumentResolver(); + private final ResolvableMethod testMethod = ResolvableMethod.onClass(getClass()).name("handle"); - private ServerWebExchange exchange; + private final ServerWebExchangeArgumentResolver resolver = new ServerWebExchangeArgumentResolver(); - private ResolvableMethod testMethod = ResolvableMethod.onClass(getClass()).name("handle"); + private ServerWebExchange exchange; @Before - public void setUp() throws Exception { + public void setup() throws Exception { ServerHttpRequest request = MockServerHttpRequest.get("/path").build(); ServerHttpResponse response = new MockServerHttpResponse(); @@ -61,6 +59,7 @@ public class ServerWebExchangeArgumentResolverTests { this.exchange = new DefaultServerWebExchange(request, response, sessionManager); } + @Test public void supportsParameter() throws Exception { assertTrue(this.resolver.supportsParameter(parameter(ServerWebExchange.class))); @@ -78,6 +77,7 @@ public class ServerWebExchangeArgumentResolverTests { testResolveArgument(parameter(HttpMethod.class), HttpMethod.GET); } + private void testResolveArgument(MethodParameter parameter, Object expected) { Mono mono = this.resolver.resolveArgument(parameter, new BindingContext(), this.exchange); assertSame(expected, mono.block()); 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 dce012ff71..f4c007e31c 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-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -44,17 +44,12 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange; import org.springframework.web.server.session.MockWebSessionManager; import org.springframework.web.server.session.WebSessionManager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; /** * Unit tests for {@link SessionAttributeMethodArgumentResolver}. + * * @author Rossen Stoyanchev */ public class SessionAttributeMethodArgumentResolverTests { @@ -69,8 +64,7 @@ public class SessionAttributeMethodArgumentResolverTests { @Before - @SuppressWarnings("ConfusingArgumentToVarargsMethod") - public void setUp() throws Exception { + public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); this.resolver = new SessionAttributeMethodArgumentResolver(context.getBeanFactory()); @@ -84,6 +78,7 @@ public class SessionAttributeMethodArgumentResolverTests { this.handleMethod = ReflectionUtils.findMethod(getClass(), "handleWithSessionAttribute", (Class[]) null); } + @Test public void supportsParameter() throws Exception { assertTrue(this.resolver.supportsParameter(new MethodParameter(this.handleMethod, 0))); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/RedirectViewTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/RedirectViewTests.java index 010dad20e5..8df9804717 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/RedirectViewTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/RedirectViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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 java.util.HashMap; import java.util.Map; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; @@ -50,7 +49,7 @@ public class RedirectViewTests { @Before - public void setUp() { + public void setup() { this.request = MockServerHttpRequest.get("/").contextPath("/context").build(); this.response = new MockServerHttpResponse(); } @@ -142,7 +141,7 @@ public class RedirectViewTests { this.response.getHeaders().getLocation()); } - @NotNull + private DefaultServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, this.response); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/UrlBasedViewResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/UrlBasedViewResolverTests.java index c06afb6580..2be460f727 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/UrlBasedViewResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/UrlBasedViewResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -19,17 +19,17 @@ package org.springframework.web.reactive.result.view; import java.util.Locale; import java.util.Map; -import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; import org.springframework.context.support.StaticApplicationContext; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.web.server.ServerWebExchange; -import reactor.test.StepVerifier; +import static org.junit.Assert.*; /** * Unit tests for {@link UrlBasedViewResolver}. @@ -42,13 +42,14 @@ public class UrlBasedViewResolverTests { private UrlBasedViewResolver resolver; @Before - public void setUp() { + public void setup() { StaticApplicationContext context = new StaticApplicationContext(); context.refresh(); resolver = new UrlBasedViewResolver(); resolver.setApplicationContext(context); } + @Test public void viewNames() throws Exception { resolver.setViewClass(TestView.class); @@ -90,6 +91,7 @@ public class UrlBasedViewResolverTests { .expectComplete(); } + private static class TestView extends AbstractUrlBasedView { @Override diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java index 918c25885c..9165577f97 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -41,6 +41,7 @@ import org.springframework.core.Ordered; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DefaultDataBufferFactory; +import org.springframework.core.io.buffer.support.DataBufferTestUtils; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; @@ -57,13 +58,11 @@ import org.springframework.web.server.NotAcceptableStatusException; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.springframework.core.ResolvableType.forClass; -import static org.springframework.core.ResolvableType.forClassWithGenerics; -import static org.springframework.core.io.buffer.support.DataBufferTestUtils.dumpString; -import static org.springframework.http.MediaType.APPLICATION_JSON; +import static java.nio.charset.StandardCharsets.*; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; +import static org.springframework.core.ResolvableType.*; +import static org.springframework.http.MediaType.*; /** * Unit tests for {@link ViewResolutionResultHandler}. @@ -77,7 +76,7 @@ public class ViewResolutionResultHandlerTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.request = MockServerHttpRequest.get("/path").build(); } @@ -288,6 +287,7 @@ public class ViewResolutionResultHandlerTests { "}"); } + private ServerWebExchange createExchange() { return new DefaultServerWebExchange(this.request, new MockServerHttpResponse()); } @@ -336,7 +336,7 @@ public class ViewResolutionResultHandlerTests { private void assertResponseBody(ServerWebExchange exchange, String responseBody) { MockServerHttpResponse response = (MockServerHttpResponse) exchange.getResponse(); StepVerifier.create(response.getBody()) - .consumeNextWith(buf -> assertEquals(responseBody, dumpString(buf, UTF_8))) + .consumeNextWith(buf -> assertEquals(responseBody, DataBufferTestUtils.dumpString(buf, UTF_8))) .expectComplete() .verify(); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java index 5e8d56d97e..25a1684e1d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -37,8 +37,7 @@ import org.springframework.ui.ModelMap; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author Rossen Stoyanchev @@ -61,7 +60,7 @@ public class FreeMarkerViewTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.context = new GenericApplicationContext(); this.context.refresh(); @@ -71,9 +70,6 @@ public class FreeMarkerViewTests { configurer.setResourceLoader(this.context); this.freeMarkerConfig = configurer.createConfiguration(); - FreeMarkerView fv = new FreeMarkerView(); - fv.setApplicationContext(this.context); - MockServerHttpRequest request = MockServerHttpRequest.get("/path").build(); this.response = new MockServerHttpResponse(); this.exchange = new DefaultServerWebExchange(request, this.response); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.java index 048708e2af..5c341c6857 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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.socket; import java.io.File; @@ -21,7 +22,6 @@ import java.net.URI; import java.net.URISyntaxException; import org.apache.tomcat.websocket.server.WsContextListener; -import org.jetbrains.annotations.NotNull; import org.junit.After; import org.junit.Before; import org.junit.runner.RunWith; @@ -61,7 +61,7 @@ import org.springframework.web.reactive.socket.server.upgrade.RxNettyRequestUpgr import org.springframework.web.reactive.socket.server.upgrade.TomcatRequestUpgradeStrategy; import org.springframework.web.reactive.socket.server.upgrade.UndertowRequestUpgradeStrategy; -import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.*; /** * Base class for WebSocket integration tests. Sub-classes must implement @@ -123,7 +123,6 @@ public abstract class AbstractWebSocketIntegrationTests { @Before public void setup() throws Exception { - // TODO // Caused by: java.io.IOException: Upgrade responses cannot have a transfer coding // at org.xnio.http.HttpUpgrade$HttpUpgradeState.handleUpgrade(HttpUpgrade.java:490) @@ -146,6 +145,15 @@ public abstract class AbstractWebSocketIntegrationTests { } } + @After + public void stop() throws Exception { + if (this.client instanceof Lifecycle) { + ((Lifecycle) this.client).stop(); + } + this.server.stop(); + } + + private HttpHandler createHttpHandler() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(DispatcherConfig.class, this.serverConfigClass); @@ -154,16 +162,12 @@ public abstract class AbstractWebSocketIntegrationTests { return DispatcherHandler.toHttpHandler(context); } - protected abstract Class getWebConfigClass(); - - @After - public void tearDown() throws Exception { - if (this.client instanceof Lifecycle) { - ((Lifecycle) this.client).stop(); - } - this.server.stop(); + protected URI getUrl(String path) throws URISyntaxException { + return new URI("ws://localhost:" + this.port + path); } + protected abstract Class getWebConfigClass(); + @Configuration static class DispatcherConfig { @@ -174,11 +178,6 @@ public abstract class AbstractWebSocketIntegrationTests { } } - @NotNull - protected URI getUrl(String path) throws URISyntaxException { - return new URI("ws://localhost:" + this.port + path); - } - static abstract class AbstractHandlerAdapterConfig { @@ -193,9 +192,9 @@ public abstract class AbstractWebSocketIntegrationTests { } protected abstract RequestUpgradeStrategy getUpgradeStrategy(); - } + @Configuration static class ReactorNettyConfig extends AbstractHandlerAdapterConfig { @@ -205,6 +204,7 @@ public abstract class AbstractWebSocketIntegrationTests { } } + @Configuration static class RxNettyConfig extends AbstractHandlerAdapterConfig { @@ -214,6 +214,7 @@ public abstract class AbstractWebSocketIntegrationTests { } } + @Configuration static class TomcatConfig extends AbstractHandlerAdapterConfig { @@ -223,6 +224,7 @@ public abstract class AbstractWebSocketIntegrationTests { } } + @Configuration static class UndertowConfig extends AbstractHandlerAdapterConfig { @@ -232,6 +234,7 @@ public abstract class AbstractWebSocketIntegrationTests { } } + @Configuration static class JettyConfig extends AbstractHandlerAdapterConfig { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java index 1ba056dceb..8f8d5ed1df 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 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,18 +16,16 @@ package org.springframework.web.servlet.mvc; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.*; - import java.util.Properties; import org.hamcrest.Matchers; -import org.junit.Before; import org.junit.Test; import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.mock.web.test.MockHttpServletResponse; -import org.springframework.web.servlet.support.WebContentGenerator; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; /** * @author Rick Evans @@ -35,17 +33,9 @@ import org.springframework.web.servlet.support.WebContentGenerator; */ public class WebContentInterceptorTests { - private MockHttpServletRequest request; + private MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); - private MockHttpServletResponse response; - - - @Before - public void setUp() throws Exception { - request = new MockHttpServletRequest(); - request.setMethod(WebContentGenerator.METHOD_GET); - response = new MockHttpServletResponse(); - } + private MockHttpServletResponse response = new MockHttpServletResponse(); @Test @@ -68,14 +58,14 @@ public class WebContentInterceptorTests { interceptor.setCacheSeconds(10); interceptor.setCacheMappings(mappings); -// request.setRequestURI("http://localhost:7070/example/adminhandle.vm"); + // request.setRequestURI("http://localhost:7070/example/adminhandle.vm"); request.setRequestURI("example/adminhandle.vm"); interceptor.preHandle(request, response, null); Iterable cacheControlHeaders = response.getHeaders("Cache-Control"); assertThat(cacheControlHeaders, Matchers.emptyIterable()); -// request.setRequestURI("http://localhost:7070/example/bingo.html"); + // request.setRequestURI("http://localhost:7070/example/bingo.html"); request.setRequestURI("example/bingo.html"); interceptor.preHandle(request, response, null); @@ -148,7 +138,7 @@ public class WebContentInterceptorTests { mappings.setProperty("*/*.cache.html", "10"); // was **/*.cache.html interceptor.setCacheMappings(mappings); -// request.setRequestURI("http://example.org/foo/page.html"); + // request.setRequestURI("http://example.org/foo/page.html"); request.setRequestURI("foo/page.html"); interceptor.preHandle(request, response, null); @@ -159,9 +149,9 @@ public class WebContentInterceptorTests { Iterable pragmaHeaders = response.getHeaders("Pragma"); assertThat(pragmaHeaders, Matchers.contains("no-cache")); + // request.setRequestURI("http://example.org/page.cache.html"); + request = new MockHttpServletRequest("GET", "foo/page.cache.html"); response = new MockHttpServletResponse(); -// request.setRequestURI("http://example.org/page.cache.html"); - request.setRequestURI("foo/page.cache.html"); interceptor.preHandle(request, response, null); expiresHeaders = response.getHeaders("Expires"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java index e327e822e3..0ebaca7614 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -84,7 +84,7 @@ public class RequestMappingInfoHandlerMappingTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { TestController testController = new TestController(); this.fooMethod = new HandlerMethod(testController, "foo"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractRequestAttributesArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractRequestAttributesArgumentResolverTests.java index cc2dc56e8c..2e0d6cc792 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractRequestAttributesArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractRequestAttributesArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -62,11 +62,13 @@ public abstract class AbstractRequestAttributesArgumentResolverTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { HttpServletRequest request = new MockHttpServletRequest(); HttpServletResponse response = new MockHttpServletResponse(); this.webRequest = new ServletWebRequest(request, response); + this.resolver = createResolver(); + this.handleMethod = AbstractRequestAttributesArgumentResolverTests.class .getDeclaredMethod(getHandleMethodName(), Foo.class, Foo.class, Foo.class, Optional.class); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java index e1ee78a52a..3d7088aa3c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -74,7 +74,7 @@ public class CrossOriginTests { @Before - public void setUp() { + public void setup() { StaticWebApplicationContext wac = new StaticWebApplicationContext(); Properties props = new Properties(); props.setProperty("myOrigin", "http://example.com"); @@ -89,6 +89,7 @@ public class CrossOriginTests { this.request.addHeader(HttpHeaders.ORIGIN, "http://domain.com/"); } + @Test public void noAnnotationWithoutOrigin() throws Exception { this.handlerMapping.registerHandler(new MethodLevelController()); @@ -288,6 +289,7 @@ public class CrossOriginTests { assertNull(this.handlerMapping.getHandler(request)); } + private CorsConfiguration getCorsConfiguration(HandlerExecutionChain chain, boolean isPreFlightRequest) { if (isPreFlightRequest) { Object handler = chain.getHandler(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java index 9e902ac621..47ab93dea7 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -41,6 +41,7 @@ import static org.junit.Assert.assertTrue; /** * Unit tests for {@link DeferredResultMethodReturnValueHandler}. + * * @author Rossen Stoyanchev */ public class DeferredResultReturnValueHandlerTests { @@ -53,7 +54,7 @@ public class DeferredResultReturnValueHandlerTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.handler = new DeferredResultMethodReturnValueHandler(); this.request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); @@ -190,8 +191,6 @@ public class DeferredResultReturnValueHandlerTests { private CompletableFuture handleCompletableFuture() { return null; } - - } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java index 20af19ec40..22a79a5dc5 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -110,9 +110,9 @@ public class HttpEntityMethodProcessorMockTests { private ServletWebRequest webRequest; - @SuppressWarnings("unchecked") @Before - public void setUp() throws Exception { + @SuppressWarnings("unchecked") + public void setup() throws Exception { dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); @@ -259,8 +259,8 @@ public class HttpEntityMethodProcessorMockTests { verify(stringHttpMessageConverter).write(eq(body), eq(MediaType.TEXT_HTML), isA(HttpOutputMessage.class)); } - @SuppressWarnings("unchecked") @Test + @SuppressWarnings("unchecked") public void shouldHandleReturnValueWithResponseBodyAdvice() throws Exception { servletRequest.addHeader("Accept", "text/*"); servletRequest.setAttribute(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(MediaType.TEXT_HTML)); @@ -310,7 +310,7 @@ public class HttpEntityMethodProcessorMockTests { processor.handleReturnValue(returnValue, returnTypeResponseEntityProduces, mavContainer, webRequest); } - @Test // SPR-9142 + @Test // SPR-9142 public void shouldFailHandlingWhenAcceptHeaderIllegal() throws Exception { ResponseEntity returnValue = new ResponseEntity<>("Body", HttpStatus.ACCEPTED); servletRequest.addHeader("Accept", "01"); @@ -371,7 +371,7 @@ public class HttpEntityMethodProcessorMockTests { assertConditionalResponse(HttpStatus.NOT_MODIFIED, null, etagValue, -1); } - @Test // SPR-14559 + @Test // SPR-14559 public void shouldHandleInvalidIfNoneMatchWithHttp200() throws Exception { String etagValue = "\"deadb33f8badf00d\""; servletRequest.addHeader(HttpHeaders.IF_NONE_MATCH, "unquoted"); @@ -429,7 +429,7 @@ public class HttpEntityMethodProcessorMockTests { assertConditionalResponse(HttpStatus.OK, null, changedEtagValue, oneMinuteAgo); } - @Test // SPR-13496 + @Test // SPR-13496 public void shouldHandleConditionalRequestIfNoneMatchWildcard() throws Exception { String wildcardValue = "*"; String etagValue = "\"some-etag\""; @@ -443,7 +443,7 @@ public class HttpEntityMethodProcessorMockTests { assertConditionalResponse(HttpStatus.OK, "body", etagValue, -1); } - @Test // SPR-13626 + @Test // SPR-13626 public void shouldHandleGetIfNoneMatchWildcard() throws Exception { String wildcardValue = "*"; String etagValue = "\"some-etag\""; @@ -456,7 +456,7 @@ public class HttpEntityMethodProcessorMockTests { assertConditionalResponse(HttpStatus.OK, "body", etagValue, -1); } - @Test // SPR-13626 + @Test // SPR-13626 public void shouldHandleIfNoneMatchIfMatch() throws Exception { String etagValue = "\"some-etag\""; servletRequest.addHeader(HttpHeaders.IF_NONE_MATCH, etagValue); @@ -469,7 +469,7 @@ public class HttpEntityMethodProcessorMockTests { assertConditionalResponse(HttpStatus.NOT_MODIFIED, null, etagValue, -1); } - @Test // SPR-13626 + @Test // SPR-13626 public void shouldHandleIfNoneMatchIfUnmodifiedSince() throws Exception { String etagValue = "\"some-etag\""; servletRequest.addHeader(HttpHeaders.IF_NONE_MATCH, etagValue); @@ -498,7 +498,7 @@ public class HttpEntityMethodProcessorMockTests { assertEquals(200, servletResponse.getStatus()); } - @Test //SPR-14767 + @Test //SPR-14767 public void shouldHandleValidatorHeadersInPutResponses() throws Exception { servletRequest.setMethod("PUT"); String etagValue = "\"some-etag\""; @@ -510,6 +510,7 @@ public class HttpEntityMethodProcessorMockTests { assertConditionalResponse(HttpStatus.OK, "body", etagValue, -1); } + private void initStringMessageConversion(MediaType accepted) { given(stringHttpMessageConverter.canWrite(String.class, null)).willReturn(true); given(stringHttpMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN)); @@ -541,6 +542,7 @@ public class HttpEntityMethodProcessorMockTests { } } + @SuppressWarnings("unused") public ResponseEntity handle1(HttpEntity httpEntity, ResponseEntity entity, int i, RequestEntity requestEntity) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorTests.java index e6f621ed59..6e78e13d3e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -46,10 +46,7 @@ import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.support.ModelAndViewContainer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Test fixture with {@link HttpEntityMethodProcessor} delegating to @@ -78,7 +75,7 @@ public class HttpEntityMethodProcessorTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { Method method = getClass().getDeclaredMethod("handle", HttpEntity.class, HttpEntity.class); paramList = new MethodParameter(method, 0); paramSimpleBean = new MethodParameter(method, 1); @@ -110,9 +107,7 @@ public class HttpEntityMethodProcessorTests { assertEquals("Jad", result.getBody().getName()); } - // SPR-12861 - - @Test + @Test // SPR-12861 public void resolveArgumentWithEmptyBody() throws Exception { this.servletRequest.setContent(new byte[0]); this.servletRequest.setContentType("application/json"); @@ -187,9 +182,7 @@ public class HttpEntityMethodProcessorTests { assertTrue(content.contains("\"type\":\"bar\"")); } - // SPR-13423 - - @Test + @Test // SPR-13423 public void handleReturnValueCharSequence() throws Exception { List>converters = new ArrayList<>(); converters.add(new ByteArrayHttpMessageConverter()); @@ -207,7 +200,6 @@ public class HttpEntityMethodProcessorTests { } - @SuppressWarnings("unused") private void handle(HttpEntity> arg1, HttpEntity arg2) { } @@ -216,6 +208,7 @@ public class HttpEntityMethodProcessorTests { return null; } + @SuppressWarnings("unused") private static abstract class MyParameterizedController { @@ -223,10 +216,12 @@ public class HttpEntityMethodProcessorTests { } } + @SuppressWarnings("unused") private static class MySimpleParameterizedController extends MyParameterizedController { } + private interface Identifiable extends Serializable { Long getId(); @@ -275,6 +270,7 @@ public class HttpEntityMethodProcessorTests { } } + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") private static class ParentClass { @@ -296,6 +292,7 @@ public class HttpEntityMethodProcessorTests { } } + @JsonTypeName("foo") private static class Foo extends ParentClass { @@ -307,6 +304,7 @@ public class HttpEntityMethodProcessorTests { } } + @JsonTypeName("bar") private static class Bar extends ParentClass { @@ -318,6 +316,7 @@ public class HttpEntityMethodProcessorTests { } } + private static class JacksonController { @RequestMapping diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java index 57dd208b2c..cd1f69bb0d 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -47,22 +47,28 @@ public class MatrixVariablesMapMethodArgumentResolverTests { private MatrixVariableMapMethodArgumentResolver resolver; - private MethodParameter paramString; - private MethodParameter paramMap; - private MethodParameter paramMultivalueMap; - private MethodParameter paramMapForPathVar; - private MethodParameter paramMapWithName; - private ModelAndViewContainer mavContainer; private ServletWebRequest webRequest; private MockHttpServletRequest request; + private MethodParameter paramString; + private MethodParameter paramMap; + private MethodParameter paramMultivalueMap; + private MethodParameter paramMapForPathVar; + private MethodParameter paramMapWithName; + @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.resolver = new MatrixVariableMapMethodArgumentResolver(); + this.mavContainer = new ModelAndViewContainer(); + this.request = new MockHttpServletRequest(); + this.webRequest = new ServletWebRequest(request, new MockHttpServletResponse()); + + Map> params = new LinkedHashMap<>(); + this.request.setAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, params); Method method = getClass().getMethod("handle", String.class, Map.class, MultiValueMap.class, MultiValueMap.class, Map.class); @@ -72,15 +78,9 @@ public class MatrixVariablesMapMethodArgumentResolverTests { this.paramMultivalueMap = new SynthesizingMethodParameter(method, 2); this.paramMapForPathVar = new SynthesizingMethodParameter(method, 3); this.paramMapWithName = new SynthesizingMethodParameter(method, 4); - - this.mavContainer = new ModelAndViewContainer(); - this.request = new MockHttpServletRequest(); - this.webRequest = new ServletWebRequest(request, new MockHttpServletResponse()); - - Map> params = new LinkedHashMap<>(); - this.request.setAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, params); } + @Test public void supportsParameter() { assertFalse(resolver.supportsParameter(paramString)); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java index 9f57f9a42d..92db11b0e0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java @@ -48,36 +48,35 @@ public class MatrixVariablesMethodArgumentResolverTests { private MatrixVariableMethodArgumentResolver resolver; - private MethodParameter paramString; - private MethodParameter paramColors; - private MethodParameter paramYear; - private ModelAndViewContainer mavContainer; private ServletWebRequest webRequest; private MockHttpServletRequest request; + private MethodParameter paramString; + private MethodParameter paramColors; + private MethodParameter paramYear; + @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.resolver = new MatrixVariableMethodArgumentResolver(); - - Method method = getClass().getMethod("handle", String.class, List.class, int.class); - this.paramString = new MethodParameter(method, 0); - this.paramColors = new MethodParameter(method, 1); - this.paramYear = new MethodParameter(method, 2); - - this.paramColors.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer()); - this.mavContainer = new ModelAndViewContainer(); this.request = new MockHttpServletRequest(); this.webRequest = new ServletWebRequest(request, new MockHttpServletResponse()); Map> params = new LinkedHashMap<>(); this.request.setAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, params); + + Method method = getClass().getMethod("handle", String.class, List.class, int.class); + this.paramString = new MethodParameter(method, 0); + this.paramColors = new MethodParameter(method, 1); + this.paramColors.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer()); + this.paramYear = new MethodParameter(method, 2); } + @Test public void supportsParameter() { assertFalse(resolver.supportsParameter(paramString)); @@ -87,7 +86,6 @@ public class MatrixVariablesMethodArgumentResolverTests { @Test public void resolveArgument() throws Exception { - MultiValueMap params = getMatrixVariables("cars"); params.add("colors", "red"); params.add("colors", "green"); @@ -99,7 +97,6 @@ public class MatrixVariablesMethodArgumentResolverTests { @Test public void resolveArgumentPathVariable() throws Exception { - getMatrixVariables("cars").add("year", "2006"); getMatrixVariables("bikes").add("year", "2005"); @@ -113,7 +110,6 @@ public class MatrixVariablesMethodArgumentResolverTests { @Test(expected = ServletRequestBindingException.class) public void resolveArgumentMultipleMatches() throws Exception { - getMatrixVariables("var1").add("colors", "red"); getMatrixVariables("var2").add("colors", "green"); @@ -127,7 +123,6 @@ public class MatrixVariablesMethodArgumentResolverTests { @Test public void resolveArgumentNoMatch() throws Exception { - MultiValueMap params = getMatrixVariables("cars"); params.add("anotherYear", "2012"); @@ -137,7 +132,6 @@ public class MatrixVariablesMethodArgumentResolverTests { @SuppressWarnings("unchecked") private MultiValueMap getMatrixVariables(String pathVarName) { - Map> matrixVariables = (Map>) this.request.getAttribute( HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java index fa243ccda4..b7cf954c98 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -49,7 +49,7 @@ public class ModelAndViewMethodReturnValueHandlerTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.handler = new ModelAndViewMethodReturnValueHandler(); this.mavContainer = new ModelAndViewContainer(); this.webRequest = new ServletWebRequest(new MockHttpServletRequest()); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandlerTests.java index d05252ef5a..c7873d0eac 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -52,7 +52,7 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests { @Before - public void setUp() { + public void setup() { mavResolvers = new ArrayList<>(); handler = new ModelAndViewResolverMethodReturnValueHandler(mavResolvers); mavContainer = new ModelAndViewContainer(); @@ -118,7 +118,7 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests { private static class TestModelAndViewResolver implements ModelAndViewResolver { - private Class returnValueType; + private final Class returnValueType; public TestModelAndViewResolver(Class returnValueType) { this.returnValueType = returnValueType; diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java index daa1108aed..2536dce8f8 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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,10 +16,6 @@ package org.springframework.web.servlet.mvc.method.annotation; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.*; - import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -58,6 +54,10 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; +import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.*; + /** * Unit tests for {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}. * @@ -73,12 +73,12 @@ public class MvcUriComponentsBuilderTests { @Before - public void setUp() { + public void setup() { RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request)); } @After - public void tearDown() { + public void reset() { RequestContextHolder.resetRequestAttributes(); } @@ -372,15 +372,16 @@ public class MvcUriComponentsBuilderTests { } } + @RequestMapping("/people") interface PersonController { - } - private class PersonControllerImpl implements PersonController { + private class PersonControllerImpl implements PersonController { } + @RequestMapping("/people/{id}/addresses") private static class PersonsAddressesController { @@ -390,11 +391,12 @@ public class MvcUriComponentsBuilderTests { } } - @RequestMapping({ "/persons", "/people" }) - private class InvalidController { + @RequestMapping({"/persons", "/people"}) + private class InvalidController { } + private class UnmappedController { @RequestMapping @@ -402,6 +404,7 @@ public class MvcUriComponentsBuilderTests { } } + @RequestMapping("/something") static class ControllerWithMethods { @@ -439,11 +442,13 @@ public class MvcUriComponentsBuilderTests { } } - @RequestMapping("/extended") @SuppressWarnings("WeakerAccess") - static class ExtendedController extends ControllerWithMethods { + @RequestMapping("/extended") + @SuppressWarnings("WeakerAccess") + static class ExtendedController extends ControllerWithMethods { } + @RequestMapping("/user/{userId}/contacts") private static class UserContactController { @@ -453,11 +458,13 @@ public class MvcUriComponentsBuilderTests { } } + static abstract class AbstractCrudController { abstract T get(ID id); } + private static class PersonCrudController extends AbstractCrudController { @RequestMapping(path = "/{id}", method = RequestMethod.GET) @@ -466,6 +473,7 @@ public class MvcUriComponentsBuilderTests { } } + @Controller private static class MetaAnnotationController { @@ -473,12 +481,12 @@ public class MvcUriComponentsBuilderTests { public void handle() { } - @PostJson(path="/input") + @PostJson(path = "/input") public void handleInput() { } - } + @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @@ -486,9 +494,11 @@ public class MvcUriComponentsBuilderTests { @Retention(RetentionPolicy.RUNTIME) @Documented private @interface PostJson { + String[] path() default {}; } + @EnableWebMvc static class WebConfig extends WebMvcConfigurerAdapter { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolverTests.java index 78c151928b..acf9b42e31 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,32 +43,31 @@ public class PathVariableMapMethodArgumentResolverTests { private PathVariableMapMethodArgumentResolver resolver; - private MethodParameter paramMap; - - private MethodParameter paramNamedMap; - - private MethodParameter paramMapNoAnnot; - private ModelAndViewContainer mavContainer; private ServletWebRequest webRequest; private MockHttpServletRequest request; + private MethodParameter paramMap; + private MethodParameter paramNamedMap; + private MethodParameter paramMapNoAnnot; + + @Before - public void setUp() throws Exception { + public void setup() throws Exception { resolver = new PathVariableMapMethodArgumentResolver(); + mavContainer = new ModelAndViewContainer(); + request = new MockHttpServletRequest(); + webRequest = new ServletWebRequest(request, new MockHttpServletResponse()); Method method = getClass().getMethod("handle", Map.class, Map.class, Map.class); paramMap = new MethodParameter(method, 0); paramNamedMap = new MethodParameter(method, 1); paramMapNoAnnot = new MethodParameter(method, 2); - - mavContainer = new ModelAndViewContainer(); - request = new MockHttpServletRequest(); - webRequest = new ServletWebRequest(request, new MockHttpServletResponse()); } + @Test public void supportsParameter() { assertTrue(resolver.supportsParameter(paramMap)); @@ -103,4 +102,4 @@ public class PathVariableMapMethodArgumentResolverTests { Map mapWithoutAnnotat) { } -} \ No newline at end of file +} diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolverTests.java index 4cc08a760f..4fc63187c1 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -52,34 +52,30 @@ public class PathVariableMethodArgumentResolverTests { private PathVariableMethodArgumentResolver resolver; - private MethodParameter paramNamedString; - - private MethodParameter paramString; - - private MethodParameter paramNotRequired; - - private MethodParameter paramOptional; - private ModelAndViewContainer mavContainer; private ServletWebRequest webRequest; private MockHttpServletRequest request; + private MethodParameter paramNamedString; + private MethodParameter paramString; + private MethodParameter paramNotRequired; + private MethodParameter paramOptional; + @Before - public void setUp() throws Exception { + public void setup() throws Exception { resolver = new PathVariableMethodArgumentResolver(); + mavContainer = new ModelAndViewContainer(); + request = new MockHttpServletRequest(); + webRequest = new ServletWebRequest(request, new MockHttpServletResponse()); Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class[]) null); paramNamedString = new SynthesizingMethodParameter(method, 0); paramString = new SynthesizingMethodParameter(method, 1); paramNotRequired = new SynthesizingMethodParameter(method, 2); paramOptional = new SynthesizingMethodParameter(method, 3); - - mavContainer = new ModelAndViewContainer(); - request = new MockHttpServletRequest(); - webRequest = new ServletWebRequest(request, new MockHttpServletResponse()); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java index 267a43fee8..5813a6d561 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -123,7 +123,7 @@ public class RequestPartIntegrationTests { } @Before - public void setUp() { + public void setup() { ByteArrayHttpMessageConverter emptyBodyConverter = new ByteArrayHttpMessageConverter(); emptyBodyConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON)); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolverTests.java index b054c80fe3..a2a70b9a90 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -65,13 +65,18 @@ import static org.mockito.BDDMockito.*; */ public class RequestPartMethodArgumentResolverTests { - private RequestPartMethodArgumentResolver resolver; - private HttpMessageConverter messageConverter; + private RequestPartMethodArgumentResolver resolver; + private MultipartFile multipartFile1; + private MultipartFile multipartFile2; + private MockMultipartHttpServletRequest multipartRequest; + + private NativeWebRequest webRequest; + private MethodParameter paramRequestPart; private MethodParameter paramNamedRequestPart; private MethodParameter paramValidRequestPart; @@ -90,16 +95,26 @@ public class RequestPartMethodArgumentResolverTests { private MethodParameter optionalPartList; private MethodParameter optionalRequestPart; - private NativeWebRequest webRequest; - private MockMultipartHttpServletRequest multipartRequest; + @Before + @SuppressWarnings("unchecked") + public void setup() throws Exception { + messageConverter = mock(HttpMessageConverter.class); + given(messageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN)); + resolver = new RequestPartMethodArgumentResolver(Collections.>singletonList(messageConverter)); + reset(messageConverter); - @SuppressWarnings("unchecked") - @Before - public void setUp() throws Exception { - Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class[]) null); + byte[] content = "doesn't matter as long as not empty".getBytes(StandardCharsets.UTF_8); + multipartFile1 = new MockMultipartFile("requestPart", "", "text/plain", content); + multipartFile2 = new MockMultipartFile("requestPart", "", "text/plain", content); + multipartRequest = new MockMultipartHttpServletRequest(); + multipartRequest.addFile(multipartFile1); + multipartRequest.addFile(multipartFile2); + multipartRequest.addFile(new MockMultipartFile("otherPart", "", "text/plain", content)); + webRequest = new ServletWebRequest(multipartRequest, new MockHttpServletResponse()); + Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class[]) null); paramRequestPart = new SynthesizingMethodParameter(method, 0); paramRequestPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer()); paramNamedRequestPart = new SynthesizingMethodParameter(method, 1); @@ -124,22 +139,6 @@ public class RequestPartMethodArgumentResolverTests { optionalPartList = new SynthesizingMethodParameter(method, 15); optionalPartList.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer()); optionalRequestPart = new SynthesizingMethodParameter(method, 16); - - messageConverter = mock(HttpMessageConverter.class); - given(messageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN)); - - resolver = new RequestPartMethodArgumentResolver(Collections.>singletonList(messageConverter)); - reset(messageConverter); - - byte[] content = "doesn't matter as long as not empty".getBytes(StandardCharsets.UTF_8); - - multipartFile1 = new MockMultipartFile("requestPart", "", "text/plain", content); - multipartFile2 = new MockMultipartFile("requestPart", "", "text/plain", content); - multipartRequest = new MockMultipartHttpServletRequest(); - multipartRequest.addFile(multipartFile1); - multipartRequest.addFile(multipartFile2); - multipartRequest.addFile(new MockMultipartFile("otherPart", "", "text/plain", content)); - webRequest = new ServletWebRequest(multipartRequest, new MockHttpServletResponse()); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorMockTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorMockTests.java index 4529274a51..3a5957c431 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorMockTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorMockTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 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. @@ -66,12 +66,20 @@ import static org.mockito.BDDMockito.*; */ public class RequestResponseBodyMethodProcessorMockTests { - private RequestResponseBodyMethodProcessor processor; - private HttpMessageConverter stringMessageConverter; private HttpMessageConverter resourceMessageConverter; + private RequestResponseBodyMethodProcessor processor; + + private ModelAndViewContainer mavContainer; + + private MockHttpServletRequest servletRequest; + + private MockHttpServletResponse servletResponse; + + private NativeWebRequest webRequest; + private MethodParameter paramRequestBodyString; private MethodParameter paramInt; private MethodParameter paramValidBean; @@ -82,18 +90,10 @@ public class RequestResponseBodyMethodProcessorMockTests { private MethodParameter returnTypeStringProduces; private MethodParameter returnTypeResource; - private ModelAndViewContainer mavContainer; - private NativeWebRequest webRequest; - - private MockHttpServletRequest servletRequest; - - private MockHttpServletResponse servletResponse; - - - @SuppressWarnings("unchecked") @Before - public void setUp() throws Exception { + @SuppressWarnings("unchecked") + public void setup() throws Exception { stringMessageConverter = mock(HttpMessageConverter.class); given(stringMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN)); @@ -102,6 +102,12 @@ public class RequestResponseBodyMethodProcessorMockTests { processor = new RequestResponseBodyMethodProcessor(Arrays.asList(stringMessageConverter, resourceMessageConverter)); + mavContainer = new ModelAndViewContainer(); + servletRequest = new MockHttpServletRequest(); + servletRequest.setMethod("POST"); + servletResponse = new MockHttpServletResponse(); + webRequest = new ServletWebRequest(servletRequest, servletResponse); + Method methodHandle1 = getClass().getMethod("handle1", String.class, Integer.TYPE); paramRequestBodyString = new MethodParameter(methodHandle1, 0); paramInt = new MethodParameter(methodHandle1, 1); @@ -112,13 +118,6 @@ public class RequestResponseBodyMethodProcessorMockTests { returnTypeInt = new MethodParameter(getClass().getMethod("handle5"), -1); returnTypeStringProduces = new MethodParameter(getClass().getMethod("handle6"), -1); returnTypeResource = new MethodParameter(getClass().getMethod("handle7"), -1); - - mavContainer = new ModelAndViewContainer(); - - servletRequest = new MockHttpServletRequest(); - servletRequest.setMethod("POST"); - servletResponse = new MockHttpServletResponse(); - webRequest = new ServletWebRequest(servletRequest, servletResponse); } @Test diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java index 4858f18b44..363a496d5b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -82,45 +82,42 @@ import static org.junit.Assert.*; @SuppressWarnings("unused") public class RequestResponseBodyMethodProcessorTests { - private MethodParameter paramGenericList; - private MethodParameter paramSimpleBean; - private MethodParameter paramMultiValueMap; - private MethodParameter paramString; - private MethodParameter returnTypeString; - private ModelAndViewContainer container; - private NativeWebRequest request; - private MockHttpServletRequest servletRequest; private MockHttpServletResponse servletResponse; - private ValidatingBinderFactory factory; - + private NativeWebRequest request; - @Before - public void setUp() throws Exception { + private ValidatingBinderFactory factory; - Method method = getClass().getDeclaredMethod("handle", List.class, SimpleBean.class, - MultiValueMap.class, String.class); + private MethodParameter paramGenericList; + private MethodParameter paramSimpleBean; + private MethodParameter paramMultiValueMap; + private MethodParameter paramString; + private MethodParameter returnTypeString; - paramGenericList = new MethodParameter(method, 0); - paramSimpleBean = new MethodParameter(method, 1); - paramMultiValueMap = new MethodParameter(method, 2); - paramString = new MethodParameter(method, 3); - returnTypeString = new MethodParameter(method, -1); + @Before + public void setup() throws Exception { container = new ModelAndViewContainer(); - servletRequest = new MockHttpServletRequest(); servletRequest.setMethod("POST"); servletResponse = new MockHttpServletResponse(); request = new ServletWebRequest(servletRequest, servletResponse); - this.factory = new ValidatingBinderFactory(); + + Method method = getClass().getDeclaredMethod("handle", + List.class, SimpleBean.class, MultiValueMap.class, String.class); + paramGenericList = new MethodParameter(method, 0); + paramSimpleBean = new MethodParameter(method, 1); + paramMultiValueMap = new MethodParameter(method, 2); + paramString = new MethodParameter(method, 3); + returnTypeString = new MethodParameter(method, -1); } + @Test public void resolveArgumentParameterizedType() throws Exception { String content = "[{\"name\" : \"Jad\"}, {\"name\" : \"Robert\"}]"; diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandlerTests.java index bf36781537..c572b33e73 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -15,10 +15,6 @@ */ package org.springframework.web.servlet.mvc.method.annotation; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import static org.springframework.web.servlet.mvc.method.annotation.SseEmitter.*; - import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collections; @@ -43,9 +39,12 @@ import org.springframework.web.context.request.async.StandardServletAsyncWebRequ import org.springframework.web.context.request.async.WebAsyncUtils; import org.springframework.web.method.support.ModelAndViewContainer; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; /** * Unit tests for ResponseBodyEmitterReturnValueHandler. + * * @author Rossen Stoyanchev */ public class ResponseBodyEmitterReturnValueHandlerTests { @@ -60,8 +59,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests { @Before - public void setUp() throws Exception { - + public void setup() throws Exception { List> converters = Arrays.asList( new StringHttpMessageConverter(), new MappingJackson2HttpMessageConverter()); @@ -75,6 +73,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests { this.request.setAsyncSupported(true); } + @Test public void supportsReturnType() throws Exception { assertTrue(this.handler.supportsReturnType(returnType("handle"))); @@ -158,7 +157,8 @@ public class ResponseBodyEmitterReturnValueHandlerTests { bean2.setId(2L); bean2.setName("John"); - emitter.send(event().comment("a test").name("update").id("1").reconnectTime(5000L).data(bean1).data(bean2)); + emitter.send(SseEmitter.event(). + comment("a test").name("update").id("1").reconnectTime(5000L).data(bean1).data(bean2)); assertEquals(":a test\n" + "event:update\n" + @@ -193,6 +193,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests { assertEquals(Collections.singletonList("bar"), this.response.getHeaders("foo")); } + private void handleReturnValue(Object returnValue, MethodParameter returnType) throws Exception { ModelAndViewContainer mavContainer = new ModelAndViewContainer(); this.handler.handleReturnValue(returnValue, returnType, mavContainer, this.webRequest); @@ -204,7 +205,6 @@ public class ResponseBodyEmitterReturnValueHandlerTests { } - @SuppressWarnings("unused") private static class TestController { @@ -235,9 +235,9 @@ public class ResponseBodyEmitterReturnValueHandlerTests { private ResponseEntity handleRawResponseEntity() { return null; } - } + private static class SimpleBean { private Long id; diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java index 5796f1248f..48b6fe28f4 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 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. @@ -41,25 +41,23 @@ public class ServletCookieValueMethodArgumentResolverTests { private ServletCookieValueMethodArgumentResolver resolver; - private MethodParameter cookieParameter; - - private MethodParameter cookieStringParameter; + private MockHttpServletRequest request; private ServletWebRequest webRequest; - private MockHttpServletRequest request; + private MethodParameter cookieParameter; + private MethodParameter cookieStringParameter; @Before - public void setUp() throws Exception { + public void setup() throws Exception { resolver = new ServletCookieValueMethodArgumentResolver(null); + request = new MockHttpServletRequest(); + webRequest = new ServletWebRequest(request, new MockHttpServletResponse()); Method method = getClass().getMethod("params", Cookie.class, String.class); cookieParameter = new SynthesizingMethodParameter(method, 0); cookieStringParameter = new SynthesizingMethodParameter(method, 1); - - request = new MockHttpServletRequest(); - webRequest = new ServletWebRequest(request, new MockHttpServletResponse()); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessorTests.java index 253a9b3d7a..75de7e5077 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -48,40 +48,36 @@ public class ServletModelAttributeMethodProcessorTests { private ServletModelAttributeMethodProcessor processor; - private MethodParameter testBeanModelAttr; - - private MethodParameter testBeanWithoutStringConstructorModelAttr; - - private MethodParameter testBeanWithOptionalModelAttr; + private WebDataBinderFactory binderFactory; private ModelAndViewContainer mavContainer; - private NativeWebRequest webRequest; - private MockHttpServletRequest request; - private WebDataBinderFactory binderFactory; - + private NativeWebRequest webRequest; - @Before - public void setUp() throws Exception { - this.processor = new ServletModelAttributeMethodProcessor(false); + private MethodParameter testBeanModelAttr; + private MethodParameter testBeanWithoutStringConstructorModelAttr; + private MethodParameter testBeanWithOptionalModelAttr; - Method method = getClass().getDeclaredMethod("modelAttribute", - TestBean.class, TestBeanWithoutStringConstructor.class, Optional.class); - this.testBeanModelAttr = new MethodParameter(method, 0); - this.testBeanWithoutStringConstructorModelAttr = new MethodParameter(method, 1); - this.testBeanWithOptionalModelAttr = new MethodParameter(method, 2); + @Before + public void setup() throws Exception { + processor = new ServletModelAttributeMethodProcessor(false); ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultConversionService()); + binderFactory = new ServletRequestDataBinderFactory(null, initializer); - this.binderFactory = new ServletRequestDataBinderFactory(null, initializer); - this.mavContainer = new ModelAndViewContainer(); + mavContainer = new ModelAndViewContainer(); + request = new MockHttpServletRequest(); + webRequest = new ServletWebRequest(request); - this.request = new MockHttpServletRequest(); - this.webRequest = new ServletWebRequest(request); + Method method = getClass().getDeclaredMethod("modelAttribute", + TestBean.class, TestBeanWithoutStringConstructor.class, Optional.class); + testBeanModelAttr = new MethodParameter(method, 0); + testBeanWithoutStringConstructorModelAttr = new MethodParameter(method, 1); + testBeanWithOptionalModelAttr = new MethodParameter(method, 2); } @@ -89,13 +85,11 @@ public class ServletModelAttributeMethodProcessorTests { public void createAttributeUriTemplateVar() throws Exception { Map uriTemplateVars = new HashMap<>(); uriTemplateVars.put("testBean1", "Patty"); - this.request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); + request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); // Type conversion from "Patty" to TestBean via TestBean(String) constructor - - TestBean testBean = - (TestBean) this.processor.resolveArgument( - this.testBeanModelAttr, this.mavContainer, this.webRequest, this.binderFactory); + TestBean testBean = (TestBean) processor.resolveArgument( + testBeanModelAttr, mavContainer, webRequest, binderFactory); assertEquals("Patty", testBean.getName()); } @@ -106,9 +100,8 @@ public class ServletModelAttributeMethodProcessorTests { uriTemplateVars.put("testBean2", "Patty"); request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); - TestBeanWithoutStringConstructor testBean = - (TestBeanWithoutStringConstructor) this.processor.resolveArgument( - this.testBeanWithoutStringConstructorModelAttr, this.mavContainer, this.webRequest, this.binderFactory); + TestBeanWithoutStringConstructor testBean = (TestBeanWithoutStringConstructor) processor.resolveArgument( + testBeanWithoutStringConstructorModelAttr, mavContainer, webRequest, binderFactory); assertNotNull(testBean); } @@ -117,89 +110,81 @@ public class ServletModelAttributeMethodProcessorTests { public void createAttributeUriTemplateVarWithOptional() throws Exception { Map uriTemplateVars = new HashMap<>(); uriTemplateVars.put("testBean3", "Patty"); - this.request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); + request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); // Type conversion from "Patty" to TestBean via TestBean(String) constructor - - Optional testBean = - (Optional) this.processor.resolveArgument( - this.testBeanWithOptionalModelAttr, this.mavContainer, this.webRequest, this.binderFactory); + Optional testBean = (Optional) processor.resolveArgument( + testBeanWithOptionalModelAttr, mavContainer, webRequest, binderFactory); assertEquals("Patty", testBean.get().getName()); } @Test public void createAttributeRequestParameter() throws Exception { - this.request.addParameter("testBean1", "Patty"); + request.addParameter("testBean1", "Patty"); // Type conversion from "Patty" to TestBean via TestBean(String) constructor - - TestBean testBean = - (TestBean) this.processor.resolveArgument( - this.testBeanModelAttr, this.mavContainer, this.webRequest, this.binderFactory); + TestBean testBean = (TestBean) processor.resolveArgument( + testBeanModelAttr, mavContainer, webRequest, binderFactory); assertEquals("Patty", testBean.getName()); } @Test public void createAttributeRequestParameterCannotConvert() throws Exception { - this.request.addParameter("testBean2", "Patty"); + request.addParameter("testBean2", "Patty"); - TestBeanWithoutStringConstructor testBean = - (TestBeanWithoutStringConstructor) this.processor.resolveArgument( - this.testBeanWithoutStringConstructorModelAttr, this.mavContainer, this.webRequest, this.binderFactory); + TestBeanWithoutStringConstructor testBean = (TestBeanWithoutStringConstructor) processor.resolveArgument( + testBeanWithoutStringConstructorModelAttr, mavContainer, webRequest, binderFactory); assertNotNull(testBean); } @Test public void createAttributeRequestParameterWithOptional() throws Exception { - this.request.addParameter("testBean3", "Patty"); + request.addParameter("testBean3", "Patty"); - Optional testBean = - (Optional) this.processor.resolveArgument( - this.testBeanWithOptionalModelAttr, this.mavContainer, this.webRequest, this.binderFactory); + Optional testBean = (Optional) processor.resolveArgument( + testBeanWithOptionalModelAttr, mavContainer, webRequest, binderFactory); assertEquals("Patty", testBean.get().getName()); } @Test public void attributesAsNullValues() throws Exception { - this.request.addParameter("name", "Patty"); + request.addParameter("name", "Patty"); - this.mavContainer.getModel().put("testBean1", null); - this.mavContainer.getModel().put("testBean2", null); - this.mavContainer.getModel().put("testBean3", null); + mavContainer.getModel().put("testBean1", null); + mavContainer.getModel().put("testBean2", null); + mavContainer.getModel().put("testBean3", null); - assertNull(this.processor.resolveArgument( - this.testBeanModelAttr, this.mavContainer, this.webRequest, this.binderFactory)); + assertNull(processor.resolveArgument( + testBeanModelAttr, mavContainer, webRequest, binderFactory)); - assertNull(this.processor.resolveArgument( - this.testBeanWithoutStringConstructorModelAttr, this.mavContainer, this.webRequest, this.binderFactory)); + assertNull(processor.resolveArgument( + testBeanWithoutStringConstructorModelAttr, mavContainer, webRequest, binderFactory)); - Optional testBean = - (Optional) this.processor.resolveArgument( - this.testBeanWithOptionalModelAttr, this.mavContainer, this.webRequest, this.binderFactory); + Optional testBean = (Optional) processor.resolveArgument( + testBeanWithOptionalModelAttr, mavContainer, webRequest, binderFactory); assertFalse(testBean.isPresent()); } @Test public void attributesAsOptionalEmpty() throws Exception { - this.request.addParameter("name", "Patty"); + request.addParameter("name", "Patty"); - this.mavContainer.getModel().put("testBean1", Optional.empty()); - this.mavContainer.getModel().put("testBean2", Optional.empty()); - this.mavContainer.getModel().put("testBean3", Optional.empty()); + mavContainer.getModel().put("testBean1", Optional.empty()); + mavContainer.getModel().put("testBean2", Optional.empty()); + mavContainer.getModel().put("testBean3", Optional.empty()); - assertNull(this.processor.resolveArgument( - this.testBeanModelAttr, this.mavContainer, this.webRequest, this.binderFactory)); + assertNull(processor.resolveArgument( + testBeanModelAttr, mavContainer, webRequest, binderFactory)); - assertNull(this.processor.resolveArgument( - this.testBeanWithoutStringConstructorModelAttr, this.mavContainer, this.webRequest, this.binderFactory)); + assertNull(processor.resolveArgument( + testBeanWithoutStringConstructorModelAttr, mavContainer, webRequest, binderFactory)); - Optional testBean = - (Optional) this.processor.resolveArgument( - this.testBeanWithOptionalModelAttr, this.mavContainer, this.webRequest, this.binderFactory); + Optional testBean =(Optional) processor.resolveArgument( + testBeanWithOptionalModelAttr, mavContainer, webRequest, binderFactory); assertFalse(testBean.isPresent()); } @@ -219,7 +204,6 @@ public class ServletModelAttributeMethodProcessorTests { public TestBeanWithoutStringConstructor(int i) { } - } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolverTests.java index 5fa371217f..0304387b2a 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolverTests.java @@ -41,22 +41,23 @@ public class ServletResponseMethodArgumentResolverTests { private ServletResponseMethodArgumentResolver resolver; - private Method method; - private ModelAndViewContainer mavContainer; + private MockHttpServletResponse servletResponse; + private ServletWebRequest webRequest; - private MockHttpServletResponse servletResponse; + private Method method; @Before - public void setUp() throws Exception { + public void setup() throws Exception { resolver = new ServletResponseMethodArgumentResolver(); - method = getClass().getMethod("supportedParams", ServletResponse.class, OutputStream.class, Writer.class); - servletResponse = new MockHttpServletResponse(); mavContainer = new ModelAndViewContainer(); + servletResponse = new MockHttpServletResponse(); webRequest = new ServletWebRequest(new MockHttpServletRequest(), servletResponse); + + method = getClass().getMethod("supportedParams", ServletResponse.class, OutputStream.class, Writer.class); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandlerTests.java index 80049799a1..bc775e5df7 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandlerTests.java @@ -62,7 +62,7 @@ public class StreamingResponseBodyReturnValueHandlerTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.handler = new StreamingResponseBodyReturnValueHandler(); this.mavContainer = new ModelAndViewContainer(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolverTests.java index 79d580d32a..0e6200fcc2 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. @@ -39,27 +39,28 @@ public class UriComponentsBuilderMethodArgumentResolverTests { private UriComponentsBuilderMethodArgumentResolver resolver; - private MethodParameter builderParam; + private ServletWebRequest webRequest; - private MethodParameter servletBuilderParam; + private MockHttpServletRequest servletRequest; + private MethodParameter builderParam; + private MethodParameter servletBuilderParam; private MethodParameter intParam; - private ServletWebRequest webRequest; - - private MockHttpServletRequest servletRequest; @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.resolver = new UriComponentsBuilderMethodArgumentResolver(); + this.servletRequest = new MockHttpServletRequest(); + this.webRequest = new ServletWebRequest(this.servletRequest); + Method method = this.getClass().getDeclaredMethod("handle", UriComponentsBuilder.class, ServletUriComponentsBuilder.class, int.class); this.builderParam = new MethodParameter(method, 0); this.servletBuilderParam = new MethodParameter(method, 1); this.intParam = new MethodParameter(method, 2); - this.servletRequest = new MockHttpServletRequest(); - this.webRequest = new ServletWebRequest(this.servletRequest); } + @Test public void supportsParameter() throws Exception { assertTrue(this.resolver.supportsParameter(this.builderParam)); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandlerTests.java index 293f9c6449..9642d2202f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. @@ -46,13 +46,15 @@ public class ViewMethodReturnValueHandlerTests { private ServletWebRequest webRequest; + @Before - public void setUp() { + public void setup() { this.handler = new ViewMethodReturnValueHandler(); this.mavContainer = new ModelAndViewContainer(); this.webRequest = new ServletWebRequest(new MockHttpServletRequest()); } + @Test public void supportsReturnType() throws Exception { assertTrue(this.handler.supportsReturnType(createReturnValueParam("view"))); @@ -83,6 +85,7 @@ public class ViewMethodReturnValueHandlerTests { return new MethodParameter(method, -1); } + View view() { return null; } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandlerTests.java index fba25796cc..e25b902813 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 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. @@ -45,13 +45,15 @@ public class ViewNameMethodReturnValueHandlerTests { @Before - public void setUp() throws NoSuchMethodException { + public void setup() throws NoSuchMethodException { this.handler = new ViewNameMethodReturnValueHandler(); this.mavContainer = new ModelAndViewContainer(); this.webRequest = new ServletWebRequest(new MockHttpServletRequest()); + this.param = new MethodParameter(getClass().getDeclaredMethod("viewName"), -1); } + @Test public void supportsReturnType() throws Exception { assertTrue(this.handler.supportsReturnType(this.param)); @@ -98,4 +100,4 @@ public class ViewNameMethodReturnValueHandlerTests { return null; } -} \ No newline at end of file +} diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java index c2ab52fd88..2eda26c11c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -52,21 +52,19 @@ import static org.junit.Assert.*; */ public class DefaultHandlerExceptionResolverTests { - private DefaultHandlerExceptionResolver exceptionResolver; + private final DefaultHandlerExceptionResolver exceptionResolver = new DefaultHandlerExceptionResolver(); - private MockHttpServletRequest request; + private final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); + + private final MockHttpServletResponse response = new MockHttpServletResponse(); - private MockHttpServletResponse response; @Before - public void setUp() { - exceptionResolver = new DefaultHandlerExceptionResolver(); + public void setup() { exceptionResolver.setWarnLogCategory(exceptionResolver.getClass().getName()); - request = new MockHttpServletRequest(); - response = new MockHttpServletResponse(); - request.setMethod("GET"); } + @Test public void handleHttpRequestMethodNotSupported() { HttpRequestMethodNotSupportedException ex = @@ -207,7 +205,7 @@ public class DefaultHandlerExceptionResolverTests { assertSame(ex, request.getAttribute("javax.servlet.error.exception")); } - @Test // SPR-14669 + @Test // SPR-14669 public void handleAsyncRequestTimeoutException() throws Exception { Exception ex = new AsyncRequestTimeoutException(); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/ParameterizableViewControllerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/ParameterizableViewControllerTests.java index 2192fa236f..4cfe84d885 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/ParameterizableViewControllerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/ParameterizableViewControllerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 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,7 +16,6 @@ package org.springframework.web.servlet.mvc.support; -import org.junit.Before; import org.junit.Test; import org.springframework.http.HttpStatus; @@ -38,19 +37,11 @@ import static org.junit.Assert.*; */ public class ParameterizableViewControllerTests { - private ParameterizableViewController controller; + private final ParameterizableViewController controller = new ParameterizableViewController(); - private MockHttpServletRequest request; + private final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); - private MockHttpServletResponse response; - - - @Before - public void setUp() throws Exception { - this.controller = new ParameterizableViewController(); - this.request = new MockHttpServletRequest("GET", "/"); - this.response = new MockHttpServletResponse(); - } + private final MockHttpServletResponse response = new MockHttpServletResponse(); @Test -- GitLab