File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
main/java/org/springframework/data/redis/core
test/java/org/springframework/data/redis/core Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 28
28
* @author Christoph Strobl
29
29
* @author Thomas Darimont
30
30
* @author Ninad Divadkar
31
+ * @author Mark Paluch
31
32
* @since 1.3
32
33
* @see Redis command list:
33
34
* https://github.com/antirez/redis/blob/93e7a130fc9594e41ccfc996b5eca7626ae5356a/src/redis.c#L119
@@ -279,10 +280,10 @@ public boolean requiresArguments() {
279
280
}
280
281
281
282
/**
282
- * @return {@literal true} if an exact number of arguments is expected
283
+ * @return {@literal true} if an exact number of arguments is expected.
283
284
*/
284
285
public boolean requiresExactNumberOfArguments () {
285
- return maxArgs >= 0 ;
286
+ return maxArgs == 0 || minArgs == maxArgs ;
286
287
}
287
288
288
289
/**
@@ -345,6 +346,11 @@ public void validateArgumentCount(int nrArguments) {
345
346
throw new IllegalArgumentException (
346
347
String .format ("%s command requires at least %s arguments." , this .name (), this .minArgs ));
347
348
}
349
+
350
+ if (maxArgs != 0 && nrArguments > maxArgs ) {
351
+ throw new IllegalArgumentException (
352
+ String .format ("%s command requires at most %s arguments." , this .name (), this .maxArgs ));
353
+ }
348
354
}
349
355
}
350
356
Original file line number Diff line number Diff line change 23
23
import org .junit .rules .ExpectedException ;
24
24
25
25
/**
26
+ * Unit tests for {@link RedisCommand}.
27
+ *
26
28
* @author Christoph Strobl
27
29
* @author Thomas Darimont
30
+ * @author Mark Paluch
28
31
*/
29
32
public class RedisCommandUnitTests {
30
33
@@ -65,8 +68,25 @@ public void shouldNotThrowExceptionOnValidArgumentCount() {
65
68
RedisCommand .AUTH .validateArgumentCount (1 );
66
69
}
67
70
71
+ @ Test // DATAREDIS-822
72
+ public void shouldConsiderMinMaxArguments () {
73
+
74
+ RedisCommand .BITPOS .validateArgumentCount (2 );
75
+ RedisCommand .BITPOS .validateArgumentCount (3 );
76
+ RedisCommand .BITPOS .validateArgumentCount (4 );
77
+ }
78
+
79
+ @ Test // DATAREDIS-822
80
+ public void shouldReportArgumentMismatchIfMaxArgumentsExceeded () {
81
+
82
+ expectedException .expect (IllegalArgumentException .class );
83
+ expectedException .expectMessage ("BITPOS command requires at most 4 arguments" );
84
+
85
+ RedisCommand .BITPOS .validateArgumentCount (5 );
86
+ }
87
+
68
88
@ Test // DATAREDIS-73
69
- public void shouldThrowExceptionOnInvalidArgumentCountWhenExpectedExcatMatch () {
89
+ public void shouldThrowExceptionOnInvalidArgumentCountWhenExpectedExactMatch () {
70
90
71
91
expectedException .expect (IllegalArgumentException .class );
72
92
expectedException .expectMessage ("AUTH command requires 1 arguments" );
You can’t perform that action at this time.
0 commit comments