@@ -395,25 +395,25 @@ public void testMatchesAllStartingWith() throws Exception {
395395 query = new ParseQuery .State .Builder <>("TestObject" )
396396 .addCondition ("foo" , "$all" ,
397397 Arrays .asList (
398- buildStartsWithRegex ("foo" ),
399- buildStartsWithRegex ("bar" )))
398+ buildStartsWithRegexKeyConstraint ("foo" ),
399+ buildStartsWithRegexKeyConstraint ("bar" )))
400400 .build ();
401401 assertTrue (matches (logic , query , object ));
402402
403403 query = new ParseQuery .State .Builder <>("TestObject" )
404404 .addCondition ("foo" , "$all" ,
405405 Arrays .asList (
406- buildStartsWithRegex ("fo" ),
407- buildStartsWithRegex ("b" )))
406+ buildStartsWithRegexKeyConstraint ("fo" ),
407+ buildStartsWithRegexKeyConstraint ("b" )))
408408 .build ();
409409 assertTrue (matches (logic , query , object ));
410410
411411 query = new ParseQuery .State .Builder <>("TestObject" )
412412 .addCondition ("foo" , "$all" ,
413413 Arrays .asList (
414- buildStartsWithRegex ("foo" ),
415- buildStartsWithRegex ("bar" ),
416- buildStartsWithRegex ("qux" )))
414+ buildStartsWithRegexKeyConstraint ("foo" ),
415+ buildStartsWithRegexKeyConstraint ("bar" ),
416+ buildStartsWithRegexKeyConstraint ("qux" )))
417417 .build ();
418418 assertFalse (matches (logic , query , object ));
419419
@@ -439,19 +439,43 @@ public void testMatchesAllStartingWithParameters() throws Exception {
439439 query = new ParseQuery .State .Builder <>("TestObject" )
440440 .addCondition ("foo" , "$all" ,
441441 Arrays .asList (
442- buildStartsWithRegex ("foo" ),
443- buildStartsWithRegex ("bar" )))
442+ buildStartsWithRegexKeyConstraint ("foo" ),
443+ buildStartsWithRegexKeyConstraint ("bar" )))
444444 .build ();
445445 assertTrue (matches (logic , query , object ));
446446
447447 query = new ParseQuery .State .Builder <>("TestObject" )
448448 .addCondition ("foo" , "$all" ,
449449 Arrays .asList (
450- buildStartsWithRegex ("fo" ),
450+ buildStartsWithRegexKeyConstraint ("fo" ),
451+ buildStartsWithRegex ("ba" ),
451452 "b" ))
452453 .build ();
453454 thrown .expect (IllegalArgumentException .class );
454455 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 ;
455479 }
456480
457481 /**
0 commit comments