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;
028import org.junit.Ignore;
029
030/**
031 * Tester for {@code Multimap.toString()}.
032 *
033 * @author Louis Wasserman
034 */
035@GwtCompatible
036@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
037public class MultimapToStringTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
038  @CollectionSize.Require(ZERO)
039  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
040  public void testToStringEmpty() {
041    assertEquals("{}", multimap().toString());
042  }
043
044  @CollectionSize.Require(ONE)
045  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
046  public void testToStringSingleton() {
047    assertEquals("{" + k0() + "=[" + v0() + "]}", multimap().toString());
048  }
049
050  @CollectionSize.Require(absent = ZERO)
051  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
052  @MapFeature.Require(ALLOWS_NULL_KEYS)
053  public void testToStringWithNullKey() {
054    initMultimapWithNullKey();
055    testToStringMatchesAsMap();
056  }
057
058  @CollectionSize.Require(absent = ZERO)
059  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
060  @MapFeature.Require(ALLOWS_NULL_VALUES)
061  public void testToStringWithNullValue() {
062    initMultimapWithNullValue();
063    testToStringMatchesAsMap();
064  }
065
066  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
067  public void testToStringMatchesAsMap() {
068    assertEquals(multimap().asMap().toString(), multimap().toString());
069  }
070}