@@ -395,25 +395,25 @@ public void testMatchesAllStartingWith() throws Exception {
395
395
query = new ParseQuery .State .Builder <>("TestObject" )
396
396
.addCondition ("foo" , "$all" ,
397
397
Arrays .asList (
398
- buildStartsWithRegex ("foo" ),
399
- buildStartsWithRegex ("bar" )))
398
+ buildStartsWithRegexKeyConstraint ("foo" ),
399
+ buildStartsWithRegexKeyConstraint ("bar" )))
400
400
.build ();
401
401
assertTrue (matches (logic , query , object ));
402
402
403
403
query = new ParseQuery .State .Builder <>("TestObject" )
404
404
.addCondition ("foo" , "$all" ,
405
405
Arrays .asList (
406
- buildStartsWithRegex ("fo" ),
407
- buildStartsWithRegex ("b" )))
406
+ buildStartsWithRegexKeyConstraint ("fo" ),
407
+ buildStartsWithRegexKeyConstraint ("b" )))
408
408
.build ();
409
409
assertTrue (matches (logic , query , object ));
410
410
411
411
query = new ParseQuery .State .Builder <>("TestObject" )
412
412
.addCondition ("foo" , "$all" ,
413
413
Arrays .asList (
414
- buildStartsWithRegex ("foo" ),
415
- buildStartsWithRegex ("bar" ),
416
- buildStartsWithRegex ("qux" )))
414
+ buildStartsWithRegexKeyConstraint ("foo" ),
415
+ buildStartsWithRegexKeyConstraint ("bar" ),
416
+ buildStartsWithRegexKeyConstraint ("qux" )))
417
417
.build ();
418
418
assertFalse (matches (logic , query , object ));
419
419
@@ -439,19 +439,43 @@ public void testMatchesAllStartingWithParameters() throws Exception {
439
439
query = new ParseQuery .State .Builder <>("TestObject" )
440
440
.addCondition ("foo" , "$all" ,
441
441
Arrays .asList (
442
- buildStartsWithRegex ("foo" ),
443
- buildStartsWithRegex ("bar" )))
442
+ buildStartsWithRegexKeyConstraint ("foo" ),
443
+ buildStartsWithRegexKeyConstraint ("bar" )))
444
444
.build ();
445
445
assertTrue (matches (logic , query , object ));
446
446
447
447
query = new ParseQuery .State .Builder <>("TestObject" )
448
448
.addCondition ("foo" , "$all" ,
449
449
Arrays .asList (
450
- buildStartsWithRegex ("fo" ),
450
+ buildStartsWithRegexKeyConstraint ("fo" ),
451
+ buildStartsWithRegex ("ba" ),
451
452
"b" ))
452
453
.build ();
453
454
thrown .expect (IllegalArgumentException .class );
454
455
assertFalse (matches (logic , query , object ));
456
+
457
+ query = new ParseQuery .State .Builder <>("TestObject" )
458
+ .addCondition ("foo" , "$all" ,
459
+ Arrays .asList (
460
+ buildStartsWithRegexKeyConstraint ("fo" ),
461
+ "b" ))
462
+ .build ();
463
+ thrown .expect (IllegalArgumentException .class );
464
+ assertFalse (matches (logic , query , object ));
465
+ }
466
+
467
+ /**
468
+ * Helper method to convert a string to a key constraint to match strings that starts with given
469
+ * string.
470
+ *
471
+ * @param prefix String to use as prefix in regex.
472
+ * @return The key constraint for word matching at the beginning of a string.
473
+ */
474
+ @ NonNull
475
+ private ParseQuery .KeyConstraints buildStartsWithRegexKeyConstraint (String prefix ) {
476
+ ParseQuery .KeyConstraints constraint = new ParseQuery .KeyConstraints ();
477
+ constraint .put ("$regex" , buildStartsWithRegex (prefix ));
478
+ return constraint ;
455
479
}
456
480
457
481
/**
0 commit comments