Polishing.
Additionally, applied Java 17 syntax, cleaned up compiler warnings, and edited Javadoc. Closes #2644 Original pull request: #2640
This commit is contained in:
@@ -31,6 +31,7 @@ import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Mark Paluch
|
||||
* @author John Blum
|
||||
*/
|
||||
public abstract class SettingsUtils {
|
||||
|
||||
@@ -66,14 +67,14 @@ public abstract class SettingsUtils {
|
||||
* @return the Redis port.
|
||||
*/
|
||||
public static int getPort() {
|
||||
return Integer.valueOf(SETTINGS.getProperty("port"));
|
||||
return Integer.parseInt(SETTINGS.getProperty("port"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Redis Cluster port.
|
||||
*/
|
||||
public static int getSentinelPort() {
|
||||
return Integer.valueOf(SETTINGS.getProperty("sentinelPort"));
|
||||
return Integer.parseInt(SETTINGS.getProperty("sentinelPort"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +88,7 @@ public abstract class SettingsUtils {
|
||||
* @return the Redis Cluster port.
|
||||
*/
|
||||
public static int getClusterPort() {
|
||||
return Integer.valueOf(SETTINGS.getProperty("clusterPort"));
|
||||
return Integer.parseInt(SETTINGS.getProperty("clusterPort"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,13 +55,16 @@ import org.springframework.data.redis.test.extension.parametrized.ParameterizedR
|
||||
public class LegacyRedisCacheTests {
|
||||
|
||||
private static final String CACHE_NAME = "testCache";
|
||||
private ObjectFactory<Object> keyFactory;
|
||||
private ObjectFactory<Object> valueFactory;
|
||||
private RedisConnectionFactory connectionFactory;
|
||||
|
||||
private final boolean allowCacheNullValues;
|
||||
|
||||
private ObjectFactory<Object> keyFactory;
|
||||
private ObjectFactory<Object> valueFactory;
|
||||
|
||||
private RedisCache cache;
|
||||
|
||||
private RedisConnectionFactory connectionFactory;
|
||||
|
||||
public LegacyRedisCacheTests(RedisTemplate template, ObjectFactory<Object> keyFactory,
|
||||
ObjectFactory<Object> valueFactory, boolean allowCacheNullValues) {
|
||||
|
||||
@@ -69,8 +72,7 @@ public class LegacyRedisCacheTests {
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
this.allowCacheNullValues = allowCacheNullValues;
|
||||
|
||||
cache = createCache();
|
||||
this.cache = createCache();
|
||||
}
|
||||
|
||||
public static Collection<Object[]> testParams() {
|
||||
@@ -93,11 +95,11 @@ public class LegacyRedisCacheTests {
|
||||
return target;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private RedisCache createCache() {
|
||||
|
||||
RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
|
||||
.entryTtl(Duration.ofSeconds(10));
|
||||
|
||||
if (!allowCacheNullValues) {
|
||||
cacheConfiguration = cacheConfiguration.disableCachingNullValues();
|
||||
}
|
||||
@@ -116,6 +118,7 @@ public class LegacyRedisCacheTests {
|
||||
|
||||
@ParameterizedRedisTest
|
||||
void testCachePut() {
|
||||
|
||||
Object key = getKey();
|
||||
Object value = getValue();
|
||||
|
||||
@@ -130,6 +133,7 @@ public class LegacyRedisCacheTests {
|
||||
|
||||
@ParameterizedRedisTest
|
||||
void testCacheClear() {
|
||||
|
||||
Object key1 = getKey();
|
||||
Object value1 = getValue();
|
||||
|
||||
@@ -382,7 +386,7 @@ public class LegacyRedisCacheTests {
|
||||
|
||||
this.redisCache = redisCache;
|
||||
|
||||
cacheLoader = new TestCacheLoader<String>("test") {
|
||||
cacheLoader = new TestCacheLoader<>("test") {
|
||||
|
||||
@Override
|
||||
public String call() {
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test;
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
* @author Oscar Cai
|
||||
* @author John Blum
|
||||
*/
|
||||
class RedisCommandUnitTests {
|
||||
|
||||
@@ -101,4 +102,19 @@ class RedisCommandUnitTests {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> RedisCommand.ZADD.validateArgumentCount(2))
|
||||
.withMessageContaining("ZADD command requires at least 3 arguments");
|
||||
}
|
||||
|
||||
@Test // GH-2644
|
||||
void isRepresentedByIsCorrectForAllCommandsAndTheirAliases() {
|
||||
|
||||
for (RedisCommand command : RedisCommand.values()) {
|
||||
|
||||
assertThat(command.isRepresentedBy(command.name())).isTrue();
|
||||
assertThat(command.isRepresentedBy(command.name().toLowerCase())).isTrue();
|
||||
|
||||
for (String alias : command.getAliases()) {
|
||||
assertThat(command.isRepresentedBy(alias)).isTrue();
|
||||
assertThat(command.isRepresentedBy(alias.toUpperCase())).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.springframework.data.redis.ConnectionFactoryTracker.Managed;
|
||||
class MethodArgumentsProvider implements ArgumentsProvider, AnnotationConsumer<MethodSource> {
|
||||
|
||||
private static final Namespace NAMESPACE = Namespace.create(MethodArgumentsProvider.class);
|
||||
|
||||
private String[] methodNames = new String[0];
|
||||
|
||||
@Override
|
||||
@@ -55,6 +56,7 @@ class MethodArgumentsProvider implements ArgumentsProvider, AnnotationConsumer<M
|
||||
|
||||
Store store = context.getRoot().getStore(NAMESPACE);
|
||||
Object testInstance = context.getTestInstance().orElse(null);
|
||||
|
||||
return Arrays.stream(this.methodNames).map(factoryMethodName -> getMethod(context, factoryMethodName))
|
||||
.map(method -> (CloseablePararmeters) store.getOrComputeIfAbsent(new SourceKey(method, testInstance),
|
||||
key -> new CloseablePararmeters(ReflectionUtils.invokeMethod(method, testInstance), context)))
|
||||
@@ -63,6 +65,7 @@ class MethodArgumentsProvider implements ArgumentsProvider, AnnotationConsumer<M
|
||||
}
|
||||
|
||||
private Method getMethod(ExtensionContext context, String factoryMethodName) {
|
||||
|
||||
if (StringUtils.isNotBlank(factoryMethodName)) {
|
||||
if (factoryMethodName.contains("#")) {
|
||||
return getMethodByFullyQualifiedName(factoryMethodName);
|
||||
@@ -74,6 +77,7 @@ class MethodArgumentsProvider implements ArgumentsProvider, AnnotationConsumer<M
|
||||
}
|
||||
|
||||
private Method getMethodByFullyQualifiedName(String fullyQualifiedMethodName) {
|
||||
|
||||
String[] methodParts = ReflectionUtils.parseFullyQualifiedMethodName(fullyQualifiedMethodName);
|
||||
String className = methodParts[0];
|
||||
String methodName = methodParts[1];
|
||||
@@ -93,8 +97,8 @@ class MethodArgumentsProvider implements ArgumentsProvider, AnnotationConsumer<M
|
||||
private static Arguments toArguments(Object item) {
|
||||
|
||||
// Nothing to do except cast.
|
||||
if (item instanceof Arguments) {
|
||||
return (Arguments) item;
|
||||
if (item instanceof Arguments arguments) {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
// Pass all multidimensional arrays "as is", in contrast to Object[].
|
||||
@@ -105,8 +109,8 @@ class MethodArgumentsProvider implements ArgumentsProvider, AnnotationConsumer<M
|
||||
|
||||
// Special treatment for one-dimensional reference arrays.
|
||||
// See https://github.com/junit-team/junit5/issues/1665
|
||||
if (item instanceof Object[]) {
|
||||
return arguments((Object[]) item);
|
||||
if (item instanceof Object[] array) {
|
||||
return arguments(array);
|
||||
}
|
||||
|
||||
// Pass everything else "as is".
|
||||
@@ -136,41 +140,40 @@ class MethodArgumentsProvider implements ArgumentsProvider, AnnotationConsumer<M
|
||||
}
|
||||
|
||||
private void close0(Object object) {
|
||||
|
||||
if (object instanceof Managed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (object instanceof CloseableResource) {
|
||||
if (object instanceof CloseableResource closeableResource) {
|
||||
try {
|
||||
((CloseableResource) object).close();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
closeableResource.close();
|
||||
return;
|
||||
} catch (Throwable cause) {
|
||||
throw new RuntimeException(cause);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (object instanceof Closeable) {
|
||||
if (object instanceof Closeable closeable) {
|
||||
try {
|
||||
((AutoCloseable) object).close();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
closeable.close();
|
||||
return;
|
||||
} catch (Throwable cause) {
|
||||
throw new RuntimeException(cause);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (object instanceof Arguments) {
|
||||
close0(((Arguments) object).get());
|
||||
if (object instanceof Arguments arguments) {
|
||||
close0(arguments.get());
|
||||
}
|
||||
|
||||
if (object instanceof Object[]) {
|
||||
Arrays.asList((Object[]) object).forEach(this::close0);
|
||||
if (object instanceof Object[] array) {
|
||||
Arrays.asList(array).forEach(this::close0);
|
||||
}
|
||||
|
||||
if (object instanceof Iterable<?>) {
|
||||
((Iterable<Object>) object).forEach(this::close0);
|
||||
if (object instanceof Iterable<?> iterableObject) {
|
||||
iterableObject.forEach(this::close0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user