@@ -600,4 +600,111 @@ void emptyValueArrayRetrievedAsAnyArrayType() {
600600 assertThat (attributes .get (doubleArrayKey ("key" ))).isEmpty ();
601601 assertThat (attributes .get (booleanArrayKey ("key" ))).isEmpty ();
602602 }
603+
604+ @ Test
605+ void getNullKey () {
606+ ExtendedAttributes attributes = ExtendedAttributes .builder ().put ("key" , "value" ).build ();
607+ assertThat (attributes .get ((ExtendedAttributeKey <?>) null )).isNull ();
608+ }
609+
610+ @ Test
611+ void putNullKey () {
612+ ExtendedAttributes attributes =
613+ ExtendedAttributes .builder ().put ((ExtendedAttributeKey <String >) null , "value" ).build ();
614+ assertThat (attributes .isEmpty ()).isTrue ();
615+ }
616+
617+ @ Test
618+ void putNullValue () {
619+ ExtendedAttributes attributes =
620+ ExtendedAttributes .builder ().put (stringKey ("key" ), null ).build ();
621+ assertThat (attributes .isEmpty ()).isTrue ();
622+ }
623+
624+ @ Test
625+ void putEmptyKey () {
626+ ExtendedAttributes attributes =
627+ ExtendedAttributes .builder ().put (stringKey ("" ), "value" ).build ();
628+ assertThat (attributes .isEmpty ()).isTrue ();
629+ }
630+
631+ @ Test
632+ void extendedAttributesNotConvertibleToValue () {
633+ ExtendedAttributes nested = ExtendedAttributes .builder ().put ("child" , "value" ).build ();
634+ ExtendedAttributes attributes =
635+ ExtendedAttributes .builder ()
636+ .put (ExtendedAttributeKey .extendedAttributesKey ("key" ), nested )
637+ .build ();
638+
639+ // Getting as VALUE should return null since EXTENDED_ATTRIBUTES cannot be converted to Value
640+ assertThat (attributes .get (valueKey ("key" ))).isNull ();
641+ }
642+
643+ @ Test
644+ void complexValueWithKeyValueList () {
645+ // KEY_VALUE_LIST should be kept as VALUE type
646+ Value <?> kvListValue = Value .of (Collections .emptyMap ());
647+ ExtendedAttributes attributes =
648+ ExtendedAttributes .builder ().put (valueKey ("key" ), kvListValue ).build ();
649+
650+ // Should be stored as VALUE type
651+ assertThat (attributes .get (valueKey ("key" ))).isEqualTo (kvListValue );
652+
653+ // forEach should show VALUE type
654+ Map <ExtendedAttributeKey <?>, Object > entriesSeen = new HashMap <>();
655+ attributes .forEach (entriesSeen ::put );
656+ assertThat (entriesSeen ).containsExactly (entry (valueKey ("key" ), kvListValue ));
657+ }
658+
659+ @ Test
660+ void complexValueWithBytes () {
661+ // BYTES should be kept as VALUE type
662+ Value <?> bytesValue = Value .of (new byte [] {1 , 2 , 3 });
663+ ExtendedAttributes attributes =
664+ ExtendedAttributes .builder ().put (valueKey ("key" ), bytesValue ).build ();
665+
666+ // Should be stored as VALUE type
667+ assertThat (attributes .get (valueKey ("key" ))).isEqualTo (bytesValue );
668+
669+ // forEach should show VALUE type
670+ Map <ExtendedAttributeKey <?>, Object > entriesSeen = new HashMap <>();
671+ attributes .forEach (entriesSeen ::put );
672+ assertThat (entriesSeen ).containsExactly (entry (valueKey ("key" ), bytesValue ));
673+ }
674+
675+ @ Test
676+ void complexValueWithNonHomogeneousArray () {
677+ // Non-homogeneous array should be kept as VALUE type
678+ Value <?> mixedArray = Value .of (Arrays .asList (Value .of ("string" ), Value .of (123L )));
679+ ExtendedAttributes attributes =
680+ ExtendedAttributes .builder ().put (valueKey ("key" ), mixedArray ).build ();
681+
682+ // Should be stored as VALUE type
683+ assertThat (attributes .get (valueKey ("key" ))).isEqualTo (mixedArray );
684+
685+ // forEach should show VALUE type
686+ Map <ExtendedAttributeKey <?>, Object > entriesSeen = new HashMap <>();
687+ attributes .forEach (entriesSeen ::put );
688+ assertThat (entriesSeen ).containsExactly (entry (valueKey ("key" ), mixedArray ));
689+ }
690+
691+ @ Test
692+ void complexValueWithNestedArray () {
693+ // Array containing arrays should be kept as VALUE type
694+ Value <?> nestedArray =
695+ Value .of (
696+ Arrays .asList (
697+ Value .of (Arrays .asList (Value .of ("a" ), Value .of ("b" ))),
698+ Value .of (Arrays .asList (Value .of ("c" ), Value .of ("d" )))));
699+ ExtendedAttributes attributes =
700+ ExtendedAttributes .builder ().put (valueKey ("key" ), nestedArray ).build ();
701+
702+ // Should be stored as VALUE type
703+ assertThat (attributes .get (valueKey ("key" ))).isEqualTo (nestedArray );
704+
705+ // forEach should show VALUE type
706+ Map <ExtendedAttributeKey <?>, Object > entriesSeen = new HashMap <>();
707+ attributes .forEach (entriesSeen ::put );
708+ assertThat (entriesSeen ).containsExactly (entry (valueKey ("key" ), nestedArray ));
709+ }
603710}
0 commit comments