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 29
29
* @author Christoph Strobl
30
30
* @author Thomas Darimont
31
31
* @author Ninad Divadkar
32
+ * @author Mark Paluch
32
33
* @since 1.3
33
34
* @see Redis command list:
34
35
* https://github.com/antirez/redis/blob/93e7a130fc9594e41ccfc996b5eca7626ae5356a/src/redis.c#L119
@@ -280,10 +281,10 @@ public boolean requiresArguments() {
280
281
}
281
282
282
283
/**
283
- * @return {@literal true} if an exact number of arguments is expected
284
+ * @return {@literal true} if an exact number of arguments is expected.
284
285
*/
285
286
public boolean requiresExactNumberOfArguments () {
286
- return maxArgs >= 0 ;
287
+ return maxArgs == 0 || minArgs == maxArgs ;
287
288
}
288
289
289
290
/**
@@ -346,6 +347,11 @@ public void validateArgumentCount(int nrArguments) {
346
347
throw new IllegalArgumentException (
347
348
String .format ("%s command requires at least %s arguments." , this .name (), this .minArgs ));
348
349
}
350
+
351
+ if (maxArgs != 0 && nrArguments > maxArgs ) {
352
+ throw new IllegalArgumentException (
353
+ String .format ("%s command requires at most %s arguments." , this .name (), this .maxArgs ));
354
+ }
349
355
}
350
356
}
351
357
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