DATAREDIS-1013 - Polishing.
Add test. Consider grammar depending on argument count. Original pull request: #468.
This commit is contained in:
@@ -342,21 +342,25 @@ public enum RedisCommand {
|
||||
if (requiresExactNumberOfArguments()) {
|
||||
if (nrArguments != maxArgs) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s command requires %s arguments.", this.name(), this.maxArgs));
|
||||
String.format("%s command requires %s %s.", this.name(), this.maxArgs, arguments(this.maxArgs)));
|
||||
}
|
||||
}
|
||||
if (nrArguments < minArgs) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s command requires at least %s arguments.", this.name(), this.minArgs));
|
||||
String.format("%s command requires at least %s %s.", this.name(), this.minArgs, arguments(this.maxArgs)));
|
||||
}
|
||||
|
||||
if (maxArgs > 0 && nrArguments > maxArgs) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s command requires at most %s arguments.", this.name(), this.maxArgs));
|
||||
String.format("%s command requires at most %s %s.", this.name(), this.maxArgs, arguments(this.maxArgs)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String arguments(int count) {
|
||||
return count == 1 ? "argument" : "arguments";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command represented by the given {@code key}. Returns {@link #UNKNOWN} if no matching command could be
|
||||
* found.
|
||||
|
||||
@@ -63,7 +63,7 @@ public class RedisCommandUnitTests {
|
||||
assertThat(RedisCommand.failsafeCommandLookup("strangecommand")).isEqualTo(RedisCommand.UNKNOWN);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73, DATAREDIS-972
|
||||
@Test // DATAREDIS-73, DATAREDIS-972, DATAREDIS-1013
|
||||
public void shouldNotThrowExceptionOnValidArgumentCount() {
|
||||
|
||||
RedisCommand.AUTH.validateArgumentCount(1);
|
||||
@@ -71,6 +71,7 @@ public class RedisCommandUnitTests {
|
||||
RedisCommand.ZADD.validateArgumentCount(4);
|
||||
RedisCommand.ZADD.validateArgumentCount(5);
|
||||
RedisCommand.ZADD.validateArgumentCount(100);
|
||||
RedisCommand.SELECT.validateArgumentCount(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-822
|
||||
@@ -85,16 +86,16 @@ public class RedisCommandUnitTests {
|
||||
public void shouldReportArgumentMismatchIfMaxArgumentsExceeded() {
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage("BITPOS command requires at most 4 arguments");
|
||||
expectedException.expectMessage("SELECT command requires 1 argument");
|
||||
|
||||
RedisCommand.BITPOS.validateArgumentCount(5);
|
||||
RedisCommand.SELECT.validateArgumentCount(0);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73
|
||||
public void shouldThrowExceptionOnInvalidArgumentCountWhenExpectedExactMatch() {
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage("AUTH command requires 1 arguments");
|
||||
expectedException.expectMessage("AUTH command requires 1 argument");
|
||||
|
||||
RedisCommand.AUTH.validateArgumentCount(2);
|
||||
}
|
||||
@@ -103,7 +104,7 @@ public class RedisCommandUnitTests {
|
||||
public void shouldThrowExceptionOnInvalidArgumentCountForDelWhenExpectedMinimalMatch() {
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage("DEL command requires at least 1 arguments");
|
||||
expectedException.expectMessage("DEL command requires at least 1 argument");
|
||||
|
||||
RedisCommand.DEL.validateArgumentCount(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user