Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2008 The Guava Authors
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.google.common.collect.testing.testers;
 
 import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_QUERIES;
 import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES;
 import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION;
 import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE;
 import static com.google.common.collect.testing.features.CollectionSize.SEVERAL;
 import static com.google.common.collect.testing.features.CollectionSize.ZERO;
 
 
A generic JUnit test which tests removeAll operations on a collection. Can't be invoked directly; please see com.google.common.collect.testing.CollectionTestSuiteBuilder.

This class is GWT compatible.

Author(s):
George van den Driessche
Chris Povirk
 
 @SuppressWarnings("unchecked"// too many "unchecked generic array creations"
 public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
   public void testRemoveAll_emptyCollection() {
     assertFalse("removeAll(emptyCollection) should return false",
         .removeAll(MinimalCollection.of()));
     expectUnchanged();
   }
 
   public void testRemoveAll_nonePresent() {
     assertFalse("removeAll(disjointCollection) should return false",
         .removeAll(MinimalCollection.of(.)));
     expectUnchanged();
   }
 
   @CollectionSize.Require(absent = )
   public void testRemoveAll_allPresent() {
     assertTrue("removeAll(intersectingCollection) should return true",
         .removeAll(MinimalCollection.of(.)));
   }
 
   @CollectionSize.Require(absent = )
   public void testRemoveAll_somePresent() {
     assertTrue("removeAll(intersectingCollection) should return true",
         .removeAll(MinimalCollection.of(..)));
   }
 
     try {
       Iterator<E> iterator = .iterator();
       assertTrue(.removeAll(MinimalCollection.of(..)));
       iterator.next();
       fail("Expected ConcurrentModificationException");
     } catch (ConcurrentModificationException expected) {
       // success
     }
   }

  
Trigger the other.size() >= this.size() case in AbstractSet.removeAll().
 
   @CollectionSize.Require(absent = )
    assertTrue("removeAll(largeIntersectingCollection) should return true",
        .removeAll(MinimalCollection.of(
            ...,
            ...)));
  }
    try {
      assertFalse("removeAll(emptyCollection) should return false or throw "
          + "UnsupportedOperationException",
        .removeAll(MinimalCollection.of()));
    } catch (UnsupportedOperationException tolerated) {
    }
  }
    try {
      assertFalse("removeAll(disjointCollection) should return false or throw "
          + "UnsupportedOperationException",
        .removeAll(MinimalCollection.of(.)));
    } catch (UnsupportedOperationException tolerated) {
    }
  }
  @CollectionSize.Require(absent = )
    try {
      .removeAll(MinimalCollection.of(.));
      fail("removeAll(intersectingCollection) should throw "
          + "UnsupportedOperationException");
    } catch (UnsupportedOperationException expected) {
    }
  }
  /*
   * AbstractCollection fails the removeAll(null) test when the subject
   * collection is empty, but we'd still like to test removeAll(null) when we
   * can. We split the test into empty and non-empty cases. This allows us to
   * suppress only the former.
   */
    try {
      .removeAll(null);
      // Returning successfully is not ideal, but tolerated.
    } catch (NullPointerException expected) {
    }
  }
  @CollectionSize.Require(absent = )
    try {
      .removeAll(null);
      fail("removeAll(null) should throw NullPointerException");
    } catch (NullPointerException expected) {
    }
  }
      absent = )
  public void testRemoveAll_containsNullNo() {
    MinimalCollection<?> containsNull = MinimalCollection.of((Objectnull);
    try {
      assertFalse("removeAll(containsNull) should return false or throw",
          .removeAll(containsNull));
    } catch (NullPointerException tolerated) {
    }
  }
    MinimalCollection<?> containsNull = MinimalCollection.of((Objectnull);
    assertFalse("removeAll(containsNull) should return false",
        .removeAll(containsNull));
  }
  @CollectionSize.Require(absent = )
  public void testRemoveAll_containsNullYes() {
    assertTrue("removeAll(containsNull) should return true",
        .removeAll(Collections.singleton(null)));
    // TODO: make this work with MinimalCollection
  }
  public void testRemoveAll_containsWrongType() {
    try {
      assertFalse("removeAll(containsWrongType) should return false or throw",
          .removeAll(MinimalCollection.of(.)));
    } catch (ClassCastException tolerated) {
    }
  }
New to GrepCode? Check out our FAQ X