@@ -22,182 +22,200 @@ public class MultiValuedMapUnitTest {
2222 public void givenMultiValuesMap_whenPuttingMultipleValuesUsingPutMethod_thenReturningAllValues () {
2323 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
2424
25- map .put ("key" , "value1" );
26- map .put ("key" , "value2" );
27- map .put ("key" , "value2" );
25+ map .put ("fruits" , "apple" );
26+ map .put ("fruits" , "orange" );
2827
29- assertThat ((Collection <String >) map .get ("key" )).containsExactly ("value1" , "value2" , "value2" );
28+ assertThat ((Collection <String >) map .get ("fruits" )).containsExactly ("apple" , "orange" );
29+
3030 }
3131
3232 @ Test
3333 public void givenMultiValuesMap_whenPuttingMultipleValuesUsingPutAllMethod_thenReturningAllValues () {
3434 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
35+
36+ map .putAll ("vehicles" , Arrays .asList ("car" , "bike" ));
3537
36- map .putAll ("key" , Arrays .asList ("value1" , "value2" , "value2" ));
37-
38- assertThat ((Collection <String >) map .get ("key" )).containsExactly ("value1" , "value2" , "value2" );
38+ assertThat ((Collection <String >) map .get ("vehicles" )).containsExactly ("car" , "bike" );
39+
3940 }
4041
4142 @ Test
4243 public void givenMultiValuesMap_whenGettingValueUsingGetMethod_thenReturningValue () {
4344 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
44- map .put ("key" , "value" );
45+
46+ map .put ("fruits" , "apple" );
4547
46- assertThat ((Collection <String >) map .get ("key " )).containsExactly ("value " );
48+ assertThat ((Collection <String >) map .get ("fruits " )).containsExactly ("apple " );
4749 }
4850
4951 @ Test
5052 public void givenMultiValuesMap_whenUsingEntriesMethod_thenReturningMappings () {
5153 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
52- map .put ("key " , "value1 " );
53- map .put ("key " , "value2 " );
54-
54+ map .put ("fruits " , "apple " );
55+ map .put ("fruits " , "orange " );
56+
5557 Collection <Entry <String , String >> entries = (Collection <Entry <String , String >>) map .entries ();
5658
5759 for (Map .Entry <String ,String > entry : entries ) {
58- assertThat (entry .getKey ()).contains ("key " );
59- assertTrue (entry .getValue ().equals ("value1 " ) || entry .getValue ().equals ("value2 " ) );
60+ assertThat (entry .getKey ()).contains ("fruits " );
61+ assertTrue (entry .getValue ().equals ("apple " ) || entry .getValue ().equals ("orange " ) );
6062 }
6163 }
6264
6365 @ Test
6466 public void givenMultiValuesMap_whenUsingKeysMethod_thenReturningAllKeys () {
6567 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
66- map .put ("key" , "value" );
67- map .put ("key1" , "value1" );
68- map .put ("key2" , "value2" );
68+
69+ map .put ("fruits" , "apple" );
70+ map .put ("fruits" , "orange" );
71+ map .put ("vehicles" , "car" );
72+ map .put ("vehicles" , "bike" );
6973
70- assertThat (((Collection <String >) map .keys ())).contains ("key " , "key1" , "key2 " );
74+ assertThat (((Collection <String >) map .keys ())).contains ("fruits " , "vehicles " );
7175 }
7276
7377 @ Test
7478 public void givenMultiValuesMap_whenUsingKeySetMethod_thenReturningAllKeys () {
7579 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
76- map .put ("key" , "value" );
77- map .put ("key1" , "value1" );
78- map .put ("key2" , "value2" );
80+
81+ map .put ("fruits" , "apple" );
82+ map .put ("fruits" , "orange" );
83+ map .put ("vehicles" , "car" );
84+ map .put ("vehicles" , "bike" );
7985
80- assertThat ((Collection <String >) map .keySet ()).contains ("key" , "key1" , "key2" );
86+ assertThat ((Collection <String >) map .keySet ()).contains ("fruits" , "vehicles" );
87+
8188 }
8289
8390 @ Test
8491 public void givenMultiValuesMap_whenUsingValuesMethod_thenReturningAllValues () {
8592 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
86- map .put ("key" , "value" );
87- map .put ("key1" , "value1" );
88- map .put ("key2" , "value2" );
93+
94+ map .put ("fruits" , "apple" );
95+ map .put ("fruits" , "orange" );
96+ map .put ("vehicles" , "car" );
97+ map .put ("vehicles" , "bike" );
8998
90- assertThat (((Collection <String >) map .values ())).contains ("value " , "value1 " , "value2 " );
99+ assertThat (((Collection <String >) map .values ())).contains ("apple " , "orange " , "car" , "bike " );
91100 }
92101
93102 @ Test
94103 public void givenMultiValuesMap_whenUsingRemoveMethod_thenReturningUpdatedMap () {
95104 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
96- map .put ("key" , "value" );
97- map .put ("key1" , "value1" );
98- map .put ("key2" , "value2" );
99- assertThat (((Collection <String >) map .values ())).contains ("value" , "value1" , "value2" );
105+
106+ map .put ("fruits" , "apple" );
107+ map .put ("fruits" , "orange" );
108+ map .put ("vehicles" , "car" );
109+ map .put ("vehicles" , "bike" );
110+ assertThat (((Collection <String >) map .values ())).contains ("apple" , "orange" , "car" , "bike" );
100111
101- map .remove ("key " );
112+ map .remove ("fruits " );
102113
103- assertThat (((Collection <String >) map .values ())).contains ("value1" , "value2" );
114+ assertThat (((Collection <String >) map .values ())).contains ("car" , "bike" );
115+
104116 }
105117
106118 @ Test
107119 public void givenMultiValuesMap_whenUsingRemoveMappingMethod_thenReturningUpdatedMapAfterMappingRemoved () {
108120 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
109- map .put ("key" , "value" );
110- map .put ("key1" , "value1" );
111- map .put ("key2" , "value2" );
112- assertThat (((Collection <String >) map .values ())).contains ("value" , "value1" , "value2" );
121+
122+ map .put ("fruits" , "apple" );
123+ map .put ("fruits" , "orange" );
124+ map .put ("vehicles" , "car" );
125+ map .put ("vehicles" , "bike" );
126+ assertThat (((Collection <String >) map .values ())).contains ("apple" , "orange" , "car" , "bike" );
113127
114- map .removeMapping ("key " , "value " );
128+ map .removeMapping ("fruits " , "apple " );
115129
116- assertThat (((Collection <String >) map .values ())).contains ("value1 " , "value2 " );
130+ assertThat (((Collection <String >) map .values ())).contains ("orange " , "car" , "bike " );
117131 }
118132
119133 @ Test
120134 public void givenMultiValuesMap_whenUsingClearMethod_thenReturningEmptyMap () {
121135 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
122- map .put ("key" , "value" );
123- map .put ("key1" , "value1" );
124- map .put ("key2" , "value2" );
125- assertThat (((Collection <String >) map .values ())).contains ("value" , "value1" , "value2" );
136+ map .put ("fruits" , "apple" );
137+ map .put ("fruits" , "orange" );
138+ map .put ("vehicles" , "car" );
139+ map .put ("vehicles" , "bike" );
140+ assertThat (((Collection <String >) map .values ())).contains ("apple" , "orange" , "car" , "bike" );
126141
127142 map .clear ();
128-
143+
129144 assertTrue (map .isEmpty ());
130145 }
131146
132147 @ Test
133148 public void givenMultiValuesMap_whenUsingContainsKeyMethod_thenReturningTrue () {
134149 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
135- map .put ("key" , "value" );
136- map .put ("key1" , "value1" );
137- map .put ("key2" , "value2" );
150+ map .put ("fruits" , "apple" );
151+ map .put ("fruits" , "orange" );
152+ map .put ("vehicles" , "car" );
153+ map .put ("vehicles" , "bike" );
138154
139- assertTrue (map .containsKey ("key " ));
155+ assertTrue (map .containsKey ("fruits " ));
140156 }
141157
142158 @ Test
143159 public void givenMultiValuesMap_whenUsingContainsValueMethod_thenReturningTrue () {
144160 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
145- map .put ("key" , "value" );
146- map .put ("key1" , "value1" );
147- map .put ("key2" , "value2" );
161+ map .put ("fruits" , "apple" );
162+ map .put ("fruits" , "orange" );
163+ map .put ("vehicles" , "car" );
164+ map .put ("vehicles" , "bike" );
148165
149- assertTrue (map .containsValue ("value " ));
166+ assertTrue (map .containsValue ("orange " ));
150167 }
151168
152169 @ Test
153170 public void givenMultiValuesMap_whenUsingIsEmptyMethod_thenReturningFalse () {
154171 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
155- map .put ("key" , "value" );
156- map .put ("key1" , "value1" );
157- map .put ("key2" , "value2" );
172+ map .put ("fruits" , "apple" );
173+ map .put ("fruits" , "orange" );
174+ map .put ("vehicles" , "car" );
175+ map .put ("vehicles" , "bike" );
158176
159177 assertFalse (map .isEmpty ());
160178 }
161179
162180 @ Test
163181 public void givenMultiValuesMap_whenUsingSizeMethod_thenReturningElementCount () {
164182 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
165- map .put ("key" , "value" );
166- map .put ("key1" , "value1" );
167- map .put ("key2" , "value2" );
183+ map .put ("fruits" , "apple" );
184+ map .put ("fruits" , "orange" );
185+ map .put ("vehicles" , "car" );
186+ map .put ("vehicles" , "bike" );
168187
169- assertEquals (3 , map .size ());
188+ assertEquals (4 , map .size ());
170189 }
171190
172191 @ Test
173192 public void givenArrayListValuedHashMap_whenPuttingDoubleValues_thenReturningAllValues () {
174193 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
194+ map .put ("fruits" , "apple" );
195+ map .put ("fruits" , "orange" );
196+ map .put ("fruits" , "orange" );
175197
176- map .put ("key" , "value1" );
177- map .put ("key" , "value2" );
178- map .put ("key" , "value2" );
179-
180- assertThat ((Collection <String >) map .get ("key" )).containsExactly ("value1" , "value2" , "value2" );
198+ assertThat ((Collection <String >) map .get ("fruits" )).containsExactly ("apple" , "orange" , "orange" );
181199 }
182200
183201 @ Test
184202 public void givenHashSetValuedHashMap_whenPuttingTwiceTheSame_thenReturningOneValue () {
185203 MultiValuedMap <String , String > map = new HashSetValuedHashMap <>();
186-
187- map .put ("key1" , "value1" );
188- map .put ("key1" , "value1" );
189-
190- assertThat ((Collection <String >) map .get ("key1" )).containsExactly ("value1" );
204+ map .put ("fruits" , "apple" );
205+ map .put ("fruits" , "apple" );
206+
207+ assertThat ((Collection <String >) map .get ("fruits" )).containsExactly ("apple" );
191208 }
192209
193210 @ Test (expected = UnsupportedOperationException .class )
194211 public void givenUnmodifiableMultiValuedMap_whenInserting_thenThrowingException () {
195212 MultiValuedMap <String , String > map = new ArrayListValuedHashMap <>();
196- map .put ("key " , "value1 " );
197- map .put ("key " , "value2 " );
213+ map .put ("fruits " , "apple " );
214+ map .put ("fruits " , "orange " );
198215 MultiValuedMap <String , String > immutableMap = MultiMapUtils .unmodifiableMultiValuedMap (map );
199216
200- immutableMap .put ("key" , "value3" );
217+ immutableMap .put ("fruits" , "banana" );
218+
201219 }
202220
203221
0 commit comments