1 /*
2  * Copyright (C) 2013 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 
15 package com.google.common.collect.testing.google;
16 
17 import static com.google.common.collect.testing.features.CollectionSize.ONE;
18 import static com.google.common.collect.testing.features.CollectionSize.ZERO;
19 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
20 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
21 
22 import com.google.common.annotations.GwtCompatible;
23 import com.google.common.collect.Multimap;
24 import com.google.common.collect.testing.features.CollectionSize;
25 import com.google.common.collect.testing.features.MapFeature;
26 
27 /**
28  * Tester for {@code Multimap.toString()}.
29  *
30  * @author Louis Wasserman
31  */
32 @GwtCompatible
33 public class MultimapToStringTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
34   @CollectionSize.Require(ZERO)
testToStringEmpty()35   public void testToStringEmpty() {
36     assertEquals("{}", multimap().toString());
37   }
38 
39   @CollectionSize.Require(ONE)
testToStringSingleton()40   public void testToStringSingleton() {
41     assertEquals("{" + sampleKeys().e0 + "=[" + sampleValues().e0 + "]}", multimap().toString());
42   }
43 
44   @CollectionSize.Require(absent = ZERO)
45   @MapFeature.Require(ALLOWS_NULL_KEYS)
testToStringWithNullKey()46   public void testToStringWithNullKey() {
47     initMultimapWithNullKey();
48     testToStringMatchesAsMap();
49   }
50 
51   @CollectionSize.Require(absent = ZERO)
52   @MapFeature.Require(ALLOWS_NULL_VALUES)
testToStringWithNullValue()53   public void testToStringWithNullValue() {
54     initMultimapWithNullValue();
55     testToStringMatchesAsMap();
56   }
57 
testToStringMatchesAsMap()58   public void testToStringMatchesAsMap() {
59     assertEquals(multimap().asMap().toString(), multimap().toString());
60   }
61 }
62