Skip to content

Commit c863f9b

Browse files
committed
Rename RedisAssertions.requiredObject(..) to requireNonNull(..).
Closes #2621
1 parent b8e6851 commit c863f9b

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

Diff for: src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration d
178178
private RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
179179
boolean allowRuntimeCacheCreation) {
180180

181-
this.defaultCacheConfiguration = RedisAssertions.requireObject(defaultCacheConfiguration,
181+
this.defaultCacheConfiguration = RedisAssertions.requireNonNull(defaultCacheConfiguration,
182182
"DefaultCacheConfiguration must not be null");
183183

184-
this.cacheWriter = RedisAssertions.requireObject(cacheWriter, "CacheWriter must not be null");
184+
this.cacheWriter = RedisAssertions.requireNonNull(cacheWriter, "CacheWriter must not be null");
185185
this.initialCacheConfiguration = new LinkedHashMap<>();
186186
this.allowRuntimeCacheCreation = allowRuntimeCacheCreation;
187187
}
@@ -410,7 +410,7 @@ public static class RedisCacheManagerBuilder {
410410
* @see org.springframework.data.redis.cache.RedisCacheWriter
411411
*/
412412
public static RedisCacheManagerBuilder fromCacheWriter(RedisCacheWriter cacheWriter) {
413-
return new RedisCacheManagerBuilder(RedisAssertions.requireObject(cacheWriter,
413+
return new RedisCacheManagerBuilder(RedisAssertions.requireNonNull(cacheWriter,
414414
"CacheWriter must not be null"));
415415
}
416416

@@ -427,7 +427,7 @@ public static RedisCacheManagerBuilder fromCacheWriter(RedisCacheWriter cacheWri
427427
public static RedisCacheManagerBuilder fromConnectionFactory(RedisConnectionFactory connectionFactory) {
428428

429429
RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(
430-
RedisAssertions.requireObject(connectionFactory, "ConnectionFactory must not be null"));
430+
RedisAssertions.requireNonNull(connectionFactory, "ConnectionFactory must not be null"));
431431

432432
return new RedisCacheManagerBuilder(cacheWriter);
433433
}
@@ -506,7 +506,7 @@ public RedisCacheConfiguration cacheDefaults() {
506506
*/
507507
public RedisCacheManagerBuilder cacheDefaults(RedisCacheConfiguration defaultCacheConfiguration) {
508508

509-
this.defaultCacheConfiguration = RedisAssertions.requireObject(defaultCacheConfiguration,
509+
this.defaultCacheConfiguration = RedisAssertions.requireNonNull(defaultCacheConfiguration,
510510
"DefaultCacheConfiguration must not be null");
511511

512512
return this;
@@ -520,7 +520,7 @@ public RedisCacheManagerBuilder cacheDefaults(RedisCacheConfiguration defaultCac
520520
* @since 2.3
521521
*/
522522
public RedisCacheManagerBuilder cacheWriter(RedisCacheWriter cacheWriter) {
523-
this.cacheWriter = RedisAssertions.requireObject(cacheWriter, "CacheWriter must not be null");
523+
this.cacheWriter = RedisAssertions.requireNonNull(cacheWriter, "CacheWriter must not be null");
524524
return this;
525525
}
526526

@@ -544,7 +544,7 @@ public RedisCacheManagerBuilder enableStatistics() {
544544
*/
545545
public RedisCacheManagerBuilder initialCacheNames(Set<String> cacheNames) {
546546

547-
RedisAssertions.requireObject(cacheNames, "CacheNames must not be null")
547+
RedisAssertions.requireNonNull(cacheNames, "CacheNames must not be null")
548548
.forEach(it -> withCacheConfiguration(it, defaultCacheConfiguration));
549549

550550
return this;
@@ -589,8 +589,8 @@ public RedisCacheManagerBuilder withCacheConfiguration(String cacheName,
589589
public RedisCacheManagerBuilder withInitialCacheConfigurations(
590590
Map<String, RedisCacheConfiguration> cacheConfigurations) {
591591

592-
RedisAssertions.requireObject(cacheConfigurations, "CacheConfigurations must not be null")
593-
.forEach((cacheName, cacheConfiguration) -> RedisAssertions.requireObject(cacheConfiguration,
592+
RedisAssertions.requireNonNull(cacheConfigurations, "CacheConfigurations must not be null")
593+
.forEach((cacheName, cacheConfiguration) -> RedisAssertions.requireNonNull(cacheConfiguration,
594594
"RedisCacheConfiguration for cache [%s] must not be null", cacheName));
595595

596596
this.initialCaches.putAll(cacheConfigurations);

Diff for: src/main/java/org/springframework/data/redis/connection/RedisClusterNode.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public RedisClusterNode(String id) {
7676

7777
this(SlotRange.empty());
7878

79-
this.id = RedisAssertions.requireObject(id, "Id must not be null");
79+
this.id = RedisAssertions.requireNonNull(id, "Id must not be null");
8080
}
8181

8282
/**
@@ -87,7 +87,7 @@ public RedisClusterNode(String id) {
8787
public RedisClusterNode(SlotRange slotRange) {
8888

8989
this.flags = Collections.emptySet();
90-
this.slotRange = RedisAssertions.requireObject(slotRange,"SlotRange must not be null");
90+
this.slotRange = RedisAssertions.requireNonNull(slotRange,"SlotRange must not be null");
9191
}
9292

9393
/**
@@ -102,7 +102,7 @@ public RedisClusterNode(String host, int port, SlotRange slotRange) {
102102
super(host, port);
103103

104104
this.flags = Collections.emptySet();
105-
this.slotRange = RedisAssertions.requireObject(slotRange,"SlotRange must not be null");
105+
this.slotRange = RedisAssertions.requireNonNull(slotRange,"SlotRange must not be null");
106106
}
107107

108108
/**

Diff for: src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ public GenericJackson2JsonRedisSerializer(ObjectMapper mapper, JacksonObjectRead
180180
private GenericJackson2JsonRedisSerializer(ObjectMapper mapper, JacksonObjectReader reader,
181181
JacksonObjectWriter writer, @Nullable String typeHintPropertyName) {
182182

183-
this.mapper = RedisAssertions.requireObject(mapper, "ObjectMapper must not be null");
184-
this.reader = RedisAssertions.requireObject(reader, "Reader must not be null");
185-
this.writer = RedisAssertions.requireObject(writer, "Writer must not be null");
183+
this.mapper = RedisAssertions.requireNonNull(mapper, "ObjectMapper must not be null");
184+
this.reader = RedisAssertions.requireNonNull(reader, "Reader must not be null");
185+
this.writer = RedisAssertions.requireNonNull(writer, "Writer must not be null");
186186

187187
this.defaultTypingEnabled = Lazy.of(() -> mapper.getSerializationConfig()
188188
.getDefaultTyper(null) != null);

Diff for: src/main/java/org/springframework/data/redis/serializer/JdkSerializationRedisSerializer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public JdkSerializationRedisSerializer(@Nullable ClassLoader classLoader) {
7777
public JdkSerializationRedisSerializer(Converter<Object, byte[]> serializer,
7878
Converter<byte[], Object> deserializer) {
7979

80-
this.serializer = RedisAssertions.requireObject(serializer, "Serializer must not be null");
81-
this.deserializer = RedisAssertions.requireObject(deserializer, "Deserializer must not be null");
80+
this.serializer = RedisAssertions.requireNonNull(serializer, "Serializer must not be null");
81+
this.deserializer = RedisAssertions.requireNonNull(deserializer, "Deserializer must not be null");
8282
}
8383

8484
@Override

Diff for: src/main/java/org/springframework/data/redis/util/RedisAssertions.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public abstract class RedisAssertions {
3737
* @param arguments array of {@link Object} arguments used to format the {@link String message}.
3838
* @return the given {@link Object}.
3939
* @throws IllegalArgumentException if the {@link Object target} is {@literal null}.
40-
* @see #requireObject(Object, Supplier)
40+
* @see #requireNonNull(Object, Supplier)
4141
*/
42-
public static <T> T requireObject(@Nullable T target, String message, Object... arguments) {
43-
return requireObject(target, () -> String.format(message, arguments));
42+
public static <T> T requireNonNull(@Nullable T target, String message, Object... arguments) {
43+
return requireNonNull(target, () -> String.format(message, arguments));
4444
}
4545

4646
/**
@@ -52,7 +52,7 @@ public static <T> T requireObject(@Nullable T target, String message, Object...
5252
* @return the given {@link Object}.
5353
* @throws IllegalArgumentException if the {@link Object target} is {@literal null}.
5454
*/
55-
public static <T> T requireObject(@Nullable T target, Supplier<String> message) {
55+
public static <T> T requireNonNull(@Nullable T target, Supplier<String> message) {
5656
Assert.notNull(target, message);
5757
return target;
5858
}
@@ -66,7 +66,7 @@ public static <T> T requireObject(@Nullable T target, Supplier<String> message)
6666
* @param arguments array of {@link Object} arguments used to format the {@link String message}.
6767
* @return the given {@link Object}.
6868
* @throws IllegalArgumentException if the {@link Object target} is {@literal null}.
69-
* @see #requireObject(Object, Supplier)
69+
* @see #requireNonNull(Object, Supplier)
7070
*/
7171
public static <T> T requireState(@Nullable T target, String message, Object... arguments) {
7272
return requireState(target, () -> String.format(message, arguments));

Diff for: src/test/java/org/springframework/data/redis/util/RedisAssertionsUnitTests.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.mockito.junit.jupiter.MockitoExtension;
3333

3434
/**
35-
* Unit tests for {@link RedisAssertions}.
35+
* Unit Tests for {@link RedisAssertions}.
3636
*
3737
* @author John Blum
3838
*/
@@ -43,34 +43,34 @@ class RedisAssertionsUnitTests {
4343
private Supplier<String> mockSupplier;
4444

4545
@Test
46-
void requireObjectWithMessageAndArgumentsIsSuccessful() {
47-
assertThat(RedisAssertions.requireObject("test", "Test message")).isEqualTo("test");
46+
void requireNonNullWithMessageAndArgumentsIsSuccessful() {
47+
assertThat(RedisAssertions.requireNonNull("test", "Test message")).isEqualTo("test");
4848
}
4949

5050
@Test
51-
void requireObjectWithMessageAndArgumentsThrowsIllegalArgumentException() {
51+
void requireNonNullWithMessageAndArgumentsThrowsIllegalArgumentException() {
5252

5353
assertThatIllegalArgumentException()
54-
.isThrownBy(() -> RedisAssertions.requireObject(null, "This is a %s", "test"))
54+
.isThrownBy(() -> RedisAssertions.requireNonNull(null, "This is a %s", "test"))
5555
.withMessage("This is a test")
5656
.withNoCause();
5757
}
5858

5959
@Test
60-
void requireObjectWithSupplierIsSuccessful() {
60+
void requireNonNullWithSupplierIsSuccessful() {
6161

62-
assertThat(RedisAssertions.requireObject("mock", this.mockSupplier)).isEqualTo("mock");
62+
assertThat(RedisAssertions.requireNonNull("mock", this.mockSupplier)).isEqualTo("mock");
6363

6464
verifyNoInteractions(this.mockSupplier);
6565
}
6666

6767
@Test
68-
void requireObjectWithSupplierThrowsIllegalArgumentException() {
68+
void requireNonNullWithSupplierThrowsIllegalArgumentException() {
6969

7070
doReturn("Mock message").when(this.mockSupplier).get();
7171

7272
assertThatIllegalArgumentException()
73-
.isThrownBy(() -> RedisAssertions.requireObject(null, this.mockSupplier))
73+
.isThrownBy(() -> RedisAssertions.requireNonNull(null, this.mockSupplier))
7474
.withMessage("Mock message")
7575
.withNoCause();
7676

0 commit comments

Comments
 (0)