1414import java .util .Map ;
1515
1616import static com .google .common .collect .TreeMultimap .create ;
17- import static junit .framework .TestCase .assertEquals ;
1817
1918/**
2019 * Unit tests to verify handling of various {@link Multimap}s.
@@ -47,7 +46,47 @@ public MultiMapWithIgnores()
4746 }
4847 }
4948
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 =
5190 "{\" first\" :[\" abc\" ,\" abc\" ,\" foo\" ]," + "\" second\" :[\" bar\" ]}" ;
5291
5392 /*
@@ -164,28 +203,31 @@ public void testNullHandling() throws Exception
164203 */
165204
166205 /*
167- public void testTreeMultimap() {
206+ public void testTreeMultimap() throws IOException {
168207 }
169208
170- public void testForwardingSortedSetMultimap() {
209+ public void testForwardingSortedSetMultimap() throws IOException {
171210
172211 }
212+ */
173213
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 );
176219 }
177- */
178220
179221 public void testHashMultimap () throws IOException {
180222 SetMultimap <String , String > map =
181- setBasedHelper (new TypeReference <HashMultimap <String , String >>() {
223+ _verifyMultiMapRead (new TypeReference <HashMultimap <String , String >>() {
182224 });
183225 assertTrue (map instanceof HashMultimap );
184226 }
185227
186228 public void testLinkedHashMultimap () throws IOException {
187229 SetMultimap <String , String > map =
188- setBasedHelper (new TypeReference <LinkedHashMultimap <String , String >>() {
230+ _verifyMultiMapRead (new TypeReference <LinkedHashMultimap <String , String >>() {
189231 });
190232 assertTrue (map instanceof LinkedHashMultimap );
191233 }
@@ -195,10 +237,10 @@ public void testForwardingSetMultimap() {
195237 }
196238 */
197239
198- private SetMultimap <String , String > setBasedHelper (TypeReference <?> type )
240+ private SetMultimap <String , String > _verifyMultiMapRead (TypeReference <?> type )
199241 throws IOException
200242 {
201- SetMultimap <String , String > map = MAPPER .readValue (StringStringMultimap , type );
243+ SetMultimap <String , String > map = MAPPER .readValue (STRING_STRING_MULTIMAP , type );
202244 assertEquals (3 , map .size ());
203245 assertTrue (map .containsEntry ("first" , "abc" ));
204246 assertTrue (map .containsEntry ("first" , "foo" ));
@@ -232,7 +274,7 @@ public void testMultimapWithIgnores() throws IOException {
232274 }
233275
234276 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 );
236278 assertEquals (4 , map .size ());
237279 assertTrue (map .remove ("first" , "abc" ));
238280 assertTrue (map .containsEntry ("first" , "abc" ));
@@ -267,44 +309,4 @@ public void testPolymorphicValue() throws IOException {
267309 ImmutableMultimapWrapper output = MAPPER .readValue (json , ImmutableMultimapWrapper .class );
268310 assertEquals (input , output );
269311 }
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- }
310312}
0 commit comments