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:
@@ -54,8 +54,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
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 various {@link Resource} implementations.
|
||||
@@ -67,7 +66,7 @@ import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
*/
|
||||
class ResourceTests {
|
||||
|
||||
@ParameterizedTest(name = "{index}: {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("resource")
|
||||
void resourceIsValid(Resource resource) throws Exception {
|
||||
assertThat(resource.getFilename()).isEqualTo("ResourceTests.class");
|
||||
@@ -79,7 +78,7 @@ class ResourceTests {
|
||||
assertThat(resource.getContentAsByteArray()).containsExactly(Files.readAllBytes(Path.of(resource.getURI())));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{index}: {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("resource")
|
||||
void resourceCreateRelative(Resource resource) throws Exception {
|
||||
Resource relative1 = resource.createRelative("ClassPathResourceTests.class");
|
||||
@@ -91,7 +90,7 @@ class ResourceTests {
|
||||
assertThat(relative1.lastModified()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{index}: {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("resource")
|
||||
void resourceCreateRelativeWithFolder(Resource resource) throws Exception {
|
||||
Resource relative2 = resource.createRelative("support/PathMatchingResourcePatternResolverTests.class");
|
||||
@@ -103,7 +102,7 @@ class ResourceTests {
|
||||
assertThat(relative2.lastModified()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{index}: {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("resource")
|
||||
void resourceCreateRelativeWithDotPath(Resource resource) throws Exception {
|
||||
Resource relative3 = resource.createRelative("../CollectionFactoryTests.class");
|
||||
@@ -115,7 +114,7 @@ class ResourceTests {
|
||||
assertThat(relative3.lastModified()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{index}: {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("resource")
|
||||
void resourceCreateRelativeUnknown(Resource resource) throws Exception {
|
||||
Resource relative4 = resource.createRelative("X.class");
|
||||
@@ -133,13 +132,13 @@ class ResourceTests {
|
||||
URL resourceClass = ResourceTests.class.getResource("ResourceTests.class");
|
||||
Path resourceClassFilePath = Paths.get(resourceClass.toURI());
|
||||
return Stream.of(
|
||||
arguments(named("ClassPathResource", new ClassPathResource("org/springframework/core/io/ResourceTests.class"))),
|
||||
arguments(named("ClassPathResource with ClassLoader", new ClassPathResource("org/springframework/core/io/ResourceTests.class", ResourceTests.class.getClassLoader()))),
|
||||
arguments(named("ClassPathResource with Class", new ClassPathResource("ResourceTests.class", ResourceTests.class))),
|
||||
arguments(named("FileSystemResource", new FileSystemResource(resourceClass.getFile()))),
|
||||
arguments(named("FileSystemResource with File", new FileSystemResource(new File(resourceClass.getFile())))),
|
||||
arguments(named("FileSystemResource with File path", new FileSystemResource(resourceClassFilePath))),
|
||||
arguments(named("UrlResource", new UrlResource(resourceClass)))
|
||||
argumentSet("ClassPathResource", new ClassPathResource("org/springframework/core/io/ResourceTests.class")),
|
||||
argumentSet("ClassPathResource with ClassLoader", new ClassPathResource("org/springframework/core/io/ResourceTests.class", ResourceTests.class.getClassLoader())),
|
||||
argumentSet("ClassPathResource with Class", new ClassPathResource("ResourceTests.class", ResourceTests.class)),
|
||||
argumentSet("FileSystemResource", new FileSystemResource(resourceClass.getFile())),
|
||||
argumentSet("FileSystemResource with File", new FileSystemResource(new File(resourceClass.getFile()))),
|
||||
argumentSet("FileSystemResource with File path", new FileSystemResource(resourceClassFilePath)),
|
||||
argumentSet("UrlResource", new UrlResource(resourceClass))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -32,8 +32,7 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.SoftAssertions.assertSoftly;
|
||||
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 {@link MultiValueMap}.
|
||||
@@ -184,18 +183,18 @@ class MultiValueMapTests {
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("mapsUnderTest")
|
||||
@interface ParameterizedMultiValueMapTest {
|
||||
}
|
||||
|
||||
static Stream<Arguments> mapsUnderTest() {
|
||||
return Stream.of(
|
||||
arguments(named("new LinkedMultiValueMap<>()", new LinkedMultiValueMap<>())),
|
||||
arguments(named("new LinkedMultiValueMap<>(new HashMap<>())", new LinkedMultiValueMap<>(new HashMap<>()))),
|
||||
arguments(named("new LinkedMultiValueMap<>(new LinkedHashMap<>())", new LinkedMultiValueMap<>(new LinkedHashMap<>()))),
|
||||
arguments(named("new LinkedMultiValueMap<>(Map.of(...))", new LinkedMultiValueMap<>(Map.of("existingkey", List.of("existingvalue1", "existingvalue2"))))),
|
||||
arguments(named("CollectionUtils.toMultiValueMap", CollectionUtils.toMultiValueMap(new HashMap<>())))
|
||||
argumentSet("new LinkedMultiValueMap<>()", new LinkedMultiValueMap<>()),
|
||||
argumentSet("new LinkedMultiValueMap<>(new HashMap<>())", new LinkedMultiValueMap<>(new HashMap<>())),
|
||||
argumentSet("new LinkedMultiValueMap<>(new LinkedHashMap<>())", new LinkedMultiValueMap<>(new LinkedHashMap<>())),
|
||||
argumentSet("new LinkedMultiValueMap<>(Map.of(...))", new LinkedMultiValueMap<>(Map.of("existingkey", List.of("existingvalue1", "existingvalue2")))),
|
||||
argumentSet("CollectionUtils.toMultiValueMap", CollectionUtils.toMultiValueMap(new HashMap<>()))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,7 @@ import org.springframework.core.io.buffer.NettyDataBufferFactory;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Base class for tests that read or write data buffers with an extension to check
|
||||
@@ -197,7 +196,7 @@ public abstract class AbstractDataBufferAllocatingTests {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("org.springframework.core.testfixture.io.buffer.AbstractDataBufferAllocatingTests#dataBufferFactories()")
|
||||
public @interface ParameterizedDataBufferAllocatingTest {
|
||||
}
|
||||
@@ -205,28 +204,28 @@ public abstract class AbstractDataBufferAllocatingTests {
|
||||
public static Stream<Arguments> dataBufferFactories() {
|
||||
return Stream.of(
|
||||
// Netty 4
|
||||
arguments(named("NettyDataBufferFactory - UnpooledByteBufAllocator - preferDirect = true",
|
||||
new NettyDataBufferFactory(netty4OffHeapUnpooled))),
|
||||
arguments(named("NettyDataBufferFactory - UnpooledByteBufAllocator - preferDirect = false",
|
||||
new NettyDataBufferFactory(netty4OnHeapUnpooled))),
|
||||
arguments(named("NettyDataBufferFactory - PooledByteBufAllocator - preferDirect = true",
|
||||
new NettyDataBufferFactory(netty4OffHeapPooled))),
|
||||
arguments(named("NettyDataBufferFactory - PooledByteBufAllocator - preferDirect = false",
|
||||
new NettyDataBufferFactory(netty4OnHeapPooled))),
|
||||
argumentSet("NettyDataBufferFactory - UnpooledByteBufAllocator - preferDirect = true",
|
||||
new NettyDataBufferFactory(netty4OffHeapUnpooled)),
|
||||
argumentSet("NettyDataBufferFactory - UnpooledByteBufAllocator - preferDirect = false",
|
||||
new NettyDataBufferFactory(netty4OnHeapUnpooled)),
|
||||
argumentSet("NettyDataBufferFactory - PooledByteBufAllocator - preferDirect = true",
|
||||
new NettyDataBufferFactory(netty4OffHeapPooled)),
|
||||
argumentSet("NettyDataBufferFactory - PooledByteBufAllocator - preferDirect = false",
|
||||
new NettyDataBufferFactory(netty4OnHeapPooled)),
|
||||
// Netty 5
|
||||
arguments(named("Netty5DataBufferFactory - BufferAllocator.onHeapUnpooled()",
|
||||
new Netty5DataBufferFactory(netty5OnHeapUnpooled))),
|
||||
arguments(named("Netty5DataBufferFactory - BufferAllocator.offHeapUnpooled()",
|
||||
new Netty5DataBufferFactory(netty5OffHeapUnpooled))),
|
||||
arguments(named("Netty5DataBufferFactory - BufferAllocator.onHeapPooled()",
|
||||
new Netty5DataBufferFactory(netty5OnHeapPooled))),
|
||||
arguments(named("Netty5DataBufferFactory - BufferAllocator.offHeapPooled()",
|
||||
new Netty5DataBufferFactory(netty5OffHeapPooled))),
|
||||
argumentSet("Netty5DataBufferFactory - BufferAllocator.onHeapUnpooled()",
|
||||
new Netty5DataBufferFactory(netty5OnHeapUnpooled)),
|
||||
argumentSet("Netty5DataBufferFactory - BufferAllocator.offHeapUnpooled()",
|
||||
new Netty5DataBufferFactory(netty5OffHeapUnpooled)),
|
||||
argumentSet("Netty5DataBufferFactory - BufferAllocator.onHeapPooled()",
|
||||
new Netty5DataBufferFactory(netty5OnHeapPooled)),
|
||||
argumentSet("Netty5DataBufferFactory - BufferAllocator.offHeapPooled()",
|
||||
new Netty5DataBufferFactory(netty5OffHeapPooled)),
|
||||
// Default
|
||||
arguments(named("DefaultDataBufferFactory - preferDirect = true",
|
||||
new DefaultDataBufferFactory(true))),
|
||||
arguments(named("DefaultDataBufferFactory - preferDirect = false",
|
||||
new DefaultDataBufferFactory(false)))
|
||||
argumentSet("DefaultDataBufferFactory - preferDirect = true",
|
||||
new DefaultDataBufferFactory(true)),
|
||||
argumentSet("DefaultDataBufferFactory - preferDirect = false",
|
||||
new DefaultDataBufferFactory(false))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.within;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
|
||||
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.expression.spel.SpelMessage.EXCEPTION_DURING_INDEX_READ;
|
||||
import static org.springframework.expression.spel.standard.SpelExpressionTestUtils.assertIsCompiled;
|
||||
|
||||
@@ -955,7 +954,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
assertThat(getAst().getExitDescriptor()).isEqualTo(exitTypeDescriptor);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("fruitMapIndexAccessors")
|
||||
void indexWithReferenceIndexTypeAndReferenceValueType(IndexAccessor indexAccessor) {
|
||||
String exitTypeDescriptor = CodeFlow.toDescriptor(String.class);
|
||||
@@ -1010,10 +1009,10 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
|
||||
static Stream<Arguments> fruitMapIndexAccessors() {
|
||||
return Stream.of(
|
||||
arguments(named("FruitMapIndexAccessor",
|
||||
new FruitMapIndexAccessor())),
|
||||
arguments(named("ReflectiveIndexAccessor",
|
||||
new ReflectiveIndexAccessor(FruitMap.class, Color.class, "getFruit", "setFruit")))
|
||||
argumentSet("FruitMapIndexAccessor",
|
||||
new FruitMapIndexAccessor()),
|
||||
argumentSet("ReflectiveIndexAccessor",
|
||||
new ReflectiveIndexAccessor(FruitMap.class, Color.class, "getFruit", "setFruit"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,14 +218,14 @@ class StatementCreatorUtilsTests {
|
||||
verify(preparedStatement).setTimestamp(1, new java.sql.Timestamp(cal.getTime().getTime()), cal);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ParameterizedTest(name = "{0} -> {1}")
|
||||
@MethodSource("javaTimeTypes")
|
||||
public void testSetParameterValueWithJavaTimeTypes(Object o, int sqlType) throws SQLException {
|
||||
StatementCreatorUtils.setParameterValue(preparedStatement, 1, sqlType, o);
|
||||
verify(preparedStatement).setObject(1, o, sqlType);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ParameterizedTest(name = "{0} -> {1}")
|
||||
@MethodSource("javaTimeTypes")
|
||||
void javaTimeTypesToSqlParameterType(Object o, int expectedSqlType) {
|
||||
assertThat(StatementCreatorUtils.javaTypeToSqlParameterType(o.getClass()))
|
||||
|
||||
@@ -28,7 +28,6 @@ import jakarta.jms.MessageListener;
|
||||
import jakarta.jms.TextMessage;
|
||||
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.artemis.junit.EmbeddedActiveMQExtension;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
@@ -40,8 +39,7 @@ import org.springframework.jms.core.JmsTemplate;
|
||||
|
||||
import static io.micrometer.observation.tck.TestObservationRegistryAssert.assertThat;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Observation tests for {@link AbstractMessageListenerContainer} implementations.
|
||||
@@ -63,7 +61,7 @@ class MessageListenerContainerObservationTests {
|
||||
connectionFactory = new ActiveMQConnectionFactory(server.getVmURL());
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("listenerContainers")
|
||||
void shouldRecordJmsProcessObservations(AbstractMessageListenerContainer listenerContainer) throws Exception {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
@@ -84,14 +82,13 @@ class MessageListenerContainerObservationTests {
|
||||
listenerContainer.shutdown();
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("listenerContainers")
|
||||
void shouldRecordJmsPublishObservations(AbstractMessageListenerContainer listenerContainer) throws Exception {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
listenerContainer.setConnectionFactory(connectionFactory);
|
||||
listenerContainer.setObservationRegistry(registry);
|
||||
listenerContainer.setDestinationName("spring.test.observation");
|
||||
listenerContainer.setMessageListener((SessionAwareMessageListener) (message, session) -> {
|
||||
listenerContainer.setMessageListener((SessionAwareMessageListener<?>) (message, session) -> {
|
||||
Message response = session.createTextMessage("test response");
|
||||
session.createProducer(message.getJMSReplyTo()).send(response);
|
||||
});
|
||||
@@ -106,12 +103,12 @@ class MessageListenerContainerObservationTests {
|
||||
// response sent to the template
|
||||
assertThat(registry).hasNumberOfObservationsWithNameEqualTo("jms.message.publish", 1);
|
||||
|
||||
Assertions.assertThat(response.getText()).isEqualTo("test response");
|
||||
assertThat(response.getText()).isEqualTo("test response");
|
||||
listenerContainer.stop();
|
||||
listenerContainer.shutdown();
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("listenerContainers")
|
||||
void shouldHaveObservationScopeInErrorHandler(AbstractMessageListenerContainer listenerContainer) throws Exception {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
@@ -143,8 +140,8 @@ class MessageListenerContainerObservationTests {
|
||||
|
||||
static Stream<Arguments> listenerContainers() {
|
||||
return Stream.of(
|
||||
arguments(named(DefaultMessageListenerContainer.class.getSimpleName(), new DefaultMessageListenerContainer())),
|
||||
arguments(named(SimpleMessageListenerContainer.class.getSimpleName(), new SimpleMessageListenerContainer()))
|
||||
argumentSet(DefaultMessageListenerContainer.class.getSimpleName(), new DefaultMessageListenerContainer()),
|
||||
argumentSet(SimpleMessageListenerContainer.class.getSimpleName(), new SimpleMessageListenerContainer())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ import org.springframework.test.context.web.WebTestContextBootstrapper;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
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.mockito.Mockito.mock;
|
||||
import static org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper;
|
||||
import static org.springframework.test.context.NestedTestConfiguration.EnclosingConfiguration.INHERIT;
|
||||
@@ -105,7 +104,7 @@ class BootstrapUtilsTests {
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void resolveTestContextBootstrapperInEnclosingClassHierarchy(Class<?> testClass, Class<?> expectedBootstrapper) {
|
||||
assertBootstrapper(testClass, expectedBootstrapper);
|
||||
@@ -130,7 +129,7 @@ class BootstrapUtilsTests {
|
||||
}
|
||||
|
||||
private static Arguments args(Class<?> testClass, Class<? extends TestContextBootstrapper> expectedBootstrapper) {
|
||||
return arguments(named(testClass.getSimpleName(), testClass), expectedBootstrapper);
|
||||
return argumentSet(testClass.getSimpleName(), testClass, expectedBootstrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,12 +18,11 @@ package org.springframework.test.context.bean.override.mockito;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.FieldSource;
|
||||
import org.junit.platform.testkit.engine.EngineTestKit;
|
||||
import org.junit.platform.testkit.engine.Events;
|
||||
import org.mockito.Mockito;
|
||||
@@ -33,6 +32,7 @@ import org.mockito.quality.Strictness;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBeanForByNameLookupIntegrationTests.Config;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
|
||||
import static org.junit.platform.testkit.engine.EventConditions.event;
|
||||
import static org.junit.platform.testkit.engine.EventConditions.finishedWithFailure;
|
||||
@@ -50,7 +50,7 @@ import static org.junit.platform.testkit.engine.TestExecutionResultConditions.me
|
||||
class MockitoBeanSettingsStrictIntegrationTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("strictCases")
|
||||
@FieldSource("strictCases")
|
||||
void unusedStubbingIsReported(Class<?> forCase) {
|
||||
Events events = EngineTestKit.engine("junit-jupiter")
|
||||
.selectors(selectClass(forCase))
|
||||
@@ -65,12 +65,10 @@ class MockitoBeanSettingsStrictIntegrationTests {
|
||||
message(msg -> msg.contains("Unnecessary stubbings detected.")))));
|
||||
}
|
||||
|
||||
private static Stream<Named<Class<?>>> strictCases() {
|
||||
return Stream.of(
|
||||
Named.of("explicit strictness", ExplicitStrictness.class),
|
||||
Named.of("implicit strictness with @MockitoBean on field", ImplicitStrictnessWithMockitoBean.class)
|
||||
static final List<Arguments> strictCases = List.of(
|
||||
argumentSet("explicit strictness", ExplicitStrictness.class),
|
||||
argumentSet("implicit strictness with @MockitoBean on field", ImplicitStrictnessWithMockitoBean.class)
|
||||
);
|
||||
}
|
||||
|
||||
abstract static class BaseCase {
|
||||
|
||||
|
||||
@@ -30,8 +30,7 @@ import org.springframework.test.context.SmartContextLoader;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Unit test which verifies proper
|
||||
@@ -51,7 +50,7 @@ class GenericXmlContextLoaderResourceLocationsTests {
|
||||
private static final Log logger = LogFactory.getLog(GenericXmlContextLoaderResourceLocationsTests.class);
|
||||
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("contextConfigurationLocationsData")
|
||||
void assertContextConfigurationLocations(Class<?> testClass, String[] expectedLocations) {
|
||||
ContextConfiguration contextConfig = testClass.getAnnotation(ContextConfiguration.class);
|
||||
@@ -98,7 +97,7 @@ class GenericXmlContextLoaderResourceLocationsTests {
|
||||
}
|
||||
|
||||
private static Arguments args(Class<?> testClass, String[] expectedLocations) {
|
||||
return arguments(named(testClass.getSimpleName(), testClass), expectedLocations);
|
||||
return argumentSet(testClass.getSimpleName(), testClass, expectedLocations);
|
||||
}
|
||||
|
||||
private static String[] array(String... elements) {
|
||||
|
||||
@@ -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())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@ import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import org.eclipse.jetty.client.Request;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.api.Test;
|
||||
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;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -83,7 +83,7 @@ import org.springframework.web.reactive.function.client.WebClient.ResponseSpec;
|
||||
import org.springframework.web.testfixture.xml.Pojo;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
|
||||
/**
|
||||
* Integration tests using an {@link ExchangeFunction} through {@link WebClient}.
|
||||
@@ -99,17 +99,17 @@ class WebClientIntegrationTests {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("arguments")
|
||||
@interface ParameterizedWebClientTest {
|
||||
}
|
||||
|
||||
static Stream<Named<ClientHttpConnector>> arguments() {
|
||||
static Stream<Arguments> arguments() {
|
||||
return Stream.of(
|
||||
named("Reactor Netty", new ReactorClientHttpConnector()),
|
||||
named("JDK", new JdkClientHttpConnector()),
|
||||
named("Jetty", new JettyClientHttpConnector()),
|
||||
named("HttpComponents", new HttpComponentsClientHttpConnector())
|
||||
argumentSet("Reactor Netty", new ReactorClientHttpConnector()),
|
||||
argumentSet("JDK", new JdkClientHttpConnector()),
|
||||
argumentSet("Jetty", new JettyClientHttpConnector()),
|
||||
argumentSet("HttpComponents", new HttpComponentsClientHttpConnector())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ class ResourceWebHandlerTests {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("httpMethods")
|
||||
@MethodSource("org.springframework.http.HttpMethod#values()")
|
||||
void resourceNotFound(HttpMethod method) {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.method(method, "").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
@@ -223,10 +223,6 @@ class ResourceWebHandlerTests {
|
||||
StepVerifier.create(mono).consumeErrorWith(ex -> assertThat(ex).isNotSameAs(exceptionRef.get())).verify();
|
||||
}
|
||||
|
||||
static Stream<HttpMethod> httpMethods() {
|
||||
return Arrays.stream(HttpMethod.values());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -684,7 +680,7 @@ class ResourceWebHandlerTests {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("httpMethods")
|
||||
@MethodSource("org.springframework.http.HttpMethod#values()")
|
||||
void resolvePathWithTraversal(HttpMethod method) throws Exception {
|
||||
Resource location = new ClassPathResource("test/", getClass());
|
||||
this.handler.setLocations(List.of(location));
|
||||
|
||||
@@ -18,9 +18,9 @@ package org.springframework.web.reactive.result.method.annotation;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -34,7 +34,6 @@ import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.reactive.config.EnableWebFlux;
|
||||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
import org.springframework.web.testfixture.http.server.reactive.bootstrap.AbstractHttpServer;
|
||||
import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer;
|
||||
import org.springframework.web.testfixture.http.server.reactive.bootstrap.JettyCoreHttpServer;
|
||||
import org.springframework.web.testfixture.http.server.reactive.bootstrap.JettyHttpServer;
|
||||
import org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer;
|
||||
@@ -42,7 +41,7 @@ import org.springframework.web.testfixture.http.server.reactive.bootstrap.Tomcat
|
||||
import org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
|
||||
/**
|
||||
* Integration tests related to the use of context paths.
|
||||
@@ -51,17 +50,17 @@ import static org.junit.jupiter.api.Named.named;
|
||||
*/
|
||||
class ContextPathIntegrationTests {
|
||||
|
||||
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())
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("httpServers")
|
||||
void multipleWebFluxApps(AbstractHttpServer server) throws Exception {
|
||||
AnnotationConfigApplicationContext context1 = new AnnotationConfigApplicationContext(WebAppConfig.class);
|
||||
|
||||
@@ -24,11 +24,13 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.net.URI;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.tomcat.websocket.server.WsContextListener;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.xnio.OptionMap;
|
||||
@@ -69,6 +71,8 @@ import org.springframework.web.testfixture.http.server.reactive.bootstrap.Reacto
|
||||
import org.springframework.web.testfixture.http.server.reactive.bootstrap.TomcatHttpServer;
|
||||
import org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer;
|
||||
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
|
||||
/**
|
||||
* Base class for reactive WebSocket integration tests. Subclasses must implement
|
||||
* {@link #getWebConfigClass()} to return Spring config class with (server-side)
|
||||
@@ -84,34 +88,35 @@ abstract class AbstractReactiveWebSocketIntegrationTests {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@ParameterizedTest(name = "[{index}] client[{0}], server[{1}]")
|
||||
@ParameterizedTest(name = "[{index}] client = {0} , server = {1}")
|
||||
@MethodSource("arguments")
|
||||
@interface ParameterizedWebSocketTest {
|
||||
}
|
||||
|
||||
static Stream<Object[]> arguments() throws IOException {
|
||||
|
||||
WebSocketClient[] clients = new WebSocketClient[] {
|
||||
new TomcatWebSocketClient(),
|
||||
new JettyWebSocketClient(),
|
||||
new ReactorNettyWebSocketClient(),
|
||||
new UndertowWebSocketClient(Xnio.getInstance().createWorker(OptionMap.EMPTY))
|
||||
};
|
||||
List<Named<WebSocketClient>> clients = List.of(
|
||||
named(TomcatWebSocketClient.class.getSimpleName(), new TomcatWebSocketClient()),
|
||||
named(JettyWebSocketClient.class.getSimpleName(), new JettyWebSocketClient()),
|
||||
named(ReactorNettyWebSocketClient.class.getSimpleName(), new ReactorNettyWebSocketClient()),
|
||||
named(UndertowWebSocketClient.class.getSimpleName(), new UndertowWebSocketClient(Xnio.getInstance().createWorker(OptionMap.EMPTY)))
|
||||
);
|
||||
|
||||
Map<HttpServer, Class<?>> servers = new LinkedHashMap<>();
|
||||
servers.put(new TomcatHttpServer(TMP_DIR.getAbsolutePath(), WsContextListener.class), TomcatConfig.class);
|
||||
servers.put(new JettyHttpServer(), JettyConfig.class);
|
||||
servers.put(new JettyCoreHttpServer(), JettyCoreConfig.class);
|
||||
servers.put(new ReactorHttpServer(), ReactorNettyConfig.class);
|
||||
servers.put(new UndertowHttpServer(), UndertowConfig.class);
|
||||
Map<Named<HttpServer>, Class<?>> servers = new LinkedHashMap<>();
|
||||
servers.put(named(TomcatHttpServer.class.getSimpleName(), new TomcatHttpServer(TMP_DIR.getAbsolutePath(), WsContextListener.class)),
|
||||
TomcatConfig.class);
|
||||
servers.put(named(JettyHttpServer.class.getSimpleName(), new JettyHttpServer()), JettyConfig.class);
|
||||
servers.put(named(JettyCoreHttpServer.class.getSimpleName(), new JettyCoreHttpServer()), JettyCoreConfig.class);
|
||||
servers.put(named(ReactorHttpServer.class.getSimpleName(), new ReactorHttpServer()), ReactorNettyConfig.class);
|
||||
servers.put(named(UndertowHttpServer.class.getSimpleName(), new UndertowHttpServer()), UndertowConfig.class);
|
||||
|
||||
// Try each client once against each server
|
||||
|
||||
Flux<WebSocketClient> f1 = Flux.fromArray(clients)
|
||||
Flux<Named<WebSocketClient>> f1 = Flux.fromIterable(clients)
|
||||
.concatMap(c -> Mono.just(c).repeat(servers.size() - 1));
|
||||
|
||||
Flux<Map.Entry<HttpServer, Class<?>>> f2 = Flux.fromIterable(servers.entrySet())
|
||||
.repeat(clients.length - 1)
|
||||
Flux<Map.Entry<Named<HttpServer>, Class<?>>> f2 = Flux.fromIterable(servers.entrySet())
|
||||
.repeat(clients.size() - 1)
|
||||
.share();
|
||||
|
||||
return Flux.zip(f1, f2.map(Map.Entry::getKey), f2.map(Map.Entry::getValue))
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.junit.jupiter.api.Named;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -40,6 +41,7 @@ import org.springframework.web.util.ServletRequestPathUtils;
|
||||
import org.springframework.web.util.pattern.PathPatternParser;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -51,8 +53,11 @@ import static org.mockito.Mockito.mock;
|
||||
class CorsAbstractHandlerMappingTests {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static Stream<TestHandlerMapping> pathPatternsArguments() {
|
||||
return Stream.of(new TestHandlerMapping(new PathPatternParser()), new TestHandlerMapping());
|
||||
private static Stream<Named<TestHandlerMapping>> pathPatternsArguments() {
|
||||
return Stream.of(
|
||||
named("TestHandlerMapping with PathPatternParser", new TestHandlerMapping(new PathPatternParser())),
|
||||
named("TestHandlerMapping without PathPatternParser", new TestHandlerMapping())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -65,6 +65,7 @@ import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link RequestMappingInfoHandlerMapping}.
|
||||
@@ -86,11 +87,13 @@ class RequestMappingInfoHandlerMappingTests {
|
||||
TestRequestMappingInfoHandlerMapping mapping2 = new TestRequestMappingInfoHandlerMapping();
|
||||
mapping2.setUrlPathHelper(pathHelper);
|
||||
|
||||
return Stream.of(mapping1, mapping2).peek(mapping -> {
|
||||
mapping.setApplicationContext(new StaticWebApplicationContext());
|
||||
mapping.registerHandler(controller);
|
||||
mapping.afterPropertiesSet();
|
||||
});
|
||||
return Stream.of(named("defaults", mapping1), named("setRemoveSemicolonContent(false)", mapping2))
|
||||
.peek(named -> {
|
||||
TestRequestMappingInfoHandlerMapping mapping = named.getPayload();
|
||||
mapping.setApplicationContext(new StaticWebApplicationContext());
|
||||
mapping.registerHandler(controller);
|
||||
mapping.afterPropertiesSet();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -35,6 +36,7 @@ import org.springframework.web.util.pattern.PathPatternParser;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.GET;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.HEAD;
|
||||
|
||||
@@ -47,10 +49,13 @@ import static org.springframework.web.bind.annotation.RequestMethod.HEAD;
|
||||
class RequestMappingInfoTests {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
static Stream<RequestMappingInfo.Builder> pathPatternsArguments() {
|
||||
static Stream<Named<RequestMappingInfo.Builder>> pathPatternsArguments() {
|
||||
RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration();
|
||||
config.setPathMatcher(new AntPathMatcher());
|
||||
return Stream.of(RequestMappingInfo.paths(), RequestMappingInfo.paths().options(config));
|
||||
return Stream.of(
|
||||
named("PathPatternParser", RequestMappingInfo.paths()),
|
||||
named("AntPathMatcher", RequestMappingInfo.paths().options(config))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Named;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
@@ -58,6 +59,7 @@ import org.springframework.web.util.ServletRequestPathUtils;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
|
||||
/**
|
||||
* Tests for {@link CrossOrigin @CrossOrigin} annotated methods.
|
||||
@@ -70,7 +72,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
class CrossOriginTests {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
static Stream<TestRequestMappingInfoHandlerMapping> pathPatternsArguments() {
|
||||
static Stream<Named<TestRequestMappingInfoHandlerMapping>> pathPatternsArguments() {
|
||||
StaticWebApplicationContext wac = new StaticWebApplicationContext();
|
||||
Properties props = new Properties();
|
||||
props.setProperty("myOrigin", "https://example.com");
|
||||
@@ -87,7 +89,7 @@ class CrossOriginTests {
|
||||
wac.getAutowireCapableBeanFactory().initializeBean(mapping2, "mapping2");
|
||||
wac.close();
|
||||
|
||||
return Stream.of(mapping1, mapping2);
|
||||
return Stream.of(named("PathPatternParser", mapping1), named("AntPathMatcher", mapping2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ import org.springframework.web.util.pattern.PathPatternParser;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -83,7 +85,10 @@ class RequestMappingHandlerMappingTests {
|
||||
mapping2.setPatternParser(null);
|
||||
mapping2.setApplicationContext(wac2);
|
||||
|
||||
return Stream.of(Arguments.of(mapping1, wac1), Arguments.of(mapping2, wac2));
|
||||
return Stream.of(
|
||||
arguments(named("PathPatternParser", mapping1), wac1),
|
||||
arguments(named("AntPathMatcher", mapping2), wac2)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user