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 remove operations on a collection. Can't be invoked directly; please see com.google.common.collect.testing.CollectionTestSuiteBuilder.

Author(s):
George van den Driessche
 
 @SuppressWarnings("unchecked"// too many "unchecked generic array creations"
 public class CollectionRemoveTester<E> extends AbstractCollectionTester<E> {
   @CollectionSize.Require(absent = )
   public void testRemove_present() {
     int initialSize = .size();
     assertTrue("remove(present) should return true",
         .remove(.));
     assertEquals("remove(present) should decrease a collection's size by one.",
         initialSize - 1, .size());
   }
 
     try {
       Iterator<E> iterator = .iterator();
       iterator.next();
       fail("Expected ConcurrentModificationException");
     } catch (ConcurrentModificationException expected) {
       // success
     }
   }
 
   public void testRemove_notPresent() {
     assertFalse("remove(notPresent) should return false",
         .remove(.));
     expectUnchanged();
   }
 
   @CollectionSize.Require(absent = )
   public void testRemove_nullPresent() {
 
     int initialSize = .size();
     assertTrue("remove(null) should return true".remove(null));
     assertEquals("remove(present) should decrease a collection's size by one.",
         initialSize - 1, .size());
     expectMissing((E) null);
   }
 
   @CollectionSize.Require(absent = )
   public void testRemove_unsupported() {
     try {
       .remove(.);
       fail("remove(present) should throw UnsupportedOperationException");
     } catch (UnsupportedOperationException expected) {
     }
     expectUnchanged();
     assertTrue("remove(present) should not remove the element",
         .contains(.));
  }
    try {
      assertFalse("remove(notPresent) should return false or throw "
          + "UnsupportedOperationException",
          .remove(.));
    } catch (UnsupportedOperationException tolerated) {
    }
  }
      value = ,
      absent = )
  public void testRemove_nullNotSupported() {
    try {
      assertFalse("remove(null) should return false or throw "
          + "NullPointerException",
          .remove(null));
    } catch (NullPointerException tolerated) {
    }
  }
  public void testRemove_nullAllowed() {
    assertFalse("remove(null) should return false".remove(null));
  }
  @CollectionSize.Require(absent = )
  public void testIteratorRemove_unsupported() {
    Iterator<E> iterator = .iterator();
    iterator.next();
    try {
      iterator.remove();
      fail("iterator.remove() should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException expected) {
    }
  }
  public void testRemove_wrongType() {
    try {
    } catch (ClassCastException tolerated) {
    }
  }
New to GrepCode? Check out our FAQ X