mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 08:24:13 +00:00
Convert various test classes to @ParameterizedClass
See gh-35833
This commit is contained in:
+29
-17
@@ -20,8 +20,11 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.junit.jupiter.api.AutoClose;
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedClass;
|
||||
import org.junit.jupiter.params.provider.FieldSource;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -34,21 +37,38 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
|
||||
/**
|
||||
* Tests for annotation-based caching methods that use reactive operators.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 6.1
|
||||
*/
|
||||
@ParameterizedClass
|
||||
@FieldSource("configClasses")
|
||||
class CaffeineReactiveCachingTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(classes = {AsyncCacheModeConfig.class, AsyncCacheModeWithoutNullValuesConfig.class})
|
||||
void cacheHitDetermination(Class<?> configClass) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(configClass, ReactiveCacheableService.class);
|
||||
ReactiveCacheableService service = ctx.getBean(ReactiveCacheableService.class);
|
||||
static List<Named<Class<?>>> configClasses = List.of(
|
||||
named(AsyncCacheModeConfig.class.getSimpleName(), AsyncCacheModeConfig.class),
|
||||
named(AsyncCacheModeWithoutNullValuesConfig.class.getSimpleName(), AsyncCacheModeWithoutNullValuesConfig.class));
|
||||
|
||||
|
||||
@AutoClose
|
||||
private final AnnotationConfigApplicationContext ctx;
|
||||
|
||||
private final ReactiveCacheableService service;
|
||||
|
||||
|
||||
CaffeineReactiveCachingTests(Class<?> configClass) {
|
||||
this.ctx = new AnnotationConfigApplicationContext(configClass, ReactiveCacheableService.class);
|
||||
this.service = ctx.getBean(ReactiveCacheableService.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void cacheHitDetermination() {
|
||||
Object key = new Object();
|
||||
|
||||
Long r1 = service.cacheFuture(key).join();
|
||||
@@ -102,16 +122,10 @@ class CaffeineReactiveCachingTests {
|
||||
|
||||
assertThat(r1).isNotNull();
|
||||
assertThat(r1).isSameAs(r2).isSameAs(r3);
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(classes = {AsyncCacheModeConfig.class, AsyncCacheModeWithoutNullValuesConfig.class})
|
||||
void fluxCacheDoesntDependOnFirstRequest(Class<?> configClass) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(configClass, ReactiveCacheableService.class);
|
||||
ReactiveCacheableService service = ctx.getBean(ReactiveCacheableService.class);
|
||||
|
||||
@Test
|
||||
void fluxCacheDoesntDependOnFirstRequest() {
|
||||
Object key = new Object();
|
||||
|
||||
List<Long> l1 = service.cacheFlux(key).take(1L, true).collectList().block();
|
||||
@@ -123,8 +137,6 @@ class CaffeineReactiveCachingTests {
|
||||
assertThat(l1).as("l1").containsExactly(first);
|
||||
assertThat(l2).as("l2").containsExactly(first, 0L, -1L);
|
||||
assertThat(l3).as("l3").containsExactly(first, 0L, -1L, -2L, -3L);
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+13
-4
@@ -20,7 +20,9 @@ import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.Parameter;
|
||||
import org.junit.jupiter.params.ParameterizedClass;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@@ -45,14 +47,21 @@ import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@ParameterizedClass
|
||||
@MethodSource("contextConfigurationLocationsData")
|
||||
class GenericXmlContextLoaderResourceLocationsTests {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(GenericXmlContextLoaderResourceLocationsTests.class);
|
||||
|
||||
@Parameter(0)
|
||||
Class<?> testClass;
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("contextConfigurationLocationsData")
|
||||
void assertContextConfigurationLocations(Class<?> testClass, String[] expectedLocations) {
|
||||
@Parameter(1)
|
||||
String[] expectedLocations;
|
||||
|
||||
|
||||
@Test
|
||||
void assertContextConfigurationLocations() {
|
||||
ContextConfiguration contextConfig = testClass.getAnnotation(ContextConfiguration.class);
|
||||
String[] configuredLocations = contextConfig.value();
|
||||
ContextConfigurationAttributes configAttributes =
|
||||
|
||||
+8
-7
@@ -18,7 +18,8 @@ package org.springframework.test.context.testng;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedClass;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.testng.TestNG;
|
||||
@@ -48,13 +49,13 @@ import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
class FailingBeforeAndAfterMethodsTestNGTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("testData")
|
||||
void runTestAndAssertCounters(Class<?> clazz, int expectedTestStartCount,
|
||||
int expectedTestSuccessCount, int expectedFailureCount, int expectedFailedConfigurationsCount) throws Exception {
|
||||
@ParameterizedClass
|
||||
@MethodSource("testData")
|
||||
record FailingBeforeAndAfterMethodsTestNGTests(Class<?> clazz, int expectedTestStartCount,
|
||||
int expectedTestSuccessCount, int expectedFailureCount, int expectedFailedConfigurationsCount) {
|
||||
|
||||
@Test
|
||||
void runTestAndAssertCounters() {
|
||||
TrackingTestNGTestListener listener = new TrackingTestNGTestListener();
|
||||
TestNG testNG = new TestNG();
|
||||
testNG.addListener(listener);
|
||||
|
||||
+10
-18
@@ -17,17 +17,14 @@
|
||||
package org.springframework.test.web.servlet.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import mockwebserver3.MockResponse;
|
||||
import mockwebserver3.MockWebServer;
|
||||
import org.junit.jupiter.api.AutoClose;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedClass;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@@ -43,15 +40,10 @@ import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
/**
|
||||
* Integration tests for {@link RestTestClient} against a live server.
|
||||
*/
|
||||
@ParameterizedClass
|
||||
@MethodSource("clientHttpRequestFactories")
|
||||
class RestTestClientIntegrationTests {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@ParameterizedTest
|
||||
@MethodSource("clientHttpRequestFactories")
|
||||
@interface ParameterizedRestClientTest {
|
||||
}
|
||||
|
||||
static Stream<Arguments> clientHttpRequestFactories() {
|
||||
return Stream.of(
|
||||
argumentSet("JDK HttpURLConnection", new SimpleClientHttpRequestFactory()),
|
||||
@@ -62,22 +54,22 @@ class RestTestClientIntegrationTests {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@AutoClose
|
||||
private MockWebServer server = new MockWebServer();
|
||||
private final MockWebServer server = new MockWebServer();
|
||||
|
||||
private RestTestClient testClient;
|
||||
private final RestTestClient testClient;
|
||||
|
||||
|
||||
private void startServer(ClientHttpRequestFactory requestFactory) throws IOException {
|
||||
RestTestClientIntegrationTests(ClientHttpRequestFactory requestFactory) throws IOException {
|
||||
this.server.start();
|
||||
this.testClient = RestTestClient.bindToServer(requestFactory)
|
||||
.baseUrl(this.server.url("/").toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
@ParameterizedRestClientTest // gh-35784
|
||||
void sequentialRequestsNotConsumingBody(ClientHttpRequestFactory requestFactory) throws IOException {
|
||||
startServer(requestFactory);
|
||||
@Test // gh-35784
|
||||
void sequentialRequestsNotConsumingBody() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
prepareResponse(builder ->
|
||||
builder.setHeader("Content-Type", "text/plain").body("Hello Spring!"));
|
||||
|
||||
Reference in New Issue
Block a user