Coverage Summary for Class: MultisetElementSetTester (com.google.common.collect.testing.google)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| MultisetElementSetTester | 0% (0/1) | 0% (0/8) | 0% (0/35) |
1 /* 2 * Copyright (C) 2013 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 17 package com.google.common.collect.testing.google; 18 19 import static com.google.common.collect.testing.Helpers.assertEmpty; 20 import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; 21 import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; 22 import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; 23 import static com.google.common.collect.testing.features.CollectionSize.ZERO; 24 25 import com.google.common.annotations.GwtCompatible; 26 import com.google.common.annotations.GwtIncompatible; 27 import com.google.common.collect.testing.Helpers; 28 import com.google.common.collect.testing.features.CollectionFeature; 29 import com.google.common.collect.testing.features.CollectionSize; 30 import java.lang.reflect.Method; 31 import java.util.Arrays; 32 import java.util.Collections; 33 import java.util.List; 34 import java.util.Set; 35 import org.junit.Ignore; 36 37 /** 38 * Tests for {@code Multiset.elementSet()} not covered by the derived {@code SetTestSuiteBuilder}. 39 * 40 * @author Louis Wasserman 41 */ 42 @GwtCompatible 43 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 44 public class MultisetElementSetTester<E> extends AbstractMultisetTester<E> { 45 @CollectionFeature.Require(SUPPORTS_ADD) 46 public void testElementSetReflectsAddAbsent() { 47 Set<E> elementSet = getMultiset().elementSet(); 48 assertFalse(elementSet.contains(e3())); 49 getMultiset().add(e3(), 4); 50 assertTrue(elementSet.contains(e3())); 51 } 52 53 @CollectionSize.Require(absent = ZERO) 54 @CollectionFeature.Require(SUPPORTS_REMOVE) 55 public void testElementSetReflectsRemove() { 56 Set<E> elementSet = getMultiset().elementSet(); 57 assertTrue(elementSet.contains(e0())); 58 getMultiset().removeAll(Collections.singleton(e0())); 59 assertFalse(elementSet.contains(e0())); 60 } 61 62 @CollectionSize.Require(absent = ZERO) 63 @CollectionFeature.Require(SUPPORTS_REMOVE) 64 public void testElementSetRemovePropagatesToMultiset() { 65 Set<E> elementSet = getMultiset().elementSet(); 66 int size = getNumElements(); 67 int expectedSize = size - getMultiset().count(e0()); 68 assertTrue(elementSet.remove(e0())); 69 assertFalse(getMultiset().contains(e0())); 70 assertEquals(expectedSize, getMultiset().size()); 71 } 72 73 @CollectionSize.Require(SEVERAL) 74 @CollectionFeature.Require(SUPPORTS_REMOVE) 75 public void testElementSetRemoveDuplicatePropagatesToMultiset() { 76 initThreeCopies(); 77 int size = getNumElements(); 78 int expectedSize = size - getMultiset().count(e0()); 79 Set<E> elementSet = getMultiset().elementSet(); 80 assertTrue(elementSet.remove(e0())); 81 assertEmpty(getMultiset()); 82 assertEquals(expectedSize, getMultiset().size()); 83 } 84 85 @CollectionFeature.Require(SUPPORTS_REMOVE) 86 public void testElementSetRemoveAbsent() { 87 Set<E> elementSet = getMultiset().elementSet(); 88 assertFalse(elementSet.remove(e3())); 89 expectUnchanged(); 90 } 91 92 @CollectionFeature.Require(SUPPORTS_REMOVE) 93 public void testElementSetClear() { 94 getMultiset().elementSet().clear(); 95 assertEmpty(getMultiset()); 96 } 97 98 /** 99 * Returns {@link Method} instances for the read tests that assume multisets support duplicates so 100 * that the test of {@code Multisets.forSet()} can suppress them. 101 */ 102 @GwtIncompatible // reflection 103 public static List<Method> getElementSetDuplicateInitializingMethods() { 104 return Arrays.asList( 105 Helpers.getMethod( 106 MultisetElementSetTester.class, "testElementSetRemoveDuplicatePropagatesToMultiset")); 107 } 108 }