Fix RedisCommand.requiresArguments for zero argument length.

Closes #2646
Original Pull Request: #2647
This commit is contained in:
John Blum
2023-07-17 16:04:45 -07:00
committed by Christoph Strobl
parent 59a7266ff7
commit e5cec58a40
2 changed files with 24 additions and 3 deletions

View File

@@ -257,8 +257,8 @@ public enum RedisCommand {
private final boolean read;
private final boolean write;
private final int minArgs;
private final int maxArgs;
final int minArgs;
final int maxArgs;
private final @Nullable String alias;
@@ -313,7 +313,7 @@ public enum RedisCommand {
* @return {@literal true} if the command requires arguments
*/
public boolean requiresArguments() {
return minArgs >= 0;
return minArgs > 0;
}
/**

View File

@@ -17,6 +17,8 @@ package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
/**
@@ -117,4 +119,23 @@ class RedisCommandUnitTests {
}
}
}
@Test // GH-2646
void commandRequiresArgumentsIsCorrect() {
Arrays.stream(RedisCommand.values()).forEach(command ->
assertThat(command.requiresArguments())
.describedAs("Redis command [%s] failed required arguments check", command)
.isEqualTo(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));
}
}