Migrate away from ExpectedException (#22922)

* Add limited checkstyles to test code

Add a limited set of checkstyle rules to the test codebase to improve
code consistency.

* Fix checksyle violations in test code

* Organize imports to fix checkstyle for test code

* Migrate to assertThatExceptionOfType

Migrate aware from ExpectedException rules to AssertJ exception
assertions. Also include a checkstyle rules to ensure that the
the ExpectedException is not accidentally used in the future.

See gh-22894
This commit is contained in:
Phil Webb
2019-05-08 07:25:52 -07:00
committed by Sam Brannen
parent 7e6e3d7027
commit d7320de871
671 changed files with 3861 additions and 4601 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -25,7 +25,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.NotAcceptableStatusException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* Unit tests for {@link HeaderContentTypeResolver}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,7 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.NotAcceptableStatusException;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* Unit tests for {@link ParameterContentTypeResolver}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,7 @@ import org.springframework.http.MediaType;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* Unit tests for {@link RequestedContentTypeResolverBuilder}.

View File

@@ -38,6 +38,7 @@ import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.BDDMockito.*;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -50,10 +50,7 @@ import org.springframework.web.reactive.resource.VersionResourceResolver;
import org.springframework.web.reactive.resource.WebJarsResourceResolver;
import static org.hamcrest.MatcherAssert.assertThat;
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 ResourceHandlerRegistry}.
@@ -126,7 +123,7 @@ public class ResourceHandlerRegistryTests {
this.registry.setResourceUrlProvider(resourceUrlProvider);
ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
ResourceTransformerSupport mockTransformer = Mockito.mock(ResourceTransformerSupport.class);
this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);
ResourceWebHandler handler = getHandler("/resources/**");

View File

@@ -78,15 +78,9 @@ import org.springframework.web.util.pattern.PathPatternParser;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.springframework.core.ResolvableType.forClass;
import static org.springframework.core.ResolvableType.forClassWithGenerics;
import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED;
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.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
import static org.springframework.core.ResolvableType.*;
import static org.springframework.http.MediaType.*;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.*;
/**
* Unit tests for {@link WebFluxConfigurationSupport}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -435,8 +435,8 @@ public class BodyExtractorsTests {
try {
buffer.release();
Assert.fail("releasing the buffer should have failed");
} catch (IllegalReferenceCountException exc) {
}
catch (IllegalReferenceCountException exc) {
}
body.assertCancelled();
}).verify();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,12 +46,9 @@ import org.springframework.http.codec.HttpMessageReader;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.springframework.web.reactive.function.BodyExtractors.*;
/**
* @author Arjen Poutsma
@@ -250,7 +247,8 @@ public class DefaultClientResponseTests {
try {
result.getStatusCode();
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
}
catch (IllegalArgumentException ex) {
// do nothing
}
assertEquals(999, result.getStatusCodeValue());
@@ -320,7 +318,8 @@ public class DefaultClientResponseTests {
try {
result.getStatusCode();
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
}
catch (IllegalArgumentException ex) {
// do nothing
}
assertEquals(999, result.getStatusCodeValue());

View File

@@ -35,6 +35,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
/**
@@ -287,12 +288,12 @@ public class DefaultWebClientTests {
@Test
public void shouldApplyFiltersAtSubscription() {
WebClient client = this.builder
.filter((request, next) -> {
return next.exchange(ClientRequest
.filter((request, next) ->
next.exchange(ClientRequest
.from(request)
.header("Custom", "value")
.build());
})
.build())
)
.build();
Mono<ClientResponse> exchange = client.get().uri("/path").exchange();
verifyZeroInteractions(this.exchangeFunction);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -730,9 +730,9 @@ public class WebClientIntegrationTests {
.exchange()
.flatMap(response -> response.toEntity(Void.class));
StepVerifier.create(result).assertNext(r -> {
assertTrue(r.getStatusCode().is2xxSuccessful());
}).verifyComplete();
StepVerifier.create(result).assertNext(r ->
assertTrue(r.getStatusCode().is2xxSuccessful())
).verifyComplete();
}
@Test // SPR-15782

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,6 +46,7 @@ import org.springframework.web.reactive.result.view.ViewResolverSupport;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,12 +30,8 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.pattern.PathPattern;
import static org.junit.Assert.*;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.all;
import static org.springframework.web.reactive.function.server.RequestPredicates.method;
import static org.springframework.web.reactive.function.server.RequestPredicates.path;
import static org.springframework.web.reactive.function.server.RouterFunctions.nest;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.RequestPredicates.*;
import static org.springframework.web.reactive.function.server.RouterFunctions.*;
/**
* @author Arjen Poutsma
@@ -141,7 +137,8 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
Flux<String> responseBody;
if (!pattern.isEmpty()) {
responseBody = Flux.just(pattern, "\n", pathVariables.toString());
} else {
}
else {
responseBody = Flux.just(pathVariables.toString());
}
return ServerResponse.ok().body(responseBody, String.class);

View File

@@ -203,9 +203,9 @@ public class RouterFunctionBuilderTests {
StepVerifier.create(fooResponseMono)
.consumeNextWith(serverResponse -> {
assertEquals(4, filterCount.get());
})
.consumeNextWith(serverResponse ->
assertEquals(4, filterCount.get())
)
.verifyComplete();
filterCount.set(0);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -109,12 +109,12 @@ public class RouterFunctionTests {
StepVerifier.create(responseMono)
.consumeNextWith(
serverResponse -> {
serverResponse ->
StepVerifier.create(serverResponse.entity())
.expectNext(42)
.expectComplete()
.verify();
})
.verify()
)
.expectComplete()
.verify();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,15 +23,8 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import static org.junit.Assert.*;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
import static org.springframework.web.reactive.function.server.RequestPredicates.contentType;
import static org.springframework.web.reactive.function.server.RequestPredicates.method;
import static org.springframework.web.reactive.function.server.RequestPredicates.methods;
import static org.springframework.web.reactive.function.server.RequestPredicates.path;
import static org.springframework.web.reactive.function.server.RequestPredicates.pathExtension;
import static org.springframework.web.reactive.function.server.RequestPredicates.queryParam;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.RequestPredicates.*;
import static org.springframework.web.reactive.function.server.RouterFunctions.*;
/**
* @author Arjen Poutsma
@@ -42,11 +35,11 @@ public class ToStringVisitorTests {
public void nested() {
HandlerFunction<ServerResponse> handler = new SimpleHandlerFunction();
RouterFunction<ServerResponse> routerFunction = route()
.path("/foo", builder -> {
.path("/foo", builder ->
builder.path("/bar", () -> route()
.GET("/baz", handler)
.build());
})
.build())
)
.build();
ToStringVisitor visitor = new ToStringVisitor();

View File

@@ -28,10 +28,7 @@ import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsConfigurationSource;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.*;
/**
* Unit tests for CORS support at {@link AbstractUrlHandlerMapping} level.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,11 +31,8 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.server.ServerWebExchange;
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.springframework.web.reactive.HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE;
import static org.junit.Assert.*;
import static org.springframework.web.reactive.HandlerMapping.*;
/**
* Unit tests for {@link SimpleUrlHandlerMapping}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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 org.junit.Test;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.reactive.handler.WebFluxResponseStatusExceptionHandler;
import org.springframework.web.server.handler.ResponseStatusExceptionHandler;
import org.springframework.web.server.handler.ResponseStatusExceptionHandlerTests;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://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,
@@ -43,7 +43,7 @@ public class AppCacheManifestTransformerTests {
private static final Duration TIMEOUT = Duration.ofSeconds(5);
private AppCacheManifestTransformer transformer;
private ResourceTransformerChain chain;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://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,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.resource;
import java.util.Collections;
@@ -25,8 +26,7 @@ import org.springframework.core.io.Resource;
import org.springframework.util.DigestUtils;
import org.springframework.util.FileCopyUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.*;
/**
* Unit tests for {@link ContentVersionStrategy}.

View File

@@ -26,12 +26,8 @@ import org.springframework.core.io.FileUrlResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import static java.util.Collections.singletonList;
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.fail;
import static java.util.Collections.*;
import static org.junit.Assert.*;
/**
* Unit tests for {@link PathResourceResolver}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -29,14 +29,9 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
import static org.mockito.BDDMockito.never;
import static org.mockito.BDDMockito.times;
import static org.mockito.BDDMockito.verify;
import static java.util.Collections.*;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
* Unit tests for {@link WebJarsResourceResolver}.

View File

@@ -31,14 +31,8 @@ import org.springframework.web.reactive.accept.FixedContentTypeResolver;
import org.springframework.web.reactive.accept.HeaderContentTypeResolver;
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
import static org.junit.Assert.assertEquals;
import static org.springframework.http.MediaType.ALL;
import static org.springframework.http.MediaType.APPLICATION_JSON;
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.junit.Assert.*;
import static org.springframework.http.MediaType.*;
/**
* Unit tests for {@link HandlerResultHandlerSupport}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,9 +23,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.bind.annotation.RequestMethod;
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}.

View File

@@ -26,11 +26,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.reactive.result.condition.ConsumesRequestCondition.ConsumeMediaTypeExpression;
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.fail;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,10 +27,8 @@ import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.util.pattern.PathPattern;
import org.springframework.web.util.pattern.PathPatternParser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
import static org.junit.Assert.*;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.*;
/**
* Unit tests for {@link PatternsRequestCondition}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,10 +22,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.bind.annotation.RequestMethod;
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 RequestConditionHolder}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,9 +22,7 @@ import java.util.Comparator;
import java.util.List;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@@ -37,13 +35,10 @@ import org.springframework.web.util.pattern.PathPattern;
import org.springframework.web.util.pattern.PathPatternParser;
import org.springframework.web.util.pattern.PatternParseException;
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 org.springframework.web.reactive.result.method.RequestMappingInfo.paths;
import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.*;
import static org.springframework.web.reactive.result.method.RequestMappingInfo.*;
/**
* Unit tests for {@link RequestMappingInfo}.
@@ -52,9 +47,6 @@ import static org.springframework.web.reactive.result.method.RequestMappingInfo.
*/
public class RequestMappingInfoTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
// TODO: CORS pre-flight (see @Ignore)
@@ -74,9 +66,9 @@ public class RequestMappingInfoTests {
@Test
public void throwWhenInvalidPattern() {
this.thrown.expect(PatternParseException.class);
this.thrown.expectMessage("Expected close capture character after variable name }");
paths("/{foo").build();
assertThatExceptionOfType(PatternParseException.class).isThrownBy(() ->
paths("/{foo").build())
.withMessageContaining("Expected close capture character after variable name }");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,7 +45,7 @@ import org.springframework.web.server.UnsupportedMediaTypeStatusException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.*;

View File

@@ -50,7 +50,7 @@ import org.springframework.web.method.HandlerMethod;
import org.springframework.web.reactive.BindingContext;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.reactive.result.method.RequestMappingInfo.*;
import org.springframework.web.reactive.result.method.RequestMappingInfo.BuilderConfiguration;
import org.springframework.web.server.MethodNotAllowedException;
import org.springframework.web.server.NotAcceptableStatusException;
import org.springframework.web.server.ServerWebExchange;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-201 the original author or authors.
* Copyright 2002-2019 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.result.method.annotation;
import java.lang.reflect.Method;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,9 +18,7 @@ package org.springframework.web.reactive.result.method.annotation;
import java.time.Duration;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import reactor.core.publisher.Mono;
import reactor.core.publisher.MonoProcessor;
@@ -36,6 +34,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.method.ResolvableMethod;
import org.springframework.web.reactive.BindingContext;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
/**
@@ -55,9 +54,6 @@ public class ErrorsMethodArgumentResolverTests {
private final ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
@Rule
public final ExpectedException expectedException = ExpectedException.none();
@Test
public void supports() {
@@ -107,22 +103,22 @@ public class ErrorsMethodArgumentResolverTests {
@Test
public void resolveWithMonoOnBindingResultAndModelAttribute() {
this.expectedException.expectMessage("An @ModelAttribute and an Errors/BindingResult argument " +
"cannot both be declared with an async type wrapper.");
MethodParameter parameter = this.testMethod.arg(BindingResult.class);
this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.block(Duration.ofMillis(5000));
assertThatIllegalStateException().isThrownBy(() ->
this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.block(Duration.ofMillis(5000)))
.withMessageContaining("An @ModelAttribute and an Errors/BindingResult argument " +
"cannot both be declared with an async type wrapper.");
}
@Test // SPR-16187
public void resolveWithBindingResultNotFound() {
this.expectedException.expectMessage("An Errors/BindingResult argument is expected " +
"immediately after the @ModelAttribute argument");
MethodParameter parameter = this.testMethod.arg(Errors.class);
this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.block(Duration.ofMillis(5000));
assertThatIllegalStateException().isThrownBy(() ->
this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.block(Duration.ofMillis(5000)))
.withMessageContaining("An Errors/BindingResult argument is expected " +
"immediately after the @ModelAttribute argument");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -33,9 +33,7 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.*;
/**
* Unit tests for {@link AbstractView}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,9 +30,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.reactive.HandlerMapping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
/**
* Tests for redirect view, and query string construction.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -26,7 +26,7 @@ import org.springframework.context.support.GenericApplicationContext;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* Unit tests for {@link RequestContext}.

View File

@@ -23,9 +23,7 @@ import java.util.Locale;
import freemarker.template.Configuration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import reactor.test.StepVerifier;
import org.springframework.context.ApplicationContextException;
@@ -42,6 +40,7 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange;
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
import org.springframework.web.server.session.DefaultWebSessionManager;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
/**
@@ -60,9 +59,6 @@ public class FreeMarkerViewTests {
private Configuration freeMarkerConfig;
@Rule
public final ExpectedException exception = ExpectedException.none();
@Before
public void setup() throws Exception {
@@ -79,22 +75,20 @@ public class FreeMarkerViewTests {
@Test
public void noFreeMarkerConfig() throws Exception {
this.exception.expect(ApplicationContextException.class);
this.exception.expectMessage("Must define a single FreeMarkerConfig bean");
FreeMarkerView view = new FreeMarkerView();
view.setApplicationContext(this.context);
view.setUrl("anythingButNull");
view.afterPropertiesSet();
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(
view::afterPropertiesSet)
.withMessageContaining("Must define a single FreeMarkerConfig bean");
}
@Test
public void noTemplateName() throws Exception {
this.exception.expect(IllegalArgumentException.class);
this.exception.expectMessage("Property 'url' is required");
FreeMarkerView freeMarkerView = new FreeMarkerView();
freeMarkerView.afterPropertiesSet();
assertThatIllegalArgumentException().isThrownBy(
freeMarkerView::afterPropertiesSet)
.withMessageContaining("Property 'url' is required");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* Unit tests for ERB templates running on JRuby.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -29,7 +29,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* Unit tests for String templates running on Jython.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,7 +32,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* Unit tests for Kotlin script templates running on Kotlin JSR-223 support.

View File

@@ -35,7 +35,7 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange;
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
import org.springframework.web.server.session.DefaultWebSessionManager;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* Unit tests for pure JavaScript templates running on Nashorn engine.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -26,17 +26,17 @@ import java.util.concurrent.Future;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.mockito.BDDMockito.*;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.context.ApplicationContextException;
import org.springframework.context.support.StaticApplicationContext;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
* Unit tests for {@link ScriptTemplateView}.
*
@@ -50,9 +50,6 @@ public class ScriptTemplateViewTests {
private StaticApplicationContext context;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setup() {
@@ -76,9 +73,9 @@ public class ScriptTemplateViewTests {
@Test
public void missingScriptTemplateConfig() throws Exception {
this.expectedException.expect(ApplicationContextException.class);
this.view.setApplicationContext(new StaticApplicationContext());
this.expectedException.expectMessage(contains("ScriptTemplateConfig"));
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() ->
this.view.setApplicationContext(new StaticApplicationContext()))
.withMessageContaining("ScriptTemplateConfig");
}
@Test
@@ -159,8 +156,8 @@ public class ScriptTemplateViewTests {
public void nonInvocableScriptEngineWithRenderFunction() throws Exception {
this.view.setEngine(mock(ScriptEngine.class));
this.view.setRenderFunction("render");
this.expectedException.expect(IllegalArgumentException.class);
this.view.setApplicationContext(this.context);
assertThatIllegalArgumentException().isThrownBy(() ->
this.view.setApplicationContext(this.context));
}
@Test
@@ -168,9 +165,9 @@ public class ScriptTemplateViewTests {
this.view.setEngine(mock(InvocableScriptEngine.class));
this.view.setEngineName("test");
this.view.setRenderFunction("render");
this.expectedException.expect(IllegalArgumentException.class);
this.view.setApplicationContext(this.context);
this.expectedException.expectMessage(contains("'engine' or 'engineName'"));
assertThatIllegalArgumentException().isThrownBy(() ->
this.view.setApplicationContext(this.context))
.withMessageContaining("'engine' or 'engineName'");
}
@Test
@@ -178,9 +175,9 @@ public class ScriptTemplateViewTests {
this.view.setEngine(mock(InvocableScriptEngine.class));
this.view.setRenderFunction("render");
this.view.setSharedEngine(false);
this.expectedException.expect(IllegalArgumentException.class);
this.view.setApplicationContext(this.context);
this.expectedException.expectMessage(contains("sharedEngine"));
assertThatIllegalArgumentException().isThrownBy(() ->
this.view.setApplicationContext(this.context))
.withMessageContaining("sharedEngine");
}
private interface InvocableScriptEngine extends ScriptEngine, Invocable {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -129,9 +129,9 @@ public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests
return session.receive()
.doOnNext(s -> logger.debug("inbound " + s))
.then()
.doFinally(signalType -> {
logger.debug("Completed with: " + signalType);
});
.doFinally(signalType ->
logger.debug("Completed with: " + signalType)
);
})
.block(TIMEOUT);
}