Skip to content

Commit f82f030

Browse files
committed
DATAMONGO-1425 - Compare not like/not containing queries in tests using JSON.
Comparing query documents using equals performs an object equals check and not a BSON represented equality check. Since Pattern.equals performs only a object instance equality check (this==that) we cannot check for equality using equals as this check always returns false. We now compare nested patterns using the JSON representation.
1 parent 1341d96 commit f82f030

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryCreatorUnitTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
/**
6464
* Unit test for {@link MongoQueryCreator}.
65-
*
65+
*
6666
* @author Oliver Gierke
6767
* @author Thomas Darimont
6868
* @author Christoph Strobl
@@ -463,7 +463,7 @@ public void shouldCreateRegexWhenUsingNotContainsOnStringProperty() {
463463
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "thew"), context);
464464
Query query = creator.createQuery();
465465

466-
assertThat(query.getQueryObject(), is(query(where("username").not().regex(".*thew.*")).getQueryObject()));
466+
assertThat(query.getQueryObject().toJson(), is(query(where("username").not().regex(".*thew.*")).getQueryObject().toJson()));
467467
}
468468

469469
/**
@@ -680,8 +680,8 @@ public void notLikeShouldEscapeSourceWhenUsedWithLeadingAndTrailingWildcard() {
680680

681681
Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
682682

683-
assertThat(query.getQueryObject(),
684-
is(query(where("username").not().regex(".*\\Qfire.fight+\\E.*")).getQueryObject()));
683+
assertThat(query.getQueryObject().toJson(),
684+
is(query(where("username").not().regex(".*\\Qfire.fight+\\E.*")).getQueryObject().toJson()));
685685
}
686686

687687
/**
@@ -695,8 +695,8 @@ public void notLikeShouldEscapeSourceWhenUsedWithLeadingWildcard() {
695695

696696
Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
697697

698-
assertThat(query.getQueryObject(),
699-
is(query(where("username").not().regex(".*\\Qsteel.heart+\\E")).getQueryObject()));
698+
assertThat(query.getQueryObject().toJson(),
699+
is(query(where("username").not().regex(".*\\Qsteel.heart+\\E")).getQueryObject().toJson()));
700700
}
701701

702702
/**
@@ -709,7 +709,7 @@ public void notLikeShouldEscapeSourceWhenUsedWithTrailingWildcard() {
709709
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "cala.mity+*"), context);
710710
Query query = creator.createQuery();
711711

712-
assertThat(query.getQueryObject(), is(query(where("username").not().regex("\\Qcala.mity+\\E.*")).getQueryObject()));
712+
assertThat(query.getQueryObject().toJson(), is(query(where("username").not().regex("\\Qcala.mity+\\E.*")).getQueryObject().toJson()));
713713
}
714714

715715
/**
@@ -722,7 +722,7 @@ public void notLikeShouldBeTreatedCorrectlyWhenUsedWithWildcardOnly() {
722722
ConvertingParameterAccessor accessor = getAccessor(converter, "*");
723723

724724
Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
725-
assertThat(query.getQueryObject(), is(query(where("username").not().regex(".*")).getQueryObject()));
725+
assertThat(query.getQueryObject().toJson(), is(query(where("username").not().regex(".*")).getQueryObject().toJson()));
726726
}
727727

728728
interface PersonRepository extends Repository<Person, Long> {

0 commit comments

Comments
 (0)