Use new features from JUnit Jupiter 5.11
This commit primarily migrates to the new argumentSet() feature but also applies additional polishing to our use of parameterized tests. See gh-33395
This commit is contained in:
@@ -55,8 +55,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
import static org.springframework.core.ResolvableType.forClass;
|
||||
import static org.springframework.core.io.buffer.DataBufferUtils.release;
|
||||
|
||||
@@ -430,7 +429,7 @@ class DefaultPartHttpMessageReaderTests {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("org.springframework.http.codec.multipart.DefaultPartHttpMessageReaderTests#messageReaders()")
|
||||
@interface ParameterizedDefaultPartHttpMessageReaderTest {
|
||||
}
|
||||
@@ -443,8 +442,8 @@ class DefaultPartHttpMessageReaderTests {
|
||||
onDisk.setMaxInMemorySize(100);
|
||||
|
||||
return Stream.of(
|
||||
arguments(named("in-memory", inMemory)),
|
||||
arguments(named("on-disk", onDisk)));
|
||||
argumentSet("in-memory", inMemory),
|
||||
argumentSet("on-disk", onDisk));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@ import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
|
||||
/**
|
||||
* Tests for {@code HeadersAdapters} {@code MultiValueMap} implementations.
|
||||
@@ -129,19 +128,19 @@ class HeadersAdaptersTests {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("headers")
|
||||
@interface ParameterizedHeadersTest {
|
||||
}
|
||||
|
||||
static Stream<Arguments> headers() {
|
||||
return Stream.of(
|
||||
arguments(named("Map", CollectionUtils.toMultiValueMap(new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH)))),
|
||||
arguments(named("Netty", new Netty4HeadersAdapter(new DefaultHttpHeaders()))),
|
||||
arguments(named("Netty", new Netty5HeadersAdapter(io.netty5.handler.codec.http.headers.HttpHeaders.newHeaders()))),
|
||||
arguments(named("Tomcat", new TomcatHeadersAdapter(new MimeHeaders()))),
|
||||
arguments(named("Undertow", new UndertowHeadersAdapter(new HeaderMap()))),
|
||||
arguments(named("Jetty", new JettyHeadersAdapter(HttpFields.build())))
|
||||
argumentSet("Map", CollectionUtils.toMultiValueMap(new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH))),
|
||||
argumentSet("Netty", new Netty4HeadersAdapter(new DefaultHttpHeaders())),
|
||||
argumentSet("Netty", new Netty5HeadersAdapter(io.netty5.handler.codec.http.headers.HttpHeaders.newHeaders())),
|
||||
argumentSet("Tomcat", new TomcatHeadersAdapter(new MimeHeaders())),
|
||||
argumentSet("Undertow", new UndertowHeadersAdapter(new HeaderMap())),
|
||||
argumentSet("Jetty", new JettyHeadersAdapter(HttpFields.build()))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class DefaultResponseErrorHandlerHttpStatusTests {
|
||||
private final ClientHttpResponse response = mock();
|
||||
|
||||
|
||||
@ParameterizedTest(name = "[{index}] error: [{0}]")
|
||||
@ParameterizedTest(name = "[{index}] error: {0}")
|
||||
@DisplayName("hasError() returns true")
|
||||
@MethodSource("errorCodes")
|
||||
void hasErrorTrue(HttpStatus httpStatus) throws Exception {
|
||||
@@ -70,7 +70,7 @@ class DefaultResponseErrorHandlerHttpStatusTests {
|
||||
assertThat(this.handler.hasError(this.response)).isTrue();
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "[{index}] error: {0}, exception: {1}")
|
||||
@ParameterizedTest(name = "[{index}] {0} -> {1}")
|
||||
@DisplayName("handleError() throws an exception")
|
||||
@MethodSource("errorCodes")
|
||||
void handleErrorException(HttpStatus httpStatus, Class<? extends Throwable> expectedExceptionClass) throws Exception {
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.web.context.request.RequestAttributes.SCOPE_REQUEST;
|
||||
|
||||
@@ -49,9 +50,9 @@ class RequestAttributesThreadLocalAccessorTests {
|
||||
|
||||
|
||||
private static Stream<Arguments> propagation() {
|
||||
RequestAttributes previous = mock(RequestAttributes.class);
|
||||
RequestAttributes current = mock(RequestAttributes.class);
|
||||
return Stream.of(Arguments.of(null, current), Arguments.of(previous, current));
|
||||
RequestAttributes previous = mock();
|
||||
RequestAttributes current = mock();
|
||||
return Stream.of(arguments(null, current), arguments(previous, current));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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,10 +26,10 @@ import java.util.stream.Stream;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
|
||||
public abstract class AbstractHttpHandlerIntegrationTests {
|
||||
|
||||
@@ -117,19 +117,19 @@ public abstract class AbstractHttpHandlerIntegrationTests {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("org.springframework.web.testfixture.http.server.reactive.bootstrap.AbstractHttpHandlerIntegrationTests#httpServers()")
|
||||
// public for Kotlin
|
||||
public @interface ParameterizedHttpServerTest {
|
||||
}
|
||||
|
||||
static Stream<Named<HttpServer>> httpServers() {
|
||||
static Stream<Arguments> httpServers() {
|
||||
return Stream.of(
|
||||
named("Jetty", new JettyHttpServer()),
|
||||
named("Jetty Core", new JettyCoreHttpServer()),
|
||||
named("Reactor Netty", new ReactorHttpServer()),
|
||||
named("Tomcat", new TomcatHttpServer()),
|
||||
named("Undertow", new UndertowHttpServer())
|
||||
argumentSet("Jetty", new JettyHttpServer()),
|
||||
argumentSet("Jetty Core", new JettyCoreHttpServer()),
|
||||
argumentSet("Reactor Netty", new ReactorHttpServer()),
|
||||
argumentSet("Tomcat", new TomcatHttpServer()),
|
||||
argumentSet("Undertow", new UndertowHttpServer())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user