DATAREDIS-972 - Fix validation for RedisCommand argument count.

Original pull request: #448.
This commit is contained in:
Oscar Cai
2019-04-17 16:29:37 +02:00
committed by Mark Paluch
parent 31faea6cc0
commit f58bf08c15
2 changed files with 9 additions and 6 deletions

View File

@@ -348,7 +348,7 @@ public enum RedisCommand {
String.format("%s command requires at least %s arguments.", this.name(), this.minArgs));
}
if (maxArgs != 0 && nrArguments > maxArgs) {
if (maxArgs > 0 && nrArguments > maxArgs) {
throw new IllegalArgumentException(
String.format("%s command requires at most %s arguments.", this.name(), this.maxArgs));
}

View File

@@ -66,11 +66,14 @@ public class RedisCommandUnitTests {
@Test // DATAREDIS-73
public void shouldNotThrowExceptionOnValidArgumentCount() {
RedisCommand.AUTH.validateArgumentCount(1);
RedisCommand.ZADD.validateArgumentCount(3); // DATAREDIS-972
RedisCommand.ZADD.validateArgumentCount(4); // DATAREDIS-972
RedisCommand.ZADD.validateArgumentCount(5); // DATAREDIS-972
RedisCommand.ZADD.validateArgumentCount(100); // DATAREDIS-972
}
@Test // DATAREDIS-822
public void shouldConsiderMinMaxArguments() {
RedisCommand.BITPOS.validateArgumentCount(2);
RedisCommand.BITPOS.validateArgumentCount(3);
RedisCommand.BITPOS.validateArgumentCount(4);
@@ -78,16 +81,13 @@ public class RedisCommandUnitTests {
@Test // DATAREDIS-822
public void shouldReportArgumentMismatchIfMaxArgumentsExceeded() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("BITPOS command requires at most 4 arguments");
RedisCommand.BITPOS.validateArgumentCount(5);
}
@Test // DATAREDIS-73
public void shouldThrowExceptionOnInvalidArgumentCountWhenExpectedExactMatch() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("AUTH command requires 1 arguments");
RedisCommand.AUTH.validateArgumentCount(2);
@@ -95,9 +95,12 @@ public class RedisCommandUnitTests {
@Test // DATAREDIS-73
public void shouldThrowExceptionOnInvalidArgumentCountWhenExpectedMinimalMatch() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("DEL command requires at least 1 arguments");
RedisCommand.DEL.validateArgumentCount(0);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("ZADD command requires at least 3 arguments");
RedisCommand.ZADD.validateArgumentCount(2); // DATAREDIS-972
}
}