14
14
import java .util .Map ;
15
15
16
16
import static com .google .common .collect .TreeMultimap .create ;
17
- import static junit .framework .TestCase .assertEquals ;
18
17
19
18
/**
20
19
* Unit tests to verify handling of various {@link Multimap}s.
@@ -47,7 +46,47 @@ public MultiMapWithIgnores()
47
46
}
48
47
}
49
48
50
- private static final String StringStringMultimap =
49
+ public static class ImmutableMultimapWrapper {
50
+
51
+ private ImmutableMultimap <String , MathOp > multimap ;
52
+
53
+ public ImmutableMultimapWrapper () {
54
+ }
55
+
56
+ public ImmutableMultimapWrapper (ImmutableMultimap <String , MathOp > f ) {
57
+ this .multimap = f ;
58
+ }
59
+
60
+ public ImmutableMultimap <String , MathOp > getMultimap () {
61
+ return multimap ;
62
+ }
63
+
64
+ public void setMultimap (ImmutableMultimap <String , MathOp > multimap ) {
65
+ this .multimap = multimap ;
66
+ }
67
+
68
+ @ Override
69
+ public int hashCode () {
70
+ int hash = 7 ;
71
+ hash = 97 * hash + (this .multimap != null ? this .multimap .hashCode () : 0 );
72
+ return hash ;
73
+ }
74
+
75
+ @ Override
76
+ public boolean equals (Object obj ) {
77
+ if (obj == null ) {
78
+ return false ;
79
+ }
80
+ if (getClass () != obj .getClass ()) {
81
+ return false ;
82
+ }
83
+ final ImmutableMultimapWrapper other = (ImmutableMultimapWrapper ) obj ;
84
+ return !(this .multimap != other .multimap && (this .multimap == null || !this .multimap .equals (other .multimap )));
85
+ }
86
+
87
+ }
88
+
89
+ private static final String STRING_STRING_MULTIMAP =
51
90
"{\" first\" :[\" abc\" ,\" abc\" ,\" foo\" ]," + "\" second\" :[\" bar\" ]}" ;
52
91
53
92
/*
@@ -164,28 +203,31 @@ public void testNullHandling() throws Exception
164
203
*/
165
204
166
205
/*
167
- public void testTreeMultimap() {
206
+ public void testTreeMultimap() throws IOException {
168
207
}
169
208
170
- public void testForwardingSortedSetMultimap() {
209
+ public void testForwardingSortedSetMultimap() throws IOException {
171
210
172
211
}
212
+ */
173
213
174
- public void testImmutableSetMultimap() {
175
- // TODO look at others
214
+ public void testImmutableSetMultimap () throws IOException {
215
+ SetMultimap <String , String > map =
216
+ _verifyMultiMapRead (new TypeReference <ImmutableSetMultimap <String , String >>() {
217
+ });
218
+ assertTrue (map instanceof ImmutableSetMultimap );
176
219
}
177
- */
178
220
179
221
public void testHashMultimap () throws IOException {
180
222
SetMultimap <String , String > map =
181
- setBasedHelper (new TypeReference <HashMultimap <String , String >>() {
223
+ _verifyMultiMapRead (new TypeReference <HashMultimap <String , String >>() {
182
224
});
183
225
assertTrue (map instanceof HashMultimap );
184
226
}
185
227
186
228
public void testLinkedHashMultimap () throws IOException {
187
229
SetMultimap <String , String > map =
188
- setBasedHelper (new TypeReference <LinkedHashMultimap <String , String >>() {
230
+ _verifyMultiMapRead (new TypeReference <LinkedHashMultimap <String , String >>() {
189
231
});
190
232
assertTrue (map instanceof LinkedHashMultimap );
191
233
}
@@ -195,10 +237,10 @@ public void testForwardingSetMultimap() {
195
237
}
196
238
*/
197
239
198
- private SetMultimap <String , String > setBasedHelper (TypeReference <?> type )
240
+ private SetMultimap <String , String > _verifyMultiMapRead (TypeReference <?> type )
199
241
throws IOException
200
242
{
201
- SetMultimap <String , String > map = MAPPER .readValue (StringStringMultimap , type );
243
+ SetMultimap <String , String > map = MAPPER .readValue (STRING_STRING_MULTIMAP , type );
202
244
assertEquals (3 , map .size ());
203
245
assertTrue (map .containsEntry ("first" , "abc" ));
204
246
assertTrue (map .containsEntry ("first" , "foo" ));
@@ -232,7 +274,7 @@ public void testMultimapWithIgnores() throws IOException {
232
274
}
233
275
234
276
private ListMultimap <String , String > listBasedHelper (TypeReference <?> type ) throws IOException {
235
- ListMultimap <String , String > map = MAPPER .readValue (StringStringMultimap , type );
277
+ ListMultimap <String , String > map = MAPPER .readValue (STRING_STRING_MULTIMAP , type );
236
278
assertEquals (4 , map .size ());
237
279
assertTrue (map .remove ("first" , "abc" ));
238
280
assertTrue (map .containsEntry ("first" , "abc" ));
@@ -267,44 +309,4 @@ public void testPolymorphicValue() throws IOException {
267
309
ImmutableMultimapWrapper output = MAPPER .readValue (json , ImmutableMultimapWrapper .class );
268
310
assertEquals (input , output );
269
311
}
270
-
271
- public static class ImmutableMultimapWrapper {
272
-
273
- private ImmutableMultimap <String , MathOp > multimap ;
274
-
275
- public ImmutableMultimapWrapper () {
276
- }
277
-
278
- public ImmutableMultimapWrapper (ImmutableMultimap <String , MathOp > f ) {
279
- this .multimap = f ;
280
- }
281
-
282
- public ImmutableMultimap <String , MathOp > getMultimap () {
283
- return multimap ;
284
- }
285
-
286
- public void setMultimap (ImmutableMultimap <String , MathOp > multimap ) {
287
- this .multimap = multimap ;
288
- }
289
-
290
- @ Override
291
- public int hashCode () {
292
- int hash = 7 ;
293
- hash = 97 * hash + (this .multimap != null ? this .multimap .hashCode () : 0 );
294
- return hash ;
295
- }
296
-
297
- @ Override
298
- public boolean equals (Object obj ) {
299
- if (obj == null ) {
300
- return false ;
301
- }
302
- if (getClass () != obj .getClass ()) {
303
- return false ;
304
- }
305
- final ImmutableMultimapWrapper other = (ImmutableMultimapWrapper ) obj ;
306
- return !(this .multimap != other .multimap && (this .multimap == null || !this .multimap .equals (other .multimap )));
307
- }
308
-
309
- }
310
312
}
0 commit comments