Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-GH-2646-SNAPSHOT</version>

<name>Spring Data Redis</name>
<description>Spring Data module for Redis</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ public enum RedisCommand {
private boolean write = true;
private Set<String> alias = new HashSet<>(1);

private int minArgs = -1;
private int maxArgs = -1;
final int minArgs;
final int maxArgs;

private final static Map<String, RedisCommand> commandLookup;

Expand Down Expand Up @@ -281,7 +281,7 @@ private static Map<String, RedisCommand> buildCommandLookupTable() {
* @return {@literal true} if the command requires arguments
*/
public boolean requiresArguments() {
return minArgs >= 0;
return minArgs > 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/
package org.springframework.data.redis.core;

import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

import java.util.Arrays;

import org.junit.jupiter.api.Test;

Expand All @@ -26,6 +29,7 @@
* @author Thomas Darimont
* @author Mark Paluch
* @author Oscar Cai
* @author John Blum
*/
class RedisCommandUnitTests {

Expand Down Expand Up @@ -101,4 +105,22 @@ void shouldThrowExceptionOnInvalidArgumentCountForZaddWhenExpectedMinimalMatch()
assertThatIllegalArgumentException().isThrownBy(() -> RedisCommand.ZADD.validateArgumentCount(2))
.withMessageContaining("ZADD command requires at least 3 arguments");
}

@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));
}
}