Skip to content

Commit feeda02

Browse files
committed
Polishing.
Use parametrized tests for Command enum verification. See #3191 Original pull request: #3193
1 parent 528c76d commit feeda02

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20-
import java.util.Arrays;
21-
2220
import org.junit.jupiter.api.Test;
21+
import org.junit.jupiter.params.ParameterizedTest;
22+
import org.junit.jupiter.params.provider.EnumSource;
23+
2324
import org.springframework.test.util.ReflectionTestUtils;
2425

2526
/**
@@ -106,37 +107,34 @@ void shouldThrowExceptionOnInvalidArgumentCountForZaddWhenExpectedMinimalMatch()
106107
.withMessageContaining("ZADD command requires at least 3 arguments");
107108
}
108109

109-
@Test // GH-2644
110-
void isRepresentedByIsCorrectForAllCommandsAndTheirAliases() {
111-
112-
for (RedisCommand command : RedisCommand.values()) {
110+
@ParameterizedTest(name = "{0}") // GH-2644
111+
@EnumSource(RedisCommand.class)
112+
void isRepresentedByIsCorrectForAllCommandsAndTheirAliases(RedisCommand command) {
113113

114-
assertThat(command.isRepresentedBy(command.name())).isTrue();
115-
assertThat(command.isRepresentedBy(command.name().toLowerCase())).isTrue();
114+
assertThat(command.isRepresentedBy(command.name())).isTrue();
115+
assertThat(command.isRepresentedBy(command.name().toLowerCase())).isTrue();
116116

117-
for (String alias : command.getAliases()) {
118-
assertThat(command.isRepresentedBy(alias)).isTrue();
119-
assertThat(command.isRepresentedBy(alias.toUpperCase())).isTrue();
120-
}
117+
for (String alias : command.getAliases()) {
118+
assertThat(command.isRepresentedBy(alias)).isTrue();
119+
assertThat(command.isRepresentedBy(alias.toUpperCase())).isTrue();
121120
}
122121
}
123122

124-
@Test // GH-2646
125-
void commandRequiresArgumentsIsCorrect() {
123+
@ParameterizedTest(name = "{0}") // GH-2646
124+
@EnumSource(RedisCommand.class)
125+
void commandRequiresArgumentsIsCorrect(RedisCommand command) {
126126

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

133-
@Test // GH-2646
134-
void commandRequiresExactNumberOfArgumentsIsCorrect() {
131+
@ParameterizedTest(name = "{0}") // GH-2646
132+
@EnumSource(RedisCommand.class)
133+
void commandRequiresExactNumberOfArgumentsIsCorrect(RedisCommand command) {
135134

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

142140
}

0 commit comments

Comments
 (0)