Skip to content

Commit 862e344

Browse files
Use reflection to access internal value in tests.
Original Pull Request: #2647
1 parent e5cec58 commit 862e344

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/main/java/org/springframework/data/redis/core/RedisCommand.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ public static RedisCommand failsafeCommandLookup(String key) {
257257
private final boolean read;
258258
private final boolean write;
259259

260-
final int minArgs;
261-
final int maxArgs;
260+
private final int minArgs;
261+
private final int maxArgs;
262262

263263
private final @Nullable String alias;
264264

src/test/java/org/springframework/data/redis/core/RedisCommandUnitTests.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Arrays;
2121

2222
import org.junit.jupiter.api.Test;
23+
import org.springframework.test.util.ReflectionTestUtils;
2324

2425
/**
2526
* Unit tests for {@link RedisCommand}.
@@ -123,19 +124,19 @@ void isRepresentedByIsCorrectForAllCommandsAndTheirAliases() {
123124
@Test // GH-2646
124125
void commandRequiresArgumentsIsCorrect() {
125126

126-
Arrays.stream(RedisCommand.values()).forEach(command ->
127-
assertThat(command.requiresArguments())
127+
Arrays.stream(RedisCommand.values())
128+
.forEach(command -> assertThat(command.requiresArguments())
128129
.describedAs("Redis command [%s] failed required arguments check", command)
129-
.isEqualTo(command.minArgs > 0));
130+
.isEqualTo((int) ReflectionTestUtils.getField(command, "minArgs") > 0));
130131
}
131132

132133
@Test // GH-2646
133134
void commandRequiresExactNumberOfArgumentsIsCorrect() {
134135

135-
Arrays.stream(RedisCommand.values()).forEach(command ->
136-
assertThat(command.requiresExactNumberOfArguments())
137-
.describedAs("Redis command [%s] failed requires exact arguments check")
138-
.isEqualTo(command.minArgs == command.maxArgs));
136+
Arrays.stream(RedisCommand.values())
137+
.forEach(command -> assertThat(command.requiresExactNumberOfArguments())
138+
.describedAs("Redis command [%s] failed requires exact arguments check").isEqualTo(
139+
ReflectionTestUtils.getField(command, "minArgs") == ReflectionTestUtils.getField(command, "maxArgs")));
139140
}
140141

141142
}

0 commit comments

Comments
 (0)