diff --git a/src/main/java/org/springframework/data/redis/core/RedisCommand.java b/src/main/java/org/springframework/data/redis/core/RedisCommand.java index 800fabf4e..e8af11374 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisCommand.java +++ b/src/main/java/org/springframework/data/redis/core/RedisCommand.java @@ -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. diff --git a/src/test/java/org/springframework/data/redis/core/RedisCommandUnitTests.java b/src/test/java/org/springframework/data/redis/core/RedisCommandUnitTests.java index bd31ebfbb..9038ab44a 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisCommandUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisCommandUnitTests.java @@ -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); }