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; 024 025import com.google.common.annotations.GwtCompatible; 026import com.google.common.collect.testing.MinimalCollection; 027import com.google.common.collect.testing.features.CollectionFeature; 028import com.google.common.collect.testing.features.CollectionSize; 029import java.util.Arrays; 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 // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 040public class ListRetainAllTester<E> extends AbstractListTester<E> { 041 @CollectionFeature.Require(SUPPORTS_REMOVE) 042 @CollectionSize.Require(absent = {ZERO, ONE}) 043 public void testRetainAll_duplicatesKept() { 044 E[] array = createSamplesArray(); 045 array[1] = e0(); 046 collection = getSubjectGenerator().create(array); 047 assertFalse( 048 "containsDuplicates.retainAll(superset) should return false", 049 collection.retainAll(MinimalCollection.of(createSamplesArray()))); 050 expectContents(array); 051 } 052 053 @SuppressWarnings("unchecked") 054 @CollectionFeature.Require(SUPPORTS_REMOVE) 055 @CollectionSize.Require(SEVERAL) 056 public void testRetainAll_duplicatesRemoved() { 057 E[] array = createSamplesArray(); 058 array[1] = e0(); 059 collection = getSubjectGenerator().create(array); 060 assertTrue( 061 "containsDuplicates.retainAll(subset) should return true", 062 collection.retainAll(MinimalCollection.of(e2()))); 063 expectContents(e2()); 064 } 065 066 @SuppressWarnings("unchecked") 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(Arrays.asList(e0(), e1()))); 072 assertContentsInOrder(getList(), e0(), e1(), e0()); 073 } 074}