1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.collect;
18
19 import com.google.common.annotations.GwtCompatible;
20
21 import junit.framework.TestCase;
22
23
24
25
26
27
28 @GwtCompatible(emulated = true)
29 public class HashMultimapTest extends TestCase {
30
31
32
33
34
35 public void testCreate() {
36 HashMultimap<String, Integer> multimap = HashMultimap.create();
37 multimap.put("foo", 1);
38 multimap.put("bar", 2);
39 multimap.put("foo", 3);
40 assertEquals(ImmutableSet.of(1, 3), multimap.get("foo"));
41 assertEquals(2, multimap.expectedValuesPerKey);
42 }
43
44 public void testCreateFromMultimap() {
45 HashMultimap<String, Integer> multimap = HashMultimap.create();
46 multimap.put("foo", 1);
47 multimap.put("bar", 2);
48 multimap.put("foo", 3);
49 HashMultimap<String, Integer> copy = HashMultimap.create(multimap);
50 assertEquals(multimap, copy);
51 assertEquals(2, copy.expectedValuesPerKey);
52 }
53
54 public void testCreateFromSizes() {
55 HashMultimap<String, Integer> multimap = HashMultimap.create(20, 15);
56 multimap.put("foo", 1);
57 multimap.put("bar", 2);
58 multimap.put("foo", 3);
59 assertEquals(ImmutableSet.of(1, 3), multimap.get("foo"));
60 assertEquals(15, multimap.expectedValuesPerKey);
61 }
62
63 public void testCreateFromIllegalSizes() {
64 try {
65 HashMultimap.create(-20, 15);
66 fail();
67 } catch (IllegalArgumentException expected) {}
68
69 try {
70 HashMultimap.create(20, -15);
71 fail();
72 } catch (IllegalArgumentException expected) {}
73 }
74
75 public void testEmptyMultimapsEqual() {
76 Multimap<String, Integer> setMultimap = HashMultimap.create();
77 Multimap<String, Integer> listMultimap = ArrayListMultimap.create();
78 assertTrue(setMultimap.equals(listMultimap));
79 assertTrue(listMultimap.equals(setMultimap));
80 }
81 }
82