| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.common.collect.testing.testers; |
| 18 |
|
| 19 |
import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; |
| 20 |
import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; |
| 21 |
import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; |
| 22 |
import static com.google.common.collect.testing.features.CollectionSize.ZERO; |
| 23 |
|
| 24 |
import com.google.common.annotations.GwtCompatible; |
| 25 |
import com.google.common.collect.testing.AbstractCollectionTester; |
| 26 |
import com.google.common.collect.testing.features.CollectionFeature; |
| 27 |
import com.google.common.collect.testing.features.CollectionSize; |
| 28 |
import java.util.ConcurrentModificationException; |
| 29 |
import java.util.Iterator; |
| 30 |
import org.junit.Ignore; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
@GwtCompatible |
| 39 |
@Ignore |
| 40 |
public class CollectionClearTester<E> extends AbstractCollectionTester<E> { |
| 41 |
@CollectionFeature.Require(SUPPORTS_REMOVE) |
| 42 |
public void testClear() { |
| 43 |
collection.clear(); |
| 44 |
assertTrue("After clear(), a collection should be empty.", collection.isEmpty()); |
| 45 |
assertEquals(0, collection.size()); |
| 46 |
assertFalse(collection.iterator().hasNext()); |
| 47 |
} |
| 48 |
|
| 49 |
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) |
| 50 |
@CollectionSize.Require(absent = ZERO) |
| 51 |
public void testClear_unsupported() { |
| 52 |
try { |
| 53 |
collection.clear(); |
| 54 |
fail( |
| 55 |
"clear() should throw UnsupportedOperation if a collection does " |
| 56 |
+ "not support it and is not empty."); |
| 57 |
} catch (UnsupportedOperationException expected) { |
| 58 |
} |
| 59 |
expectUnchanged(); |
| 60 |
} |
| 61 |
|
| 62 |
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) |
| 63 |
@CollectionSize.Require(ZERO) |
| 64 |
public void testClear_unsupportedByEmptyCollection() { |
| 65 |
try { |
| 66 |
collection.clear(); |
| 67 |
} catch (UnsupportedOperationException tolerated) { |
| 68 |
} |
| 69 |
expectUnchanged(); |
| 70 |
} |
| 71 |
|
| 72 |
@CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION}) |
| 73 |
@CollectionSize.Require(SEVERAL) |
| 74 |
public void testClearConcurrentWithIteration() { |
| 75 |
try { |
| 76 |
Iterator<E> iterator = collection.iterator(); |
| 77 |
collection.clear(); |
| 78 |
iterator.next(); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
fail("Expected ConcurrentModificationException"); |
| 84 |
} catch (ConcurrentModificationException expected) { |
| 85 |
|
| 86 |
} |
| 87 |
} |
| 88 |
} |