Skip to content

Commit ffb14f2

Browse files
committed
Duplicated the map tests for lists and sets
Added back in the control tests
1 parent 4b3c07e commit ffb14f2

File tree

2 files changed

+351
-9
lines changed

2 files changed

+351
-9
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterTests.java

Lines changed: 351 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,23 @@ public String toString() {
482482
}
483483

484484
@Nested // GH-5065
485-
class EmptyMapTests {
485+
class EmptyMapTests {
486+
487+
@Test // GH-5065
488+
void controlTestToIllustrateThatTheEmptyMapProblemIsLimitedToDocumentReferencesAndNotAMoreGenericProblem() {
489+
org.bson.Document document = org.bson.Document.parse("{\"map\":{}}");
490+
//EmptyMapDocument target = converter.read(EmptyMapDocument.class, document);
491+
assertThat(converter.read(EmptyMapDocument.class, document).map).isNotNull().isEmpty();
492+
assertThat(converter.read(EmptyMapDocument.class, document).getMap()).isNotNull().isEmpty();
493+
}
494+
495+
@Test // GH-5065
496+
void controlTestToIllustrateThatTheNullMapProblemIsLimitedToDocumentReferencesAndNotAMoreGenericProblem() {
497+
org.bson.Document document = org.bson.Document.parse("{\"map\":null}");
498+
//EmptyMapDocument target = converter.read(EmptyMapDocument.class, document);
499+
assertThat(converter.read(EmptyMapDocument.class, document).map).isNull();
500+
assertThat(converter.read(EmptyMapDocument.class, document).getMap()).isNull();
501+
}
486502

487503
@Test // GH-5065
488504
void converterShouldReadAnEmptyObjectAsAnEmptyMapWhenUsingDocumentReferenceAnnotation() {
@@ -568,6 +584,19 @@ void converterShouldReadAnExplicitlyAssignedNullAsANullMapWhenUsingDBRefAnnotati
568584
assertThat(target.getMap()).isNull();
569585
}
570586

587+
static class EmptyMapDocument {
588+
589+
Map<String, String> map;
590+
591+
public EmptyMapDocument(Map<String, String> map) {
592+
this.map = map;
593+
}
594+
595+
Map<String, String> getMap() {
596+
return map;
597+
}
598+
}
599+
571600
static class DocumentReferenceEmptyMapDocument {
572601

573602
@DocumentReference
@@ -595,19 +624,333 @@ Map<String, String> getMap() {
595624
return map;
596625
}
597626
}
627+
628+
static class DBRefEmptyMapDocument {
629+
630+
@DBRef
631+
Map<String, String> map;
632+
633+
public DBRefEmptyMapDocument(Map<String, String> map) {
634+
this.map = map;
635+
}
636+
637+
Map<String, String> getMap() {
638+
return map;
639+
}
640+
}
598641
}
599642

600-
static class DBRefEmptyMapDocument {
643+
@Nested // GH-5065
644+
class EmptyListTests {
645+
646+
@Test // GH-5065
647+
void controlTestToIllustrateThatTheEmptyListProblemIsLimitedToDocumentReferencesAndNotAMoreGenericProblem() {
648+
org.bson.Document document = org.bson.Document.parse("{\"list\":[]}");
649+
EmptyListDocument target = converter.read(EmptyListDocument.class, document);
650+
assertThat(target.list).isNotNull().isEmpty();
651+
}
652+
653+
@Test // GH-5065
654+
void controlTestToIllustrateThatTheEmptyListProblemIsLimitedToDocumentReferencesAndNotAMoreGenericProblemUsingGetList() {
655+
org.bson.Document document = org.bson.Document.parse("{\"list\":[]}");
656+
EmptyListDocument target = converter.read(EmptyListDocument.class, document);
657+
assertThat(target.getList()).isNotNull().isEmpty();
658+
}
601659

602-
@DBRef
603-
Map<String, String> map;
660+
@Test // GH-5065
661+
void controlTestToIllustrateThatTheNullListProblemIsLimitedToDocumentReferencesAndNotAMoreGenericProblem() {
662+
org.bson.Document document = org.bson.Document.parse("{\"list\":null}");
663+
EmptyListDocument target = converter.read(EmptyListDocument.class, document);
664+
assertThat(target.list).isNull();
665+
}
604666

605-
public DBRefEmptyMapDocument(Map<String, String> map) {
606-
this.map = map;
667+
@Test // GH-5065
668+
void controlTestToIllustrateThatTheNullListProblemIsLimitedToDocumentReferencesAndNotAMoreGenericProblemUsingGetList() {
669+
org.bson.Document document = org.bson.Document.parse("{\"list\":null}");
670+
EmptyListDocument target = converter.read(EmptyListDocument.class, document);
671+
assertThat(target.getList()).isNull();
607672
}
608673

609-
Map<String, String> getMap() {
610-
return map;
674+
@Test // GH-5065
675+
void converterShouldReadAnEmptyObjectAsAnEmptyListWhenUsingDocumentReferenceAnnotation() {
676+
org.bson.Document document = org.bson.Document.parse("{\"list\":[]}");
677+
DocumentReferenceEmptyListDocument target = converter.read(DocumentReferenceEmptyListDocument.class, document);
678+
assertThat(target.list).isNotNull().isEmpty();
679+
}
680+
681+
@Test // GH-5065
682+
void converterShouldReadAnEmptyObjectAsAnEmptyListWhenUsingDocumentReferenceAnnotationUsingGetList() {
683+
org.bson.Document document = org.bson.Document.parse("{\"list\":[]}");
684+
DocumentReferenceEmptyListDocument target = converter.read(DocumentReferenceEmptyListDocument.class, document);
685+
assertThat(target.getList()).isNotNull().isEmpty();
686+
}
687+
688+
@Test // GH-5065
689+
void converterShouldReadAnExplicitlyAssignedNullAsANullListWhenUsingDocumentReferenceAnnotation() {
690+
org.bson.Document document = org.bson.Document.parse("{\"list\":null}");
691+
DocumentReferenceEmptyListDocument target = converter.read(DocumentReferenceEmptyListDocument.class, document);
692+
assertThat(target.list).isNull();
693+
}
694+
695+
@Test // GH-5065
696+
void converterShouldReadAnExplicitlyAssignedNullAsANullListWhenUsingDocumentReferenceAnnotationUsingGetList() {
697+
org.bson.Document document = org.bson.Document.parse("{\"list\":null}");
698+
DocumentReferenceEmptyListDocument target = converter.read(DocumentReferenceEmptyListDocument.class, document);
699+
assertThat(target.getList()).isNull();
700+
}
701+
702+
@Test // GH-5065
703+
void converterShouldReadAnEmptyObjectAsAnEmptyListWhenUsingDocumentReferenceAnnotationWithLazyEqualToTrue() {
704+
org.bson.Document document = org.bson.Document.parse("{\"list\":[]}");
705+
LazyDocumentReferenceEmptyListDocument target = converter.read(LazyDocumentReferenceEmptyListDocument.class, document);
706+
assertThat(target.list).isNotNull().isEmpty();
707+
}
708+
709+
@Test // GH-5065
710+
void converterShouldReadAnEmptyObjectAsAnEmptyListWhenUsingDocumentReferenceAnnotationWithLazyEqualToTrueUsingGetList() {
711+
org.bson.Document document = org.bson.Document.parse("{\"list\":[]}");
712+
LazyDocumentReferenceEmptyListDocument target = converter.read(LazyDocumentReferenceEmptyListDocument.class, document);
713+
assertThat(target.getList()).isNotNull().isEmpty();
714+
}
715+
716+
@Test // GH-5065
717+
void converterShouldReadAnEmptyObjectAsAnEmptyListWhenUsingDBRefAnnotation() {
718+
org.bson.Document document = org.bson.Document.parse("{\"list\":[]}");
719+
DBRefEmptyListDocument target = converter.read(DBRefEmptyListDocument.class, document);
720+
assertThat(target.list).isNotNull().isEmpty();
721+
}
722+
723+
@Test // GH-5065
724+
void converterShouldReadAnEmptyObjectAsAnEmptyListWhenUsingDBRefAnnotationUsingGetList() {
725+
org.bson.Document document = org.bson.Document.parse("{\"list\":[]}");
726+
DBRefEmptyListDocument target = converter.read(DBRefEmptyListDocument.class, document);
727+
assertThat(target.getList()).isNotNull().isEmpty();
728+
}
729+
730+
@Test // GH-5065
731+
void converterShouldReadAnExplicitlyAssignedNullAsANullListWhenUsingDBRefAnnotation() {
732+
org.bson.Document document = org.bson.Document.parse("{\"list\":null}");
733+
DBRefEmptyListDocument target = converter.read(DBRefEmptyListDocument.class, document);
734+
assertThat(target.list).isNull();
735+
}
736+
737+
@Test // GH-5065
738+
void converterShouldReadAnExplicitlyAssignedNullAsANullListWhenUsingDBRefAnnotationUsingGetList() {
739+
org.bson.Document document = org.bson.Document.parse("{\"list\":null}");
740+
DBRefEmptyListDocument target = converter.read(DBRefEmptyListDocument.class, document);
741+
assertThat(target.getList()).isNull();
742+
}
743+
744+
static class EmptyListDocument {
745+
746+
List<String> list;
747+
748+
public EmptyListDocument(List<String> list) {
749+
this.list = list;
750+
}
751+
752+
List<String> getList() {
753+
return list;
754+
}
755+
}
756+
757+
static class DocumentReferenceEmptyListDocument {
758+
759+
@DocumentReference
760+
List<String> list;
761+
762+
public DocumentReferenceEmptyListDocument(List<String> list) {
763+
this.list = list;
764+
}
765+
766+
List<String> getList() {
767+
return list;
768+
}
769+
}
770+
771+
static class LazyDocumentReferenceEmptyListDocument {
772+
773+
@DocumentReference(lazy = true)
774+
List<String> list;
775+
776+
public LazyDocumentReferenceEmptyListDocument(List<String> list) {
777+
this.list = list;
778+
}
779+
780+
List<String> getList() {
781+
return list;
782+
}
783+
}
784+
785+
static class DBRefEmptyListDocument {
786+
787+
@DBRef
788+
List<String> list;
789+
790+
public DBRefEmptyListDocument(List<String> list) {
791+
this.list = list;
792+
}
793+
794+
List<String> getList() {
795+
return list;
796+
}
797+
}
798+
}
799+
800+
@Nested // GH-5065
801+
class EmptySetTests {
802+
803+
@Test // GH-5065
804+
void controlTestToIllustrateThatTheEmptySetProblemIsLimitedToDocumentReferencesAndNotAMoreGenericProblem() {
805+
org.bson.Document document = org.bson.Document.parse("{\"set\":[]}");
806+
EmptySetDocument target = converter.read(EmptySetDocument.class, document);
807+
assertThat(target.set).isNotNull().isEmpty();
808+
}
809+
810+
@Test // GH-5065
811+
void controlTestToIllustrateThatTheEmptySetProblemIsLimitedToDocumentReferencesAndNotAMoreGenericProblemUsingGetSet() {
812+
org.bson.Document document = org.bson.Document.parse("{\"set\":[]}");
813+
EmptySetDocument target = converter.read(EmptySetDocument.class, document);
814+
assertThat(target.getSet()).isNotNull().isEmpty();
815+
}
816+
817+
@Test // GH-5065
818+
void controlTestToIllustrateThatTheNullSetProblemIsLimitedToDocumentReferencesAndNotAMoreGenericProblem() {
819+
org.bson.Document document = org.bson.Document.parse("{\"set\":null}");
820+
EmptySetDocument target = converter.read(EmptySetDocument.class, document);
821+
assertThat(target.set).isNull();
822+
}
823+
824+
@Test // GH-5065
825+
void controlTestToIllustrateThatTheNullSetProblemIsLimitedToDocumentReferencesAndNotAMoreGenericProblemUsingGetSet() {
826+
org.bson.Document document = org.bson.Document.parse("{\"set\":null}");
827+
EmptySetDocument target = converter.read(EmptySetDocument.class, document);
828+
assertThat(target.getSet()).isNull();
829+
}
830+
831+
@Test // GH-5065
832+
void converterShouldReadAnEmptyObjectAsAnEmptySetWhenUsingDocumentReferenceAnnotation() {
833+
org.bson.Document document = org.bson.Document.parse("{\"set\":[]}");
834+
DocumentReferenceEmptySetDocument target = converter.read(DocumentReferenceEmptySetDocument.class, document);
835+
assertThat(target.set).isNotNull().isEmpty();
836+
}
837+
838+
@Test // GH-5065
839+
void converterShouldReadAnEmptyObjectAsAnEmptySetWhenUsingDocumentReferenceAnnotationUsingGetSet() {
840+
org.bson.Document document = org.bson.Document.parse("{\"set\":[]}");
841+
DocumentReferenceEmptySetDocument target = converter.read(DocumentReferenceEmptySetDocument.class, document);
842+
assertThat(target.getSet()).isNotNull().isEmpty();
843+
}
844+
845+
@Test // GH-5065
846+
void converterShouldReadAnExplicitlyAssignedNullAsANullSetWhenUsingDocumentReferenceAnnotation() {
847+
org.bson.Document document = org.bson.Document.parse("{\"set\":null}");
848+
DocumentReferenceEmptySetDocument target = converter.read(DocumentReferenceEmptySetDocument.class, document);
849+
assertThat(target.set).isNull();
850+
}
851+
852+
@Test // GH-5065
853+
void converterShouldReadAnExplicitlyAssignedNullAsANullSetWhenUsingDocumentReferenceAnnotationUsingGetSet() {
854+
org.bson.Document document = org.bson.Document.parse("{\"set\":null}");
855+
DocumentReferenceEmptySetDocument target = converter.read(DocumentReferenceEmptySetDocument.class, document);
856+
assertThat(target.getSet()).isNull();
857+
}
858+
859+
@Test // GH-5065
860+
void converterShouldReadAnEmptyObjectAsAnEmptySetWhenUsingDocumentReferenceAnnotationWithLazyEqualToTrue() {
861+
org.bson.Document document = org.bson.Document.parse("{\"set\":[]}");
862+
LazyDocumentReferenceEmptySetDocument target = converter.read(LazyDocumentReferenceEmptySetDocument.class, document);
863+
assertThat(target.set).isNotNull().isEmpty();
864+
}
865+
866+
@Test // GH-5065
867+
void converterShouldReadAnEmptyObjectAsAnEmptySetWhenUsingDocumentReferenceAnnotationWithLazyEqualToTrueUsingGetSet() {
868+
org.bson.Document document = org.bson.Document.parse("{\"set\":[]}");
869+
LazyDocumentReferenceEmptySetDocument target = converter.read(LazyDocumentReferenceEmptySetDocument.class, document);
870+
assertThat(target.getSet()).isNotNull().isEmpty();
871+
}
872+
873+
@Test // GH-5065
874+
void converterShouldReadAnEmptyObjectAsAnEmptySetWhenUsingDBRefAnnotation() {
875+
org.bson.Document document = org.bson.Document.parse("{\"set\":[]}");
876+
DBRefEmptySetDocument target = converter.read(DBRefEmptySetDocument.class, document);
877+
assertThat(target.set).isNotNull().isEmpty();
878+
}
879+
880+
@Test // GH-5065
881+
void converterShouldReadAnEmptyObjectAsAnEmptySetWhenUsingDBRefAnnotationUsingGetSet() {
882+
org.bson.Document document = org.bson.Document.parse("{\"set\":[]}");
883+
DBRefEmptySetDocument target = converter.read(DBRefEmptySetDocument.class, document);
884+
assertThat(target.getSet()).isNotNull().isEmpty();
885+
}
886+
887+
@Test // GH-5065
888+
void converterShouldReadAnExplicitlyAssignedNullAsANullSetWhenUsingDBRefAnnotation() {
889+
org.bson.Document document = org.bson.Document.parse("{\"set\":null}");
890+
DBRefEmptySetDocument target = converter.read(DBRefEmptySetDocument.class, document);
891+
assertThat(target.set).isNull();
892+
}
893+
894+
@Test // GH-5065
895+
void converterShouldReadAnExplicitlyAssignedNullAsANullSetWhenUsingDBRefAnnotationUsingGetSet() {
896+
org.bson.Document document = org.bson.Document.parse("{\"set\":null}");
897+
DBRefEmptySetDocument target = converter.read(DBRefEmptySetDocument.class, document);
898+
assertThat(target.getSet()).isNull();
899+
}
900+
901+
static class EmptySetDocument {
902+
903+
Set<String> set;
904+
905+
public EmptySetDocument(Set<String> set) {
906+
this.set = set;
907+
}
908+
909+
Set<String> getSet() {
910+
return set;
911+
}
912+
}
913+
914+
static class DocumentReferenceEmptySetDocument {
915+
916+
@DocumentReference
917+
Set<String> set;
918+
919+
public DocumentReferenceEmptySetDocument(Set<String> set) {
920+
this.set = set;
921+
}
922+
923+
Set<String> getSet() {
924+
return set;
925+
}
926+
}
927+
928+
static class LazyDocumentReferenceEmptySetDocument {
929+
930+
@DocumentReference(lazy = true)
931+
Set<String> set;
932+
933+
public LazyDocumentReferenceEmptySetDocument(Set<String> set) {
934+
this.set = set;
935+
}
936+
937+
Set<String> getSet() {
938+
return set;
939+
}
940+
}
941+
942+
static class DBRefEmptySetDocument {
943+
944+
@DBRef
945+
Set<String> set;
946+
947+
public DBRefEmptySetDocument(Set<String> set) {
948+
this.set = set;
949+
}
950+
951+
Set<String> getSet() {
952+
return set;
953+
}
611954
}
612955
}
613956

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/ReferenceLookupDelegateUnitTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.springframework.data.mongodb.core.mapping.DocumentReference;
3434
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
3535
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
36-
import org.springframework.expression.EvaluationContext;
3736

3837
/**
3938
* Unit tests for {@link ReferenceLookupDelegate}.

0 commit comments

Comments
 (0)