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("test runners must not instantiate and run this directly, only via suites we build") 037// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 038@SuppressWarnings("JUnit4ClassUsedInJUnit3") 039public class MultimapToStringTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> { 040 @CollectionSize.Require(ZERO) 041 @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING) 042 public void testToStringEmpty() { 043 assertEquals("{}", multimap().toString()); 044 } 045 046 @CollectionSize.Require(ONE) 047 @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING) 048 public void testToStringSingleton() { 049 assertEquals("{" + k0() + "=[" + v0() + "]}", multimap().toString()); 050 } 051 052 @CollectionSize.Require(absent = ZERO) 053 @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING) 054 @MapFeature.Require(ALLOWS_NULL_KEYS) 055 public void testToStringWithNullKey() { 056 initMultimapWithNullKey(); 057 testToStringMatchesAsMap(); 058 } 059 060 @CollectionSize.Require(absent = ZERO) 061 @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING) 062 @MapFeature.Require(ALLOWS_NULL_VALUES) 063 public void testToStringWithNullValue() { 064 initMultimapWithNullValue(); 065 testToStringMatchesAsMap(); 066 } 067 068 @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING) 069 public void testToStringMatchesAsMap() { 070 assertEquals(multimap().asMap().toString(), multimap().toString()); 071 } 072}