@@ -37,23 +37,6 @@ void get_ExtendedAttributeKey(
3737 actualValue = mapValue ;
3838 }
3939
40- if (extendedAttributeKey .getType () == ExtendedAttributeType .BYTE_ARRAY ) {
41- assertThat ((byte []) actualValue )
42- .describedAs (key + "(" + extendedAttributeKey .getType () + ")" )
43- .containsExactly ((byte []) value );
44- return ;
45- }
46- if (extendedAttributeKey .getType () == ExtendedAttributeType .VALUE_ARRAY ) {
47- @ SuppressWarnings ("unchecked" )
48- List <Value <?>> actualList = (List <Value <?>>) actualValue ;
49- @ SuppressWarnings ("unchecked" )
50- List <Value <?>> expectedList = (List <Value <?>>) value ;
51- assertThat (actualList )
52- .describedAs (key + "(" + extendedAttributeKey .getType () + ")" )
53- .isEqualTo (expectedList );
54- return ;
55- }
56-
5740 assertThat (actualValue )
5841 .describedAs (key + "(" + extendedAttributeKey .getType () + ")" )
5942 .isEqualTo (value );
@@ -90,6 +73,20 @@ void forEach(ExtendedAttributes extendedAttributes, Map<String, Object> expected
9073 assertMapEquals (seenEntries , expectedMap );
9174 }
9275
76+ @ SuppressWarnings ("unchecked" )
77+ private static void assertMapEquals (Map <String , Object > actual , Map <String , Object > expected ) {
78+ assertThat (actual .keySet ()).isEqualTo (expected .keySet ());
79+ actual .forEach (
80+ (key , value ) -> {
81+ Object expectedValue = expected .get (key );
82+ if (value instanceof Map && expectedValue instanceof Map ) {
83+ assertMapEquals ((Map <String , Object >) value , (Map <String , Object >) expectedValue );
84+ return ;
85+ }
86+ assertThat (value ).isEqualTo (expectedValue );
87+ });
88+ }
89+
9390 @ ParameterizedTest
9491 @ MethodSource ("attributesArgs" )
9592 void size (ExtendedAttributes extendedAttributes , Map <String , Object > expectedMap ) {
@@ -114,55 +111,16 @@ private static void assertEquals(
114111 assertThat (actual .size ()).isEqualTo (expected .size ());
115112 actual .forEach (
116113 (key , value ) -> {
117- if (key .getType () == ExtendedAttributeType .BYTE_ARRAY ) {
118- assertThat ((byte []) value ).containsExactly ((byte []) expected .get (key .getKey ()));
119- return ;
120- }
121- if (key .getType () == ExtendedAttributeType .VALUE_ARRAY ) {
122- assertThat ((List <Value <?>>) value )
123- .isEqualTo ((List <Value <?>>) expected .get (key .getKey ()));
124- return ;
125- }
126114 if (key .getType () == ExtendedAttributeType .MAP ) {
127115 assertEquals (
128116 ((ExtendedAttributes ) value ).asMap (),
129117 (Map <String , Object >) expected .get (key .getKey ()));
130118 return ;
131119 }
132- assertThat (expected .get (key .getKey ())). isEqualTo ( value );
120+ assertThat (value ). isEqualTo ( expected .get (key .getKey ()));
133121 });
134122 }
135123
136- @ SuppressWarnings ("unchecked" )
137- private static void assertMapEquals (Map <String , Object > actual , Map <String , Object > expected ) {
138- assertThat (actual .keySet ()).isEqualTo (expected .keySet ());
139- actual .forEach (
140- (key , value ) -> {
141- Object expectedValue = expected .get (key );
142- if (value instanceof byte [] && expectedValue instanceof byte []) {
143- assertThat ((byte []) value ).containsExactly ((byte []) expectedValue );
144- return ;
145- }
146- if (isValueArray (value ) && isValueArray (expectedValue )) {
147- assertThat ((List <Value <?>>) value ).isEqualTo ((List <Value <?>>) expectedValue );
148- return ;
149- }
150- if (value instanceof Map && expectedValue instanceof Map ) {
151- assertMapEquals ((Map <String , Object >) value , (Map <String , Object >) expectedValue );
152- return ;
153- }
154- assertThat (expectedValue ).isEqualTo (value );
155- });
156- }
157-
158- private static boolean isValueArray (Object value ) {
159- if (!(value instanceof List )) {
160- return false ;
161- }
162- List <?> list = (List <?>) value ;
163- return !list .isEmpty () && list .get (0 ) instanceof Value ;
164- }
165-
166124 @ ParameterizedTest
167125 @ MethodSource ("attributesArgs" )
168126 void asAttributes (ExtendedAttributes extendedAttributes , Map <String , Object > expectedMap ) {
@@ -182,6 +140,14 @@ void asAttributes(ExtendedAttributes extendedAttributes, Map<String, Object> exp
182140 assertThat (attributes .size ()).isEqualTo (expectedSize );
183141 }
184142
143+ private static boolean isValueArray (Object value ) {
144+ if (!(value instanceof List )) {
145+ return false ;
146+ }
147+ List <?> list = (List <?>) value ;
148+ return !list .isEmpty () && list .get (0 ) instanceof Value ;
149+ }
150+
185151 @ ParameterizedTest
186152 @ MethodSource ("attributesArgs" )
187153 void toBuilder (ExtendedAttributes extendedAttributes , Map <String , Object > expectedMap ) {
0 commit comments