ListRetainAllTester.java revision 3c77433663281544363151bf284b0240dfd22a42
1/* 2 * Copyright (C) 2008 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 17package com.google.common.collect.testing.testers; 18 19import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; 20import static com.google.common.collect.testing.features.CollectionSize.ONE; 21import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; 22import static com.google.common.collect.testing.features.CollectionSize.ZERO; 23 24import com.google.common.annotations.GwtCompatible; 25import com.google.common.collect.testing.MinimalCollection; 26import com.google.common.collect.testing.features.CollectionFeature; 27import com.google.common.collect.testing.features.CollectionSize; 28 29/** 30 * A generic JUnit test which tests {@code retainAll} operations on a list. 31 * Can't be invoked directly; please see 32 * {@link com.google.common.collect.testing.ListTestSuiteBuilder}. 33 * 34 * <p>This class is GWT compatible. 35 * 36 * @author Chris Povirk 37 */ 38@GwtCompatible 39public class ListRetainAllTester<E> extends AbstractListTester<E> { 40 @CollectionFeature.Require(SUPPORTS_REMOVE) 41 @CollectionSize.Require(absent = {ZERO, ONE}) 42 public void testRetainAll_duplicatesKept() { 43 E[] array = createSamplesArray(); 44 array[1] = samples.e0; 45 collection = getSubjectGenerator().create(array); 46 assertFalse("containsDuplicates.retainAll(superset) should return false", 47 collection.retainAll(MinimalCollection.of(createSamplesArray()))); 48 expectContents(array); 49 } 50 51 @SuppressWarnings("unchecked") 52 @CollectionFeature.Require(SUPPORTS_REMOVE) 53 @CollectionSize.Require(SEVERAL) 54 public void testRetainAll_duplicatesRemoved() { 55 E[] array = createSamplesArray(); 56 array[1] = samples.e0; 57 collection = getSubjectGenerator().create(array); 58 assertTrue("containsDuplicates.retainAll(subset) should return true", 59 collection.retainAll(MinimalCollection.of(samples.e2))); 60 expectContents(samples.e2); 61 } 62} 63