001/*
002 * Copyright (C) 2013 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014
015package com.google.common.collect.testing.google;
016
017import static com.google.common.collect.testing.features.CollectionFeature.NON_STANDARD_TOSTRING;
018import static com.google.common.collect.testing.features.CollectionSize.ONE;
019import static com.google.common.collect.testing.features.CollectionSize.ZERO;
020import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
021import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
022
023import com.google.common.annotations.GwtCompatible;
024import com.google.common.collect.Multimap;
025import com.google.common.collect.testing.features.CollectionFeature;
026import com.google.common.collect.testing.features.CollectionSize;
027import com.google.common.collect.testing.features.MapFeature;
028
029/**
030 * Tester for {@code Multimap.toString()}.
031 *
032 * @author Louis Wasserman
033 */
034@GwtCompatible
035public class MultimapToStringTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
036  @CollectionSize.Require(ZERO)
037  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
038  public void testToStringEmpty() {
039    assertEquals("{}", multimap().toString());
040  }
041
042  @CollectionSize.Require(ONE)
043  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
044  public void testToStringSingleton() {
045    assertEquals("{" + k0() + "=[" + v0() + "]}", multimap().toString());
046  }
047
048  @CollectionSize.Require(absent = ZERO)
049  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
050  @MapFeature.Require(ALLOWS_NULL_KEYS)
051  public void testToStringWithNullKey() {
052    initMultimapWithNullKey();
053    testToStringMatchesAsMap();
054  }
055
056  @CollectionSize.Require(absent = ZERO)
057  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
058  @MapFeature.Require(ALLOWS_NULL_VALUES)
059  public void testToStringWithNullValue() {
060    initMultimapWithNullValue();
061    testToStringMatchesAsMap();
062  }
063
064  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
065  public void testToStringMatchesAsMap() {
066    assertEquals(multimap().asMap().toString(), multimap().toString());
067  }
068}