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
|
||||
|
||||
Reference in New Issue
Block a user