DATAREDIS-1013 - Polishing.

Add test. Consider grammar depending on argument count.

Original pull request: #468.
This commit is contained in:
Mark Paluch
2019-07-26 14:48:19 +02:00
parent c6267e7d47
commit 2de4141514
2 changed files with 13 additions and 8 deletions

View File

@@ -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.