10888a09821a98ac0680fad765217302858e70fa4Paul Duffin/* 20888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Copyright (C) 2013 The Guava Authors 30888a09821a98ac0680fad765217302858e70fa4Paul Duffin * 40888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Licensed under the Apache License, Version 2.0 (the "License"); 50888a09821a98ac0680fad765217302858e70fa4Paul Duffin * you may not use this file except in compliance with the License. 60888a09821a98ac0680fad765217302858e70fa4Paul Duffin * You may obtain a copy of the License at 70888a09821a98ac0680fad765217302858e70fa4Paul Duffin * 80888a09821a98ac0680fad765217302858e70fa4Paul Duffin * http://www.apache.org/licenses/LICENSE-2.0 90888a09821a98ac0680fad765217302858e70fa4Paul Duffin * 100888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Unless required by applicable law or agreed to in writing, software 110888a09821a98ac0680fad765217302858e70fa4Paul Duffin * distributed under the License is distributed on an "AS IS" BASIS, 120888a09821a98ac0680fad765217302858e70fa4Paul Duffin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130888a09821a98ac0680fad765217302858e70fa4Paul Duffin * See the License for the specific language governing permissions and 140888a09821a98ac0680fad765217302858e70fa4Paul Duffin * limitations under the License. 150888a09821a98ac0680fad765217302858e70fa4Paul Duffin */ 160888a09821a98ac0680fad765217302858e70fa4Paul Duffin 170888a09821a98ac0680fad765217302858e70fa4Paul Duffinpackage com.google.common.collect.testing.google; 180888a09821a98ac0680fad765217302858e70fa4Paul Duffin 190888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; 200888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; 210888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport static com.google.common.collect.testing.features.CollectionSize.SEVERAL; 220888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport static com.google.common.collect.testing.features.CollectionSize.ZERO; 230888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport static org.truth0.Truth.ASSERT; 240888a09821a98ac0680fad765217302858e70fa4Paul Duffin 250888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport com.google.common.annotations.GwtCompatible; 260888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport com.google.common.collect.testing.features.CollectionFeature; 270888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport com.google.common.collect.testing.features.CollectionSize; 280888a09821a98ac0680fad765217302858e70fa4Paul Duffin 290888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport java.util.Collections; 300888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport java.util.Set; 310888a09821a98ac0680fad765217302858e70fa4Paul Duffin 320888a09821a98ac0680fad765217302858e70fa4Paul Duffin/** 330888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Tests for {@code Multiset.elementSet()} not covered by the derived {@code SetTestSuiteBuilder}. 340888a09821a98ac0680fad765217302858e70fa4Paul Duffin * 350888a09821a98ac0680fad765217302858e70fa4Paul Duffin * @author Louis Wasserman 360888a09821a98ac0680fad765217302858e70fa4Paul Duffin */ 370888a09821a98ac0680fad765217302858e70fa4Paul Duffin@GwtCompatible 380888a09821a98ac0680fad765217302858e70fa4Paul Duffinpublic class MultisetElementSetTester<E> extends AbstractMultisetTester<E> { 390888a09821a98ac0680fad765217302858e70fa4Paul Duffin @CollectionFeature.Require(SUPPORTS_ADD) 400888a09821a98ac0680fad765217302858e70fa4Paul Duffin public void testElementSetReflectsAddAbsent() { 410888a09821a98ac0680fad765217302858e70fa4Paul Duffin Set<E> elementSet = getMultiset().elementSet(); 420888a09821a98ac0680fad765217302858e70fa4Paul Duffin assertFalse(elementSet.contains(samples.e3)); 430888a09821a98ac0680fad765217302858e70fa4Paul Duffin getMultiset().add(samples.e3, 4); 440888a09821a98ac0680fad765217302858e70fa4Paul Duffin assertTrue(elementSet.contains(samples.e3)); 450888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 460888a09821a98ac0680fad765217302858e70fa4Paul Duffin 470888a09821a98ac0680fad765217302858e70fa4Paul Duffin @CollectionSize.Require(absent = ZERO) 480888a09821a98ac0680fad765217302858e70fa4Paul Duffin @CollectionFeature.Require(SUPPORTS_REMOVE) 490888a09821a98ac0680fad765217302858e70fa4Paul Duffin public void testElementSetReflectsRemove() { 500888a09821a98ac0680fad765217302858e70fa4Paul Duffin Set<E> elementSet = getMultiset().elementSet(); 510888a09821a98ac0680fad765217302858e70fa4Paul Duffin assertTrue(elementSet.contains(samples.e0)); 520888a09821a98ac0680fad765217302858e70fa4Paul Duffin getMultiset().removeAll(Collections.singleton(samples.e0)); 530888a09821a98ac0680fad765217302858e70fa4Paul Duffin assertFalse(elementSet.contains(samples.e0)); 540888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 550888a09821a98ac0680fad765217302858e70fa4Paul Duffin 560888a09821a98ac0680fad765217302858e70fa4Paul Duffin @CollectionSize.Require(absent = ZERO) 570888a09821a98ac0680fad765217302858e70fa4Paul Duffin @CollectionFeature.Require(SUPPORTS_REMOVE) 580888a09821a98ac0680fad765217302858e70fa4Paul Duffin public void testElementSetRemovePropagatesToMultiset() { 590888a09821a98ac0680fad765217302858e70fa4Paul Duffin Set<E> elementSet = getMultiset().elementSet(); 600888a09821a98ac0680fad765217302858e70fa4Paul Duffin assertTrue(elementSet.remove(samples.e0)); 610888a09821a98ac0680fad765217302858e70fa4Paul Duffin assertFalse(getMultiset().contains(samples.e0)); 620888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 630888a09821a98ac0680fad765217302858e70fa4Paul Duffin 640888a09821a98ac0680fad765217302858e70fa4Paul Duffin @CollectionSize.Require(SEVERAL) 650888a09821a98ac0680fad765217302858e70fa4Paul Duffin @CollectionFeature.Require(SUPPORTS_REMOVE) 660888a09821a98ac0680fad765217302858e70fa4Paul Duffin public void testElementSetRemoveDuplicatePropagatesToMultiset() { 670888a09821a98ac0680fad765217302858e70fa4Paul Duffin initThreeCopies(); 680888a09821a98ac0680fad765217302858e70fa4Paul Duffin Set<E> elementSet = getMultiset().elementSet(); 690888a09821a98ac0680fad765217302858e70fa4Paul Duffin assertTrue(elementSet.remove(samples.e0)); 700888a09821a98ac0680fad765217302858e70fa4Paul Duffin ASSERT.that(getMultiset()).isEmpty(); 710888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 720888a09821a98ac0680fad765217302858e70fa4Paul Duffin 730888a09821a98ac0680fad765217302858e70fa4Paul Duffin @CollectionFeature.Require(SUPPORTS_REMOVE) 740888a09821a98ac0680fad765217302858e70fa4Paul Duffin public void testElementSetRemoveAbsent() { 750888a09821a98ac0680fad765217302858e70fa4Paul Duffin Set<E> elementSet = getMultiset().elementSet(); 760888a09821a98ac0680fad765217302858e70fa4Paul Duffin assertFalse(elementSet.remove(samples.e3)); 770888a09821a98ac0680fad765217302858e70fa4Paul Duffin expectUnchanged(); 780888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 790888a09821a98ac0680fad765217302858e70fa4Paul Duffin 800888a09821a98ac0680fad765217302858e70fa4Paul Duffin @CollectionFeature.Require(SUPPORTS_REMOVE) 810888a09821a98ac0680fad765217302858e70fa4Paul Duffin public void testElementSetClear() { 820888a09821a98ac0680fad765217302858e70fa4Paul Duffin getMultiset().elementSet().clear(); 830888a09821a98ac0680fad765217302858e70fa4Paul Duffin ASSERT.that(getMultiset()).isEmpty(); 840888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 850888a09821a98ac0680fad765217302858e70fa4Paul Duffin} 86