Use reflection to access internal value in tests.

Original Pull Request: #2647
This commit is contained in:
Christoph Strobl
2023-07-25 12:13:47 +02:00
parent e5cec58a40
commit 862e3446bc
2 changed files with 10 additions and 9 deletions

View File

@@ -257,8 +257,8 @@ public enum RedisCommand {
private final boolean read;
private final boolean write;
final int minArgs;
final int maxArgs;
private final int minArgs;
private final int maxArgs;
private final @Nullable String alias;

View File

@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
/**
* Unit tests for {@link RedisCommand}.
@@ -123,19 +124,19 @@ class RedisCommandUnitTests {
@Test // GH-2646
void commandRequiresArgumentsIsCorrect() {
Arrays.stream(RedisCommand.values()).forEach(command ->
assertThat(command.requiresArguments())
Arrays.stream(RedisCommand.values())
.forEach(command -> assertThat(command.requiresArguments())
.describedAs("Redis command [%s] failed required arguments check", command)
.isEqualTo(command.minArgs > 0));
.isEqualTo((int) ReflectionTestUtils.getField(command, "minArgs") > 0));
}
@Test // GH-2646
void commandRequiresExactNumberOfArgumentsIsCorrect() {
Arrays.stream(RedisCommand.values()).forEach(command ->
assertThat(command.requiresExactNumberOfArguments())
.describedAs("Redis command [%s] failed requires exact arguments check")
.isEqualTo(command.minArgs == command.maxArgs));
Arrays.stream(RedisCommand.values())
.forEach(command -> assertThat(command.requiresExactNumberOfArguments())
.describedAs("Redis command [%s] failed requires exact arguments check").isEqualTo(
ReflectionTestUtils.getField(command, "minArgs") == ReflectionTestUtils.getField(command, "maxArgs")));
}
}