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.
|
||||
|
||||
Reference in New Issue
Block a user