@@ -781,7 +781,8 @@ void exampleWithCombinedCriteriaShouldBeMappedCorrectly() {
781781 Query query = query (byExample (probe ).and ("listOfItems" ).exists (true ));
782782 org .bson .Document document = mapper .getMappedObject (query .getQueryObject (), context .getPersistentEntity (Foo .class ));
783783
784- assertThat (document ).containsEntry ("embedded\\ ._id" , "conflux" ).containsEntry ("my_items" , new org .bson .Document ("$exists" , true ));
784+ assertThat (document ).containsEntry ("embedded\\ ._id" , "conflux" ).containsEntry ("my_items" ,
785+ new org .bson .Document ("$exists" , true ));
785786 }
786787
787788 @ Test // DATAMONGO-1988
@@ -1011,6 +1012,76 @@ void shouldParseNestedKeywordWithArgumentMatchingTheSourceEntitiesConstructorCor
10111012 assertThat (target ).isEqualTo (org .bson .Document .parse ("{\" $text\" : { \" $search\" : \" test\" }}" ));
10121013 }
10131014
1015+ @ Test // GH-3601
1016+ void resolvesFieldnameWithUnderscoresCorrectly () {
1017+
1018+ Query query = query (where ("fieldname_with_underscores" ).exists (true ));
1019+
1020+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1021+ context .getPersistentEntity (WithPropertyUsingUnderscoreInName .class ));
1022+
1023+ assertThat (document )
1024+ .isEqualTo (new org .bson .Document ("fieldname_with_underscores" , new org .bson .Document ("$exists" , true )));
1025+ }
1026+
1027+ @ Test // GH-3601
1028+ void resolvesMappedFieldnameWithUnderscoresCorrectly () {
1029+
1030+ Query query = query (where ("renamed_fieldname_with_underscores" ).exists (true ));
1031+
1032+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1033+ context .getPersistentEntity (WithPropertyUsingUnderscoreInName .class ));
1034+
1035+ assertThat (document ).isEqualTo (new org .bson .Document ("renamed" , new org .bson .Document ("$exists" , true )));
1036+ }
1037+
1038+ @ Test // GH-3601
1039+ void resolvesSimpleNestedFieldnameWithUnderscoresCorrectly () {
1040+
1041+ Query query = query (where ("simple.fieldname_with_underscores" ).exists (true ));
1042+
1043+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1044+ context .getPersistentEntity (WrapperAroundWithPropertyUsingUnderscoreInName .class ));
1045+
1046+ assertThat (document )
1047+ .isEqualTo (new org .bson .Document ("simple.fieldname_with_underscores" , new org .bson .Document ("$exists" , true )));
1048+ }
1049+
1050+ @ Test // GH-3601
1051+ void resolvesSimpleNestedMappedFieldnameWithUnderscoresCorrectly () {
1052+
1053+ Query query = query (where ("simple.renamed_fieldname_with_underscores" ).exists (true ));
1054+
1055+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1056+ context .getPersistentEntity (WrapperAroundWithPropertyUsingUnderscoreInName .class ));
1057+
1058+ assertThat (document ).isEqualTo (new org .bson .Document ("simple.renamed" , new org .bson .Document ("$exists" , true )));
1059+ }
1060+
1061+ @ Test // GH-3601
1062+ void resolvesFieldNameWithUnderscoreOnNestedFieldnameWithUnderscoresCorrectly () {
1063+
1064+ Query query = query (where ("double_underscore.fieldname_with_underscores" ).exists (true ));
1065+
1066+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1067+ context .getPersistentEntity (WrapperAroundWithPropertyUsingUnderscoreInName .class ));
1068+
1069+ assertThat (document ).isEqualTo (
1070+ new org .bson .Document ("double_underscore.fieldname_with_underscores" , new org .bson .Document ("$exists" , true )));
1071+ }
1072+
1073+ @ Test // GH-3601
1074+ void resolvesFieldNameWithUnderscoreOnNestedMappedFieldnameWithUnderscoresCorrectly () {
1075+
1076+ Query query = query (where ("double_underscore.renamed_fieldname_with_underscores" ).exists (true ));
1077+
1078+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1079+ context .getPersistentEntity (WrapperAroundWithPropertyUsingUnderscoreInName .class ));
1080+
1081+ assertThat (document )
1082+ .isEqualTo (new org .bson .Document ("double_underscore.renamed" , new org .bson .Document ("$exists" , true )));
1083+ }
1084+
10141085 class WithDeepArrayNesting {
10151086
10161087 List <WithNestedArray > level0 ;
@@ -1194,4 +1265,17 @@ public WithSingleStringArgConstructor(String value) {
11941265 this .value = value ;
11951266 }
11961267 }
1268+
1269+ static class WrapperAroundWithPropertyUsingUnderscoreInName {
1270+
1271+ WithPropertyUsingUnderscoreInName simple ;
1272+ WithPropertyUsingUnderscoreInName double_underscore ;
1273+ }
1274+
1275+ static class WithPropertyUsingUnderscoreInName {
1276+
1277+ String fieldname_with_underscores ;
1278+
1279+ @ Field ("renamed" ) String renamed_fieldname_with_underscores ;
1280+ }
11971281}
0 commit comments