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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user