001/* 002 * Copyright (C) 2007 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.features.CollectionFeature.ALLOWS_NULL_QUERIES; 020import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; 021import static com.google.common.collect.testing.features.CollectionSize.ZERO; 022 023import com.google.common.annotations.GwtCompatible; 024import com.google.common.collect.testing.AbstractCollectionTester; 025import com.google.common.collect.testing.MinimalCollection; 026import com.google.common.collect.testing.WrongType; 027import com.google.common.collect.testing.features.CollectionFeature; 028import com.google.common.collect.testing.features.CollectionSize; 029import java.util.Collection; 030import org.junit.Ignore; 031 032/** 033 * A generic JUnit test which tests {@code containsAll()} operations on a collection. Can't be 034 * invoked directly; please see {@link 035 * com.google.common.collect.testing.CollectionTestSuiteBuilder}. 036 * 037 * @author Kevin Bourrillion 038 * @author Chris Povirk 039 */ 040@SuppressWarnings("unchecked") // too many "unchecked generic array creations" 041@GwtCompatible 042@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 043public class CollectionContainsAllTester<E> extends AbstractCollectionTester<E> { 044 public void testContainsAll_empty() { 045 assertTrue( 046 "containsAll(empty) should return true", collection.containsAll(MinimalCollection.of())); 047 } 048 049 @CollectionSize.Require(absent = ZERO) 050 public void testContainsAll_subset() { 051 assertTrue( 052 "containsAll(subset) should return true", 053 collection.containsAll(MinimalCollection.of(e0()))); 054 } 055 056 public void testContainsAll_sameElements() { 057 assertTrue( 058 "containsAll(sameElements) should return true", 059 collection.containsAll(MinimalCollection.of(createSamplesArray()))); 060 } 061 062 @SuppressWarnings("ModifyingCollectionWithItself") 063 public void testContainsAll_self() { 064 assertTrue("containsAll(this) should return true", collection.containsAll(collection)); 065 } 066 067 public void testContainsAll_partialOverlap() { 068 assertFalse( 069 "containsAll(partialOverlap) should return false", 070 collection.containsAll(MinimalCollection.of(e0(), e3()))); 071 } 072 073 public void testContainsAll_disjoint() { 074 assertFalse( 075 "containsAll(disjoint) should return false", 076 collection.containsAll(MinimalCollection.of(e3()))); 077 } 078 079 @CollectionFeature.Require(absent = ALLOWS_NULL_QUERIES) 080 public void testContainsAll_nullNotAllowed() { 081 try { 082 assertFalse(collection.containsAll(MinimalCollection.of((E) null))); 083 } catch (NullPointerException tolerated) { 084 } 085 } 086 087 @CollectionFeature.Require(ALLOWS_NULL_QUERIES) 088 public void testContainsAll_nullAllowed() { 089 assertFalse(collection.containsAll(MinimalCollection.of((E) null))); 090 } 091 092 @CollectionFeature.Require(ALLOWS_NULL_VALUES) 093 @CollectionSize.Require(absent = ZERO) 094 public void testContainsAll_nullPresent() { 095 initCollectionWithNullElement(); 096 assertTrue(collection.containsAll(MinimalCollection.of((E) null))); 097 } 098 099 public void testContainsAll_wrongType() { 100 Collection<WrongType> wrong = MinimalCollection.of(WrongType.VALUE); 101 try { 102 assertFalse( 103 "containsAll(wrongType) should return false or throw", collection.containsAll(wrong)); 104 } catch (ClassCastException tolerated) { 105 } 106 } 107}