Coverage Summary for Class: MultisetAddTester (com.google.common.collect.testing.google)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| MultisetAddTester | 0% (0/1) | 0% (0/13) | 0% (0/54) |
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.features.CollectionFeature.SUPPORTS_ADD; 20 21 import com.google.common.annotations.GwtCompatible; 22 import com.google.common.collect.testing.features.CollectionFeature; 23 import java.util.Arrays; 24 import java.util.Collections; 25 import org.junit.Ignore; 26 27 /** 28 * Tests for {@code Multiset.add}. 29 * 30 * @author Jared Levy 31 */ 32 @GwtCompatible 33 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 34 public class MultisetAddTester<E> extends AbstractMultisetTester<E> { 35 @CollectionFeature.Require(absent = SUPPORTS_ADD) 36 public void testAddUnsupported() { 37 try { 38 getMultiset().add(e0()); 39 fail("Expected UnsupportedOperationException"); 40 } catch (UnsupportedOperationException expected) { 41 } 42 } 43 44 @CollectionFeature.Require(SUPPORTS_ADD) 45 public void testAddMeansAddOne() { 46 int originalCount = getMultiset().count(e0()); 47 assertTrue(getMultiset().add(e0())); 48 assertEquals(originalCount + 1, getMultiset().count(e0())); 49 } 50 51 @CollectionFeature.Require(SUPPORTS_ADD) 52 public void testAddOccurrencesZero() { 53 int originalCount = getMultiset().count(e0()); 54 assertEquals("old count", originalCount, getMultiset().add(e0(), 0)); 55 expectUnchanged(); 56 } 57 58 @CollectionFeature.Require(SUPPORTS_ADD) 59 public void testAddOccurrences() { 60 int originalCount = getMultiset().count(e0()); 61 assertEquals("old count", originalCount, getMultiset().add(e0(), 2)); 62 assertEquals("old count", originalCount + 2, getMultiset().count(e0())); 63 } 64 65 @CollectionFeature.Require(SUPPORTS_ADD) 66 public void testAddSeveralTimes() { 67 int originalCount = getMultiset().count(e0()); 68 assertEquals(originalCount, getMultiset().add(e0(), 2)); 69 assertTrue(getMultiset().add(e0())); 70 assertEquals(originalCount + 3, getMultiset().add(e0(), 1)); 71 assertEquals(originalCount + 4, getMultiset().count(e0())); 72 } 73 74 @CollectionFeature.Require(absent = SUPPORTS_ADD) 75 public void testAddOccurrences_unsupported() { 76 try { 77 getMultiset().add(e0(), 2); 78 fail("unsupported multiset.add(E, int) didn't throw exception"); 79 } catch (UnsupportedOperationException required) { 80 } 81 } 82 83 @CollectionFeature.Require(SUPPORTS_ADD) 84 public void testAddOccurrencesNegative() { 85 try { 86 getMultiset().add(e0(), -1); 87 fail("multiset.add(E, -1) didn't throw an exception"); 88 } catch (IllegalArgumentException required) { 89 } 90 } 91 92 @CollectionFeature.Require(SUPPORTS_ADD) 93 public void testAddTooMany() { 94 getMultiset().add(e3(), Integer.MAX_VALUE); 95 try { 96 getMultiset().add(e3()); 97 fail(); 98 } catch (IllegalArgumentException expected) { 99 } 100 assertEquals(Integer.MAX_VALUE, getMultiset().count(e3())); 101 assertEquals(Integer.MAX_VALUE, getMultiset().size()); 102 } 103 104 @CollectionFeature.Require(SUPPORTS_ADD) 105 public void testAddAll_emptySet() { 106 assertFalse(getMultiset().addAll(Collections.<E>emptySet())); 107 expectUnchanged(); 108 } 109 110 @CollectionFeature.Require(SUPPORTS_ADD) 111 public void testAddAll_emptyMultiset() { 112 assertFalse(getMultiset().addAll(getSubjectGenerator().create())); 113 expectUnchanged(); 114 } 115 116 @CollectionFeature.Require(SUPPORTS_ADD) 117 public void testAddAll_nonEmptyList() { 118 assertTrue(getMultiset().addAll(Arrays.asList(e3(), e4(), e3()))); 119 expectAdded(e3(), e4(), e3()); 120 } 121 122 @CollectionFeature.Require(SUPPORTS_ADD) 123 public void testAddAll_nonEmptyMultiset() { 124 assertTrue(getMultiset().addAll(getSubjectGenerator().create(e3(), e4(), e3()))); 125 expectAdded(e3(), e4(), e3()); 126 } 127 }