1/*
2 * Copyright (C) 2009 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.common.collect;
18
19import java.util.Collections;
20
21/**
22 * Unit test for {@link ForwardingMultimap}.
23 *
24 * @author Hayward Chan
25 */
26public class ForwardingMultimapTest extends ForwardingTestCase {
27
28  // Package-private so subclasses can access this variable.
29  Multimap<String, Boolean> forward;
30
31  @Override public void setUp() throws Exception {
32    super.setUp();
33    /*
34     * Class parameters must be raw, so we can't create a proxy with generic
35     * type arguments. The created proxy only records calls and returns null, so
36     * the type is irrelevant at runtime.
37     */
38    @SuppressWarnings("unchecked")
39    final Multimap<String, Boolean> multimap =
40        createProxyInstance(Multimap.class);
41    forward = new ForwardingMultimap<String, Boolean>() {
42      @Override protected Multimap<String, Boolean> delegate() {
43        return multimap;
44      }
45    };
46  }
47
48  public void testSize() {
49    forward.size();
50    assertEquals("[size]", getCalls());
51  }
52
53  public void testIsEmpty() {
54    forward.isEmpty();
55    assertEquals("[isEmpty]", getCalls());
56  }
57
58  public void testContainsKey_Object() {
59    forward.containsKey("asdf");
60    assertEquals("[containsKey(Object)]", getCalls());
61  }
62
63  public void testContainsValue_Object() {
64    forward.containsValue("asdf");
65    assertEquals("[containsValue(Object)]", getCalls());
66  }
67
68  public void testContainsEntry_Object_Object() {
69    forward.containsEntry("asdf", false);
70    assertEquals("[containsEntry(Object,Object)]", getCalls());
71  }
72
73  public void testPut_Key_Value() {
74    forward.put("asdf", true);
75    assertEquals("[put(Object,Object)]", getCalls());
76  }
77
78  public void testRemove_Key_Value() {
79    forward.remove("asdf", false);
80    assertEquals("[remove(Object,Object)]", getCalls());
81  }
82
83  public void testPutAll_Key_Iterable() {
84    forward.remove("asfd", Collections.<Boolean>emptyList());
85    assertEquals("[remove(Object,Object)]", getCalls());
86  }
87
88  public void testPutAll_Multimap() {
89    forward.putAll(ArrayListMultimap.<String, Boolean>create());
90    assertEquals("[putAll(Multimap)]", getCalls());
91  }
92
93  public void testReplaceValues_Key_Iterable() {
94    forward.replaceValues("key", Collections.<Boolean>emptyList());
95    assertEquals("[replaceValues(Object,Iterable)]", getCalls());
96  }
97
98  public void testRemoveAll_Object() {
99    forward.removeAll("key");
100    assertEquals("[removeAll(Object)]", getCalls());
101  }
102
103  public void testClear() {
104    forward.clear();
105    assertEquals("[clear]", getCalls());
106  }
107
108  public void testGet_Key() {
109    forward.get(null);
110    assertEquals("[get(Object)]", getCalls());
111  }
112
113  public void testKeySet() {
114    forward.keySet();
115    assertEquals("[keySet]", getCalls());
116  }
117
118  public void testKeys() {
119    forward.keys();
120    assertEquals("[keys]", getCalls());
121  }
122
123  public void testValues() {
124    forward.values();
125    assertEquals("[values]", getCalls());
126  }
127
128  public void testEntries() {
129    forward.entries();
130    assertEquals("[entries]", getCalls());
131  }
132
133  public void testAsMap() {
134    forward.asMap();
135    assertEquals("[asMap]", getCalls());
136  }
137
138  public void testEquals() {
139    forward.equals(null);
140    assertEquals("[equals(Object)]", getCalls());
141  }
142
143  public void testHashCode() {
144    forward.hashCode();
145    assertEquals("[hashCode]", getCalls());
146  }
147
148  public void testToString() {
149    forward.toString();
150    assertEquals("[toString]", getCalls());
151  }
152}
153