Browse Source

Clean up warnings and dead code in spring-webflux module

pull/999/merge
Sam Brannen 8 years ago
parent
commit
2575c26020
  1. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java
  2. 3
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/TomcatWebSocketSession.java
  3. 13
      spring-webflux/src/test/java/org/springframework/web/reactive/accept/HeaderContentTypeResolverTests.java
  4. 4
      spring-webflux/src/test/java/org/springframework/web/reactive/config/DelegatingWebFluxConfigurationTests.java
  5. 4
      spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java
  6. 2
      spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java
  7. 6
      spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java
  8. 22
      spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java
  9. 17
      spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilderTests.java
  10. 17
      spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java
  11. 43
      spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/RouterFunctionMappingTests.java
  12. 7
      spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java
  13. 4
      spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceUrlProviderTests.java
  14. 3
      spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/ProducesRequestConditionTests.java
  15. 3
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolverTests.java
  16. 1
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java
  17. 4
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolverTests.java
  18. 1
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java
  19. 7
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java
  20. 3
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolverTests.java
  21. 4
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java
  22. 3
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolverTests.java
  23. 4
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java
  24. 3
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SessionAttributeMethodArgumentResolverTests.java
  25. 68
      spring-webflux/src/test/java/org/springframework/web/reactive/result/view/AbstractViewTests.java

2
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java

@ -110,7 +110,7 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa
* @return indicates completion or error * @return indicates completion or error
* @since 5.0.2 * @since 5.0.2
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "rawtypes" })
protected Mono<Void> writeBody(@Nullable Object body, MethodParameter bodyParameter, protected Mono<Void> writeBody(@Nullable Object body, MethodParameter bodyParameter,
@Nullable MethodParameter actualParameter, ServerWebExchange exchange) { @Nullable MethodParameter actualParameter, ServerWebExchange exchange) {

3
spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/TomcatWebSocketSession.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,6 +38,7 @@ public class TomcatWebSocketSession extends StandardWebSocketSession {
private static final AtomicIntegerFieldUpdater<TomcatWebSocketSession> SUSPENDED = private static final AtomicIntegerFieldUpdater<TomcatWebSocketSession> SUSPENDED =
AtomicIntegerFieldUpdater.newUpdater(TomcatWebSocketSession.class, "suspended"); AtomicIntegerFieldUpdater.newUpdater(TomcatWebSocketSession.class, "suspended");
@SuppressWarnings("unused")
private volatile int suspended; private volatile int suspended;

13
spring-webflux/src/test/java/org/springframework/web/reactive/accept/HeaderContentTypeResolverTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,18 +13,17 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.reactive.accept; package org.springframework.web.reactive.accept;
import java.util.List; import java.util.List;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange; import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.NotAcceptableStatusException; import org.springframework.web.server.NotAcceptableStatusException;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -35,13 +34,7 @@ import static org.junit.Assert.assertEquals;
*/ */
public class HeaderContentTypeResolverTests { public class HeaderContentTypeResolverTests {
private HeaderContentTypeResolver resolver; private final HeaderContentTypeResolver resolver = new HeaderContentTypeResolver();
@Before
public void setup() {
this.resolver = new HeaderContentTypeResolver();
}
@Test @Test

4
spring-webflux/src/test/java/org/springframework/web/reactive/config/DelegatingWebFluxConfigurationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,14 +27,12 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.springframework.context.support.StaticApplicationContext; import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.FormatterRegistry; import org.springframework.format.FormatterRegistry;
import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.HttpMessageWriter;
import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder; import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*; import static org.mockito.BDDMockito.*;

4
spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -305,7 +305,7 @@ public class WebFluxConfigurationSupportTests {
@Override @Override
protected void configureHttpMessageCodecs(ServerCodecConfigurer configurer) { protected void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
configurer.registerDefaults(false); configurer.registerDefaults(false);
configurer.customCodecs().decoder(StringDecoder.textPlainOnly(true)); configurer.customCodecs().decoder(StringDecoder.textPlainOnly());
configurer.customCodecs().decoder(new Jaxb2XmlDecoder()); configurer.customCodecs().decoder(new Jaxb2XmlDecoder());
configurer.customCodecs().encoder(CharSequenceEncoder.textPlainOnly()); configurer.customCodecs().encoder(CharSequenceEncoder.textPlainOnly());
configurer.customCodecs().encoder(new Jaxb2XmlEncoder()); configurer.customCodecs().encoder(new Jaxb2XmlEncoder());

2
spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java

@ -76,7 +76,7 @@ public class BodyExtractorsTests {
public void createContext() { public void createContext() {
final List<HttpMessageReader<?>> messageReaders = new ArrayList<>(); final List<HttpMessageReader<?>> messageReaders = new ArrayList<>();
messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
messageReaders.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); messageReaders.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
messageReaders.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder())); messageReaders.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
messageReaders.add(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder())); messageReaders.add(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()));
messageReaders.add(new FormHttpMessageReader()); messageReaders.add(new FormHttpMessageReader());

6
spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,16 +23,12 @@ import reactor.core.publisher.Mono;
import reactor.test.StepVerifier; import reactor.test.StepVerifier;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.MultipartBodyBuilder; import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.http.codec.multipart.FilePart; import org.springframework.http.codec.multipart.FilePart;
import org.springframework.http.codec.multipart.FormFieldPart; import org.springframework.http.codec.multipart.FormFieldPart;
import org.springframework.http.codec.multipart.Part; import org.springframework.http.codec.multipart.Part;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient;

22
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java

@ -127,7 +127,7 @@ public class DefaultClientResponseTests {
when(mockResponse.getBody()).thenReturn(body); when(mockResponse.getBody()).thenReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections List<HttpMessageReader<?>> messageReaders = Collections
.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);
Mono<String> resultMono = defaultClientResponse.body(toMono(String.class)); Mono<String> resultMono = defaultClientResponse.body(toMono(String.class));
@ -148,7 +148,7 @@ public class DefaultClientResponseTests {
when(mockResponse.getBody()).thenReturn(body); when(mockResponse.getBody()).thenReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections List<HttpMessageReader<?>> messageReaders = Collections
.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);
Mono<String> resultMono = defaultClientResponse.bodyToMono(String.class); Mono<String> resultMono = defaultClientResponse.bodyToMono(String.class);
@ -169,7 +169,7 @@ public class DefaultClientResponseTests {
when(mockResponse.getBody()).thenReturn(body); when(mockResponse.getBody()).thenReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections List<HttpMessageReader<?>> messageReaders = Collections
.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);
Mono<String> resultMono = Mono<String> resultMono =
@ -192,7 +192,7 @@ public class DefaultClientResponseTests {
when(mockResponse.getBody()).thenReturn(body); when(mockResponse.getBody()).thenReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections List<HttpMessageReader<?>> messageReaders = Collections
.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);
Flux<String> resultFlux = defaultClientResponse.bodyToFlux(String.class); Flux<String> resultFlux = defaultClientResponse.bodyToFlux(String.class);
@ -214,7 +214,7 @@ public class DefaultClientResponseTests {
when(mockResponse.getBody()).thenReturn(body); when(mockResponse.getBody()).thenReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections List<HttpMessageReader<?>> messageReaders = Collections
.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);
Flux<String> resultFlux = Flux<String> resultFlux =
@ -238,7 +238,7 @@ public class DefaultClientResponseTests {
when(mockResponse.getBody()).thenReturn(body); when(mockResponse.getBody()).thenReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections List<HttpMessageReader<?>> messageReaders = Collections
.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);
ResponseEntity<String> result = defaultClientResponse.toEntity(String.class).block(); ResponseEntity<String> result = defaultClientResponse.toEntity(String.class).block();
@ -261,7 +261,7 @@ public class DefaultClientResponseTests {
when(mockResponse.getBody()).thenReturn(body); when(mockResponse.getBody()).thenReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections List<HttpMessageReader<?>> messageReaders = Collections
.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);
ResponseEntity<String> result = defaultClientResponse.toEntity( ResponseEntity<String> result = defaultClientResponse.toEntity(
@ -286,7 +286,7 @@ public class DefaultClientResponseTests {
when(mockResponse.getBody()).thenReturn(body); when(mockResponse.getBody()).thenReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections List<HttpMessageReader<?>> messageReaders = Collections
.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);
ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(String.class).block(); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(String.class).block();
@ -309,7 +309,7 @@ public class DefaultClientResponseTests {
when(mockResponse.getBody()).thenReturn(body); when(mockResponse.getBody()).thenReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections List<HttpMessageReader<?>> messageReaders = Collections
.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);
ResponseEntity<List<String>> result = defaultClientResponse.toEntityList( ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(
@ -331,7 +331,7 @@ public class DefaultClientResponseTests {
when(mockResponse.getBody()).thenReturn(body.flux()); when(mockResponse.getBody()).thenReturn(body.flux());
List<HttpMessageReader<?>> messageReaders = Collections List<HttpMessageReader<?>> messageReaders = Collections
.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);
StepVerifier.create(defaultClientResponse.bodyToMono(Void.class)) StepVerifier.create(defaultClientResponse.bodyToMono(Void.class))
@ -356,7 +356,7 @@ public class DefaultClientResponseTests {
when(mockResponse.getBody()).thenReturn(body.flux()); when(mockResponse.getBody()).thenReturn(body.flux());
List<HttpMessageReader<?>> messageReaders = Collections List<HttpMessageReader<?>> messageReaders = Collections
.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);
StepVerifier.create(defaultClientResponse.bodyToMono(Void.class)) StepVerifier.create(defaultClientResponse.bodyToMono(Void.class))

17
spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilderTests.java

@ -16,7 +16,6 @@
package org.springframework.web.reactive.function.server; package org.springframework.web.reactive.function.server;
import java.nio.ByteBuffer;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
@ -24,7 +23,6 @@ import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.BiFunction;
import org.junit.Test; import org.junit.Test;
import org.reactivestreams.Publisher; import org.reactivestreams.Publisher;
@ -34,8 +32,6 @@ import reactor.test.StepVerifier;
import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.codec.CharSequenceEncoder; import org.springframework.core.codec.CharSequenceEncoder;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.http.CacheControl; import org.springframework.http.CacheControl;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
@ -44,16 +40,13 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseCookie; import org.springframework.http.ResponseCookie;
import org.springframework.http.codec.EncoderHttpMessageWriter; import org.springframework.http.codec.EncoderHttpMessageWriter;
import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.HttpMessageWriter;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse; import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
import org.springframework.mock.web.test.server.MockServerWebExchange; import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserter;
import org.springframework.web.reactive.result.view.ViewResolver; import org.springframework.web.reactive.result.view.ViewResolver;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
@ -135,7 +128,6 @@ public class DefaultEntityResponseBuilderTests {
.verify(); .verify();
} }
@Test @Test
public void lastModified() throws Exception { public void lastModified() throws Exception {
ZonedDateTime now = ZonedDateTime.now(); ZonedDateTime now = ZonedDateTime.now();
@ -197,14 +189,6 @@ public class DefaultEntityResponseBuilderTests {
public void bodyInserter() throws Exception { public void bodyInserter() throws Exception {
String body = "foo"; String body = "foo";
Publisher<String> publisher = Mono.just(body); Publisher<String> publisher = Mono.just(body);
BiFunction<ServerHttpResponse, BodyInserter.Context, Mono<Void>> writer =
(response, strategies) -> {
byte[] bodyBytes = body.getBytes(UTF_8);
ByteBuffer byteBuffer = ByteBuffer.wrap(bodyBytes);
DataBuffer buffer = new DefaultDataBufferFactory().wrap(byteBuffer);
return response.writeWith(Mono.just(buffer));
};
Mono<EntityResponse<Publisher<String>>> result = EntityResponse.fromPublisher(publisher, String.class).build(); Mono<EntityResponse<Publisher<String>>> result = EntityResponse.fromPublisher(publisher, String.class).build();
@ -257,7 +241,6 @@ public class DefaultEntityResponseBuilderTests {
.verify(); .verify();
} }
@Test @Test
public void notModifiedLastModified() { public void notModifiedLastModified() {
ZonedDateTime now = ZonedDateTime.now(); ZonedDateTime now = ZonedDateTime.now();

17
spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.OptionalLong; import java.util.OptionalLong;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -59,14 +58,8 @@ import static org.springframework.web.reactive.function.BodyExtractors.toMono;
*/ */
public class DefaultServerRequestTests { public class DefaultServerRequestTests {
List<HttpMessageReader<?>> messageReaders; private final List<HttpMessageReader<?>> messageReaders = Collections.singletonList(
new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
@Before
public void createMocks() {
this.messageReaders = Collections.singletonList(
new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true)));
}
@Test @Test
@ -335,12 +328,12 @@ public class DefaultServerRequestTests {
.method(HttpMethod.GET, "http://example.com?foo=bar") .method(HttpMethod.GET, "http://example.com?foo=bar")
.headers(httpHeaders) .headers(httpHeaders)
.body(body); .body(body);
this.messageReaders = Collections.emptyList(); DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
Flux<String> resultFlux = request.bodyToFlux(String.class); Flux<String> resultFlux = request.bodyToFlux(String.class);
StepVerifier.create(resultFlux) StepVerifier.create(resultFlux)
.expectError(UnsupportedMediaTypeStatusException.class) .expectError(UnsupportedMediaTypeStatusException.class)
.verify(); .verify();
} }
} }

43
spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/RouterFunctionMappingTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,26 +16,15 @@
package org.springframework.web.reactive.function.server.support; package org.springframework.web.reactive.function.server.support;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.test.StepVerifier; import reactor.test.StepVerifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.codec.ByteBufferDecoder;
import org.springframework.http.codec.DecoderHttpMessageReader;
import org.springframework.http.codec.HttpMessageReader;
import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange; import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.reactive.function.server.HandlerFunction; import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse; import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
@ -44,20 +33,10 @@ import org.springframework.web.server.ServerWebExchange;
*/ */
public class RouterFunctionMappingTests { public class RouterFunctionMappingTests {
private final ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/match"));
private List<HttpMessageReader<?>> messageReaders; private final ServerCodecConfigurer codecConfigurer = ServerCodecConfigurer.create();
private ServerWebExchange exchange;
private ServerCodecConfigurer codecConfigurer;
@Before
public void setUp() {
this.messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/match"));
codecConfigurer = ServerCodecConfigurer.create();
}
@Test @Test
public void normal() { public void normal() {
@ -88,20 +67,4 @@ public class RouterFunctionMappingTests {
.verify(); .verify();
} }
@Configuration
@EnableWebFlux
private static class TestConfig {
public RouterFunction<ServerResponse> match() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
return RouterFunctions.route(RequestPredicates.GET("/match"), handlerFunction);
}
public RouterFunction<ServerResponse> noMatch() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<ServerResponse> routerFunction = request -> Mono.empty();
return RouterFunctions.route(RequestPredicates.GET("/no-match"), handlerFunction);
}
}
} }

7
spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.reactive.handler; package org.springframework.web.reactive.handler;
import java.net.URI; import java.net.URI;
@ -44,6 +45,7 @@ import static org.springframework.web.reactive.HandlerMapping.PATH_WITHIN_HANDLE
public class SimpleUrlHandlerMappingTests { public class SimpleUrlHandlerMappingTests {
@Test @Test
@SuppressWarnings("resource")
public void handlerMappingJavaConfig() throws Exception { public void handlerMappingJavaConfig() throws Exception {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(WebConfig.class); wac.register(WebConfig.class);
@ -61,6 +63,7 @@ public class SimpleUrlHandlerMappingTests {
} }
@Test @Test
@SuppressWarnings("resource")
public void handlerMappingXmlConfig() throws Exception { public void handlerMappingXmlConfig() throws Exception {
ClassPathXmlApplicationContext wac = new ClassPathXmlApplicationContext("map.xml", getClass()); ClassPathXmlApplicationContext wac = new ClassPathXmlApplicationContext("map.xml", getClass());
wac.refresh(); wac.refresh();
@ -118,7 +121,7 @@ public class SimpleUrlHandlerMappingTests {
@Configuration @Configuration
static class WebConfig { static class WebConfig {
@Bean @SuppressWarnings("unused") @Bean @SuppressWarnings("unused")
public SimpleUrlHandlerMapping handlerMapping() { public SimpleUrlHandlerMapping handlerMapping() {
SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping(); SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping();

4
spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceUrlProviderTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,7 +42,6 @@ import org.springframework.web.util.pattern.PathPattern;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
/** /**
* Unit tests for {@link ResourceUrlProvider}. * Unit tests for {@link ResourceUrlProvider}.
* *
@ -133,6 +132,7 @@ public class ResourceUrlProviderTests {
} }
@Test // SPR-12592 @Test // SPR-12592
@SuppressWarnings("resource")
public void initializeOnce() throws Exception { public void initializeOnce() throws Exception {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext()); context.setServletContext(new MockServletContext());

3
spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/ProducesRequestConditionTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,7 +21,6 @@ import java.util.Collections;
import org.junit.Test; import org.junit.Test;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange; import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;

3
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolverTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -58,6 +58,7 @@ public class CookieValueMethodArgumentResolverTests {
@Before @Before
@SuppressWarnings("resource")
public void setup() throws Exception { public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh(); context.refresh();

1
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java

@ -53,6 +53,7 @@ public class ExpressionValueMethodArgumentResolverTests {
@Before @Before
@SuppressWarnings("resource")
public void setup() throws Exception { public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh(); context.refresh();

4
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolverTests.java

@ -62,14 +62,14 @@ import static org.springframework.mock.http.server.reactive.test.MockServerHttpR
*/ */
public class HttpEntityArgumentResolverTests { public class HttpEntityArgumentResolverTests {
private HttpEntityArgumentResolver resolver = createResolver(); private final HttpEntityArgumentResolver resolver = createResolver();
private final ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build(); private final ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
private HttpEntityArgumentResolver createResolver() { private HttpEntityArgumentResolver createResolver() {
List<HttpMessageReader<?>> readers = new ArrayList<>(); List<HttpMessageReader<?>> readers = new ArrayList<>();
readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
return new HttpEntityArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance()); return new HttpEntityArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance());
} }

1
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java

@ -361,6 +361,7 @@ public class ModelAttributeMethodArgumentResolverTests {
} }
@SuppressWarnings("unused")
private static class Bar { private static class Bar {
private final String name; private final String name;

7
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,7 +43,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.bind.support.WebBindingInitializer; import org.springframework.web.bind.support.WebBindingInitializer;
@ -61,6 +60,7 @@ import static org.mockito.Mockito.mock;
/** /**
* Unit tests for {@link ModelInitializer}. * Unit tests for {@link ModelInitializer}.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class ModelInitializerTests { public class ModelInitializerTests {
@ -298,7 +298,4 @@ public class ModelInitializerTests {
private static final ReflectionUtils.MethodFilter BINDER_METHODS = method -> private static final ReflectionUtils.MethodFilter BINDER_METHODS = method ->
AnnotationUtils.findAnnotation(method, InitBinder.class) != null; AnnotationUtils.findAnnotation(method, InitBinder.class) != null;
private static final ReflectionUtils.MethodFilter ATTRIBUTE_METHODS = method ->
(AnnotationUtils.findAnnotation(method, RequestMapping.class) == null) &&
(AnnotationUtils.findAnnotation(method, ModelAttribute.class) != null);
} }

3
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolverTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -61,6 +61,7 @@ public class RequestAttributeMethodArgumentResolverTests {
@Before @Before
@SuppressWarnings("resource")
public void setup() throws Exception { public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh(); context.refresh();

4
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -69,7 +69,7 @@ public class RequestBodyArgumentResolverTests {
@Before @Before
public void setup() { public void setup() {
List<HttpMessageReader<?>> readers = new ArrayList<>(); List<HttpMessageReader<?>> readers = new ArrayList<>();
readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true))); readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
this.resolver = new RequestBodyArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance()); this.resolver = new RequestBodyArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance());
} }

3
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolverTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -70,6 +70,7 @@ public class RequestHeaderMethodArgumentResolverTests {
@Before @Before
@SuppressWarnings("resource")
public void setup() throws Exception { public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh(); context.refresh();

4
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,7 +18,6 @@ package org.springframework.web.reactive.result.method.annotation;
import java.io.IOException; import java.io.IOException;
import org.junit.Assume;
import org.junit.Test; import org.junit.Test;
import org.reactivestreams.Publisher; import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
@ -30,7 +29,6 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.http.server.reactive.bootstrap.ReactorHttpServer;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;

3
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SessionAttributeMethodArgumentResolverTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -72,6 +72,7 @@ public class SessionAttributeMethodArgumentResolverTests {
@Before @Before
@SuppressWarnings("resource")
public void setup() throws Exception { public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh(); context.refresh();

68
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/AbstractViewTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,7 +22,6 @@ import java.util.Map;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.Single; import io.reactivex.Single;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -45,52 +44,47 @@ import static org.junit.Assert.assertNull;
*/ */
public class AbstractViewTests { public class AbstractViewTests {
private MockServerWebExchange exchange; private MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
@Before
public void setup() {
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
}
@SuppressWarnings("unchecked") @Test
@Test @SuppressWarnings("unchecked")
public void resolveAsyncAttributes() { public void resolveAsyncAttributes() {
TestBean testBean1 = new TestBean("Bean1"); TestBean testBean1 = new TestBean("Bean1");
TestBean testBean2 = new TestBean("Bean2"); TestBean testBean2 = new TestBean("Bean2");
Map<String, Object> attributes = new HashMap<>(); Map<String, Object> attributes = new HashMap<>();
attributes.put("attr1", Mono.just(testBean1)); attributes.put("attr1", Mono.just(testBean1));
attributes.put("attr2", Flux.just(testBean1, testBean2)); attributes.put("attr2", Flux.just(testBean1, testBean2));
attributes.put("attr3", Single.just(testBean2)); attributes.put("attr3", Single.just(testBean2));
attributes.put("attr4", Observable.just(testBean1, testBean2)); attributes.put("attr4", Observable.just(testBean1, testBean2));
attributes.put("attr5", Mono.empty()); attributes.put("attr5", Mono.empty());
TestView view = new TestView(); TestView view = new TestView();
StepVerifier.create(view.render(attributes, null, this.exchange)).verifyComplete(); StepVerifier.create(
view.render(attributes, null, this.exchange)).verifyComplete();
Map<String, Object> actual = view.attributes; Map<String, Object> actual = view.attributes;
assertEquals(testBean1, actual.get("attr1")); assertEquals(testBean1, actual.get("attr1"));
assertArrayEquals(new TestBean[] {testBean1, testBean2}, ((List<TestBean>) actual.get("attr2")).toArray()); assertArrayEquals(new TestBean[] { testBean1, testBean2 },
assertEquals(testBean2, actual.get("attr3")); ((List<TestBean>) actual.get("attr2")).toArray());
assertArrayEquals(new TestBean[] {testBean1, testBean2}, ((List<TestBean>) actual.get("attr4")).toArray()); assertEquals(testBean2, actual.get("attr3"));
assertNull(actual.get("attr5")); assertArrayEquals(new TestBean[] { testBean1, testBean2 },
} ((List<TestBean>) actual.get("attr4")).toArray());
assertNull(actual.get("attr5"));
}
private static class TestView extends AbstractView {
private static class TestView extends AbstractView { private Map<String, Object> attributes;
private Map<String, Object> attributes; @Override
protected Mono<Void> renderInternal(Map<String, Object> renderAttributes,
@Override
protected Mono<Void> renderInternal(Map<String, Object> renderAttributes,
MediaType contentType, ServerWebExchange exchange) { MediaType contentType, ServerWebExchange exchange) {
this.attributes = renderAttributes; this.attributes = renderAttributes;
return Mono.empty(); return Mono.empty();
} }
}
public Map<String, Object> getAttributes() {
return this.attributes;
}
}
} }

Loading…
Cancel
Save