001/* 002 * Copyright (C) 2008 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.google.common.collect.testing.testers; 018 019import static com.google.common.collect.testing.Helpers.assertContentsInOrder; 020import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; 021import static com.google.common.collect.testing.features.CollectionSize.ONE; 022import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; 023import static com.google.common.collect.testing.features.CollectionSize.ZERO; 024import static java.util.Arrays.asList; 025 026import com.google.common.annotations.GwtCompatible; 027import com.google.common.collect.testing.MinimalCollection; 028import com.google.common.collect.testing.features.CollectionFeature; 029import com.google.common.collect.testing.features.CollectionSize; 030import org.junit.Ignore; 031 032/** 033 * A generic JUnit test which tests {@code retainAll} operations on a list. Can't be invoked 034 * directly; please see {@link com.google.common.collect.testing.ListTestSuiteBuilder}. 035 * 036 * @author Chris Povirk 037 */ 038@GwtCompatible 039@Ignore("test runners must not instantiate and run this directly, only via suites we build") 040// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 041@SuppressWarnings("JUnit4ClassUsedInJUnit3") 042public class ListRetainAllTester<E> extends AbstractListTester<E> { 043 @CollectionFeature.Require(SUPPORTS_REMOVE) 044 @CollectionSize.Require(absent = {ZERO, ONE}) 045 public void testRetainAll_duplicatesKept() { 046 E[] array = createSamplesArray(); 047 array[1] = e0(); 048 collection = getSubjectGenerator().create(array); 049 assertFalse( 050 "containsDuplicates.retainAll(superset) should return false", 051 collection.retainAll(MinimalCollection.of(createSamplesArray()))); 052 expectContents(array); 053 } 054 055 @CollectionFeature.Require(SUPPORTS_REMOVE) 056 @CollectionSize.Require(SEVERAL) 057 public void testRetainAll_duplicatesRemoved() { 058 E[] array = createSamplesArray(); 059 array[1] = e0(); 060 collection = getSubjectGenerator().create(array); 061 assertTrue( 062 "containsDuplicates.retainAll(subset) should return true", 063 collection.retainAll(MinimalCollection.of(e2()))); 064 expectContents(e2()); 065 } 066 067 @CollectionFeature.Require(SUPPORTS_REMOVE) 068 @CollectionSize.Require(SEVERAL) 069 public void testRetainAll_countIgnored() { 070 resetContainer(getSubjectGenerator().create(e0(), e2(), e1(), e0())); 071 assertTrue(getList().retainAll(asList(e0(), e1()))); 072 assertContentsInOrder(getList(), e0(), e1(), e0()); 073 } 074}