mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-15 06:26:29 +00:00
[COLLECTIONS-809] JUnit v5 assertThrows (#291)
Refactor PredicatedMapTest Refactor UnmodifiableSortedSetTest Refactor PredicatedSortedSetTest Refactor PredicatedSetTest Refactor PredicatedNavigableSetTest Refactor ListOrderedSetTest Refactor PredicatedSortedMapTest Refactor ReferenceIdentityMapTest Refactor ReferenceMapTest Refactor TransformedSortedMapTest Refactor PredicatedMapTest Refactor UnmodifiableSortedSetTest Refactor PredicatedSortedSetTest Refactor PredicatedSetTest Refactor PredicatedNavigableSetTest Refactor ListOrderedSetTest Refactor PredicatedSortedMapTest Refactor ReferenceIdentityMapTest Refactor ReferenceMapTest Refactor TransformedSortedMapTest Refactor UnmodifiableMultiValuedMapTest Refactor PredicatedMultiSetTest Refactor UnmodifiableMultiSetTest Refactor CircularFifoQueueTest Refactor UnmodifiableQueueTest Refactor CompositeSetTest Refactor AbstractQueueTest Refactor AbstractMultiSetTest Refactor AbstractMultiValuedMapTest Refactor AbstractBidiMapTest Refactor AbstractBloomFilterTest Refactor AbstractIteratorTest Refactor AbstractLinkedListTest Refactor AbstractListTest Refactor AbstractSortedMapTest Refactor AbstractOrderedMapTest Refactor AbstractIterableMapTest Refactor AbstractMapTest Refactor AbstractMapIteratorTest Refactor AbstractListIteratorTest Refactor AbstractCollectionTest
This commit is contained in:
parent
eab0aa0b09
commit
f55268b092
@ -556,27 +556,23 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
|
|||||||
|
|
||||||
// at this point
|
// at this point
|
||||||
// key1=newValue1, key2=newValue2
|
// key1=newValue1, key2=newValue2
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> it.setValue(newValue1)); // should remove key1
|
||||||
it.setValue(newValue1); // should remove key1
|
// below code was previously never executed
|
||||||
fail();
|
// confirmed.put(key2, newValue1);
|
||||||
} catch (final IllegalArgumentException ex) {
|
// AbstractBidiMapTest.this.getConfirmed().remove(key1);
|
||||||
return; // simplest way of dealing with tricky situation
|
// assertEquals(newValue1, it.getValue());
|
||||||
}
|
// assertTrue(bidi.containsKey(it.getKey()));
|
||||||
confirmed.put(key2, newValue1);
|
// assertTrue(bidi.containsValue(newValue1));
|
||||||
AbstractBidiMapTest.this.getConfirmed().remove(key1);
|
// assertEquals(newValue1, bidi.get(it.getKey()));
|
||||||
assertEquals(newValue1, it.getValue());
|
// assertFalse(bidi.containsKey(key1));
|
||||||
assertTrue(bidi.containsKey(it.getKey()));
|
// assertFalse(bidi.containsValue(newValue2));
|
||||||
assertTrue(bidi.containsValue(newValue1));
|
// verify();
|
||||||
assertEquals(newValue1, bidi.get(it.getKey()));
|
//
|
||||||
assertFalse(bidi.containsKey(key1));
|
// // check for ConcurrentModification
|
||||||
assertFalse(bidi.containsValue(newValue2));
|
// it.next(); // if you fail here, maybe you should be throwing an IAE, see above
|
||||||
verify();
|
// if (isRemoveSupported()) {
|
||||||
|
// it.remove();
|
||||||
// check for ConcurrentModification
|
// }
|
||||||
it.next(); // if you fail here, maybe you should be throwing an IAE, see above
|
|
||||||
if (isRemoveSupported()) {
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import org.apache.commons.collections4.BulkTest;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit tests.
|
* JUnit tests.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class DualHashBidiMapTest<K, V> extends AbstractBidiMapTest<K, V> {
|
public class DualHashBidiMapTest<K, V> extends AbstractBidiMapTest<K, V> {
|
||||||
|
|
||||||
@ -56,4 +55,5 @@ public class DualHashBidiMapTest<K, V> extends AbstractBidiMapTest<K, V> {
|
|||||||
// resetFull();
|
// resetFull();
|
||||||
// writeExternalFormToDisk((java.io.Serializable) map, "src/test/resources/data/test/DualHashBidiMap.fullCollection.version4.obj");
|
// writeExternalFormToDisk((java.io.Serializable) map, "src/test/resources/data/test/DualHashBidiMap.fullCollection.version4.obj");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.bloomfilter;
|
package org.apache.commons.collections4.bloomfilter;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.PrimitiveIterator.OfInt;
|
import java.util.PrimitiveIterator.OfInt;
|
||||||
@ -261,12 +262,8 @@ public abstract class AbstractBloomFilterTest {
|
|||||||
|
|
||||||
final List<Integer> lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
final List<Integer> lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
||||||
final Hasher hasher = new StaticHasher(lst.iterator(), anotherShape);
|
final Hasher hasher = new StaticHasher(lst.iterator(), anotherShape);
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> createFilter(hasher, shape),
|
||||||
createFilter(hasher, shape);
|
"Should throw IllegalArgumentException");
|
||||||
fail("Should throw IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException expected) {
|
|
||||||
// do nothing.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -297,12 +294,8 @@ public abstract class AbstractBloomFilterTest {
|
|||||||
final Shape anotherShape = new Shape(testFunctionX, 3, 72, 17);
|
final Shape anotherShape = new Shape(testFunctionX, 3, 72, 17);
|
||||||
final Hasher hasher2 = new StaticHasher(lst.iterator(), anotherShape);
|
final Hasher hasher2 = new StaticHasher(lst.iterator(), anotherShape);
|
||||||
final BloomFilter bf2 = createFilter(hasher2, anotherShape);
|
final BloomFilter bf2 = createFilter(hasher2, anotherShape);
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> bf.contains(bf2),
|
||||||
bf.contains(bf2);
|
"Should throw IllegalArgumentException");
|
||||||
fail("Should throw IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException expected) {
|
|
||||||
// do nothing.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -340,12 +333,8 @@ public abstract class AbstractBloomFilterTest {
|
|||||||
|
|
||||||
final List<Integer> lst2 = Arrays.asList(4, 5, 6, 7, 8, 9, 10);
|
final List<Integer> lst2 = Arrays.asList(4, 5, 6, 7, 8, 9, 10);
|
||||||
final Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape);
|
final Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape);
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> bf.contains(hasher2),
|
||||||
bf.contains(hasher2);
|
"Should have thrown IllegalArgumentException");
|
||||||
fail("Should have thrown IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException expected) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -485,12 +474,8 @@ public abstract class AbstractBloomFilterTest {
|
|||||||
final Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape);
|
final Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape);
|
||||||
final BloomFilter bf2 = createFilter(hasher2, anotherShape);
|
final BloomFilter bf2 = createFilter(hasher2, anotherShape);
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> bf.merge(bf2),
|
||||||
bf.merge(bf2);
|
"Should throw IllegalArgumentException");
|
||||||
fail("Should throw IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException expected) {
|
|
||||||
// do nothing.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -524,12 +509,8 @@ public abstract class AbstractBloomFilterTest {
|
|||||||
final List<Integer> lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
|
final List<Integer> lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
|
||||||
final Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape);
|
final Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape);
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> bf.merge(hasher2),
|
||||||
bf.merge(hasher2);
|
"Should throw IllegalArgumentException");
|
||||||
fail("Should throw IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException expected) {
|
|
||||||
// do nothing.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -638,4 +619,5 @@ public abstract class AbstractBloomFilterTest {
|
|||||||
assertEquals(20, bf.xorCardinality(bf2));
|
assertEquals(20, bf.xorCardinality(bf2));
|
||||||
assertEquals(20, bf2.xorCardinality(bf));
|
assertEquals(20, bf2.xorCardinality(bf));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.collection;
|
package org.apache.commons.collections4.collection;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
@ -118,7 +120,6 @@ import org.apache.commons.collections4.AbstractObjectTest;
|
|||||||
* If your {@link Collection} fails one of these tests by design,
|
* If your {@link Collection} fails one of these tests by design,
|
||||||
* you may still use this base set of cases. Simply override the
|
* you may still use this base set of cases. Simply override the
|
||||||
* test case (method) your {@link Collection} fails.
|
* test case (method) your {@link Collection} fails.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
||||||
|
|
||||||
@ -571,43 +572,27 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getCollection().add(getFullNonNullElements()[0]),
|
||||||
getCollection().add(getFullNonNullElements()[0]);
|
"Empty collection should not support add.");
|
||||||
fail("Empty collection should not support add.");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
// make sure things didn't change even if the expected exception was
|
// make sure things didn't change even if the expected exception was
|
||||||
// thrown.
|
// thrown.
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getCollection().addAll(Arrays.asList(getFullElements())),
|
||||||
getCollection().addAll(Arrays.asList(getFullElements()));
|
"Empty collection should not support addAll.");
|
||||||
fail("Empty collection should not support addAll.");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
// make sure things didn't change even if the expected exception was
|
// make sure things didn't change even if the expected exception was
|
||||||
// thrown.
|
// thrown.
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getCollection().add(getFullNonNullElements()[0]),
|
||||||
getCollection().add(getFullNonNullElements()[0]);
|
"Full collection should not support add.");
|
||||||
fail("Full collection should not support add.");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
// make sure things didn't change even if the expected exception was
|
// make sure things didn't change even if the expected exception was
|
||||||
// thrown.
|
// thrown.
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getCollection().addAll(Arrays.asList(getOtherElements())),
|
||||||
getCollection().addAll(Arrays.asList(getOtherElements()));
|
"Full collection should not support addAll.");
|
||||||
fail("Full collection should not support addAll.");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
// make sure things didn't change even if the expected exception was
|
// make sure things didn't change even if the expected exception was
|
||||||
// thrown.
|
// thrown.
|
||||||
verify();
|
verify();
|
||||||
@ -733,13 +718,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
resetEmpty();
|
resetEmpty();
|
||||||
Iterator<E> it1 = getCollection().iterator();
|
Iterator<E> it1 = getCollection().iterator();
|
||||||
assertFalse("Iterator for empty Collection shouldn't have next.", it1.hasNext());
|
assertFalse("Iterator for empty Collection shouldn't have next.", it1.hasNext());
|
||||||
try {
|
Iterator<E> finalIt1 = it1;
|
||||||
it1.next();
|
assertThrows(NoSuchElementException.class, () -> finalIt1.next(),
|
||||||
fail("Iterator at end of Collection should throw "
|
"Iterator at end of Collection should throw NoSuchElementException when next is called.");
|
||||||
+ "NoSuchElementException when next is called.");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
// make sure nothing has changed after non-modification
|
// make sure nothing has changed after non-modification
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
@ -759,12 +740,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
getCollection().contains(next));
|
getCollection().contains(next));
|
||||||
list.add(next);
|
list.add(next);
|
||||||
}
|
}
|
||||||
try {
|
Iterator<E> finalIt2 = it1;
|
||||||
it1.next();
|
assertThrows(NoSuchElementException.class, () -> finalIt2.next(),
|
||||||
fail("iterator.next() should raise NoSuchElementException after it finishes");
|
"iterator.next() should raise NoSuchElementException after it finishes");
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
// make sure nothing has changed after non-modification
|
// make sure nothing has changed after non-modification
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
@ -779,22 +757,14 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> getCollection().iterator().remove(),
|
||||||
getCollection().iterator().remove();
|
"New iterator.remove should raise IllegalState");
|
||||||
fail("New iterator.remove should raise IllegalState");
|
|
||||||
} catch (final IllegalStateException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
final Iterator<E> iter0 = getCollection().iterator();
|
||||||
final Iterator<E> iter = getCollection().iterator();
|
iter0.hasNext();
|
||||||
iter.hasNext();
|
assertThrows(IllegalStateException.class, () -> iter0.remove(),
|
||||||
iter.remove();
|
"New iterator.remove should raise IllegalState even after hasNext");
|
||||||
fail("New iterator.remove should raise IllegalState even after hasNext");
|
|
||||||
} catch (final IllegalStateException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
@ -832,12 +802,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
iter = getCollection().iterator();
|
iter = getCollection().iterator();
|
||||||
iter.next();
|
iter.next();
|
||||||
iter.remove();
|
iter.remove();
|
||||||
try {
|
Iterator<E> finalIter = iter;
|
||||||
iter.remove();
|
assertThrows(IllegalStateException.class, () -> finalIter.remove(),
|
||||||
fail("Second iter.remove should raise IllegalState");
|
"Second iter.remove should raise IllegalState");
|
||||||
} catch (final IllegalStateException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1100,21 +1067,13 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
assertThrows(ArrayStoreException.class, () -> getCollection().toArray(new Void[0]),
|
||||||
array = getCollection().toArray(new Void[0]);
|
"toArray(new Void[0]) should raise ArrayStore");
|
||||||
fail("toArray(new Void[0]) should raise ArrayStore");
|
|
||||||
} catch (final ArrayStoreException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
|
||||||
// Casting to Object[] allows compilation on Java 11.
|
// Casting to Object[] allows compilation on Java 11.
|
||||||
array = getCollection().toArray((Object[]) null);
|
assertThrows(NullPointerException.class, () -> getCollection().toArray((Object[]) null),
|
||||||
fail("toArray(null) should raise NPE");
|
"toArray(null) should raise NPE");
|
||||||
} catch (final NullPointerException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
array = getCollection().toArray(new Object[0]);
|
array = getCollection().toArray(new Object[0]);
|
||||||
@ -1167,55 +1126,31 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getCollection().clear(),
|
||||||
getCollection().clear();
|
"clear should raise UnsupportedOperationException");
|
||||||
fail("clear should raise UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getCollection().remove(null),
|
||||||
getCollection().remove(null);
|
"remove should raise UnsupportedOperationException");
|
||||||
fail("remove should raise UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getCollection().removeIf(e -> true),
|
||||||
getCollection().removeIf(e -> true);
|
"removeIf should raise UnsupportedOperationException");
|
||||||
fail("removeIf should raise UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getCollection().removeAll(null),
|
||||||
getCollection().removeAll(null);
|
"removeAll should raise UnsupportedOperationException");
|
||||||
fail("removeAll should raise UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getCollection().retainAll(null),
|
||||||
getCollection().retainAll(null);
|
"retainAll should raise UnsupportedOperationException");
|
||||||
fail("retainAll should raise UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
|
||||||
final Iterator<E> iterator = getCollection().iterator();
|
final Iterator<E> iterator = getCollection().iterator();
|
||||||
iterator.next();
|
iterator.next();
|
||||||
iterator.remove();
|
assertThrows(UnsupportedOperationException.class, () -> iterator.remove(),
|
||||||
fail("iterator.remove should raise UnsupportedOperationException");
|
"iterator.remove should raise UnsupportedOperationException");
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1230,28 +1165,20 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
|
|
||||||
if (isAddSupported()) {
|
if (isAddSupported()) {
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
final Iterator<E> iter0 = getCollection().iterator();
|
||||||
final Iterator<E> iter = getCollection().iterator();
|
|
||||||
final E o = getOtherElements()[0];
|
final E o = getOtherElements()[0];
|
||||||
getCollection().add(o);
|
getCollection().add(o);
|
||||||
getConfirmed().add(o);
|
getConfirmed().add(o);
|
||||||
iter.next();
|
assertThrows(ConcurrentModificationException.class, () -> iter0.next(),
|
||||||
fail("next after add should raise ConcurrentModification");
|
"next after add should raise ConcurrentModification");
|
||||||
} catch (final ConcurrentModificationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
|
||||||
final Iterator<E> iter = getCollection().iterator();
|
final Iterator<E> iter = getCollection().iterator();
|
||||||
getCollection().addAll(Arrays.asList(getOtherElements()));
|
getCollection().addAll(Arrays.asList(getOtherElements()));
|
||||||
getConfirmed().addAll(Arrays.asList(getOtherElements()));
|
getConfirmed().addAll(Arrays.asList(getOtherElements()));
|
||||||
iter.next();
|
assertThrows(ConcurrentModificationException.class, () -> iter.next(),
|
||||||
fail("next after addAll should raise ConcurrentModification");
|
"next after addAll should raise ConcurrentModification");
|
||||||
} catch (final ConcurrentModificationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1271,46 +1198,30 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
final Iterator<E> iter0 = getCollection().iterator();
|
||||||
final Iterator<E> iter = getCollection().iterator();
|
|
||||||
getCollection().remove(getFullElements()[0]);
|
getCollection().remove(getFullElements()[0]);
|
||||||
iter.next();
|
assertThrows(ConcurrentModificationException.class, () -> iter0.next(),
|
||||||
fail("next after remove should raise ConcurrentModification");
|
"next after remove should raise ConcurrentModification");
|
||||||
} catch (final ConcurrentModificationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
final Iterator<E> iter1 = getCollection().iterator();
|
||||||
final Iterator<E> iter = getCollection().iterator();
|
|
||||||
getCollection().removeIf(e -> false);
|
getCollection().removeIf(e -> false);
|
||||||
iter.next();
|
assertThrows(ConcurrentModificationException.class, () -> iter1.next(),
|
||||||
fail("next after removeIf should raise ConcurrentModification");
|
"next after removeIf should raise ConcurrentModification");
|
||||||
} catch (final ConcurrentModificationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
final Iterator<E> iter2 = getCollection().iterator();
|
||||||
final Iterator<E> iter = getCollection().iterator();
|
|
||||||
final List<E> sublist = Arrays.asList(getFullElements()).subList(2, 5);
|
final List<E> sublist = Arrays.asList(getFullElements()).subList(2, 5);
|
||||||
getCollection().removeAll(sublist);
|
getCollection().removeAll(sublist);
|
||||||
iter.next();
|
assertThrows(ConcurrentModificationException.class, () -> iter2.next(),
|
||||||
fail("next after removeAll should raise ConcurrentModification");
|
"next after removeAll should raise ConcurrentModification");
|
||||||
} catch (final ConcurrentModificationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
final Iterator<E> iter3 = getCollection().iterator();
|
||||||
final Iterator<E> iter = getCollection().iterator();
|
final List<E> sublist3 = Arrays.asList(getFullElements()).subList(2, 5);
|
||||||
final List<E> sublist = Arrays.asList(getFullElements()).subList(2, 5);
|
getCollection().retainAll(sublist3);
|
||||||
getCollection().retainAll(sublist);
|
assertThrows(ConcurrentModificationException.class, () -> iter3.next(),
|
||||||
iter.next();
|
"next after retainAll should raise ConcurrentModification");
|
||||||
fail("next after retainAll should raise ConcurrentModification");
|
|
||||||
} catch (final ConcurrentModificationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1420,4 +1331,5 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
//apparently not
|
//apparently not
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.iterators;
|
package org.apache.commons.collections4.iterators;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
@ -108,11 +110,8 @@ public abstract class AbstractIteratorTest<E> extends AbstractObjectTest {
|
|||||||
assertFalse("hasNext() should return false for empty iterators", it.hasNext());
|
assertFalse("hasNext() should return false for empty iterators", it.hasNext());
|
||||||
|
|
||||||
// next() should throw a NoSuchElementException
|
// next() should throw a NoSuchElementException
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> it.next(),
|
||||||
it.next();
|
"NoSuchElementException must be thrown when Iterator is exhausted");
|
||||||
fail("NoSuchElementException must be thrown when Iterator is exhausted");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
assertNotNull(it.toString());
|
assertNotNull(it.toString());
|
||||||
@ -145,11 +144,8 @@ public abstract class AbstractIteratorTest<E> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// next() must throw NoSuchElementException now
|
// next() must throw NoSuchElementException now
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> it.next(),
|
||||||
it.next();
|
"NoSuchElementException must be thrown when Iterator is exhausted");
|
||||||
fail("NoSuchElementException must be thrown when Iterator is exhausted");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertNotNull(it.toString());
|
assertNotNull(it.toString());
|
||||||
}
|
}
|
||||||
@ -169,10 +165,7 @@ public abstract class AbstractIteratorTest<E> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// should throw IllegalStateException before next() called
|
// should throw IllegalStateException before next() called
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.remove());
|
||||||
it.remove();
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ex) {}
|
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
// remove after next should be fine
|
// remove after next should be fine
|
||||||
@ -180,10 +173,7 @@ public abstract class AbstractIteratorTest<E> extends AbstractObjectTest {
|
|||||||
it.remove();
|
it.remove();
|
||||||
|
|
||||||
// should throw IllegalStateException for second remove()
|
// should throw IllegalStateException for second remove()
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.remove());
|
||||||
it.remove();
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.iterators;
|
package org.apache.commons.collections4.iterators;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
@ -101,18 +103,12 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
|
|||||||
assertEquals(-1, it.previousIndex());
|
assertEquals(-1, it.previousIndex());
|
||||||
|
|
||||||
// next() should throw a NoSuchElementException
|
// next() should throw a NoSuchElementException
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> it.next(),
|
||||||
it.next();
|
"NoSuchElementException must be thrown from empty ListIterator");
|
||||||
fail("NoSuchElementException must be thrown from empty ListIterator");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// previous() should throw a NoSuchElementException
|
// previous() should throw a NoSuchElementException
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> it.previous(),
|
||||||
it.previous();
|
"NoSuchElementException must be thrown from empty ListIterator");
|
||||||
fail("NoSuchElementException must be thrown from empty ListIterator");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,11 +124,8 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
|
|||||||
// check state at end
|
// check state at end
|
||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
assertTrue(it.hasPrevious());
|
assertTrue(it.hasPrevious());
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> it.next(),
|
||||||
it.next();
|
"NoSuchElementException must be thrown from next at end of ListIterator");
|
||||||
fail("NoSuchElementException must be thrown from next at end of ListIterator");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// loop back through comparing
|
// loop back through comparing
|
||||||
for (int i = list.size() - 1; i >= 0; i--) {
|
for (int i = list.size() - 1; i >= 0; i--) {
|
||||||
@ -146,11 +139,8 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
|
|||||||
// check state at start
|
// check state at start
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
assertFalse(it.hasPrevious());
|
assertFalse(it.hasPrevious());
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> it.previous(),
|
||||||
it.previous();
|
"NoSuchElementException must be thrown from previous at start of ListIterator");
|
||||||
fail("NoSuchElementException must be thrown from previous at start of ListIterator");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -162,10 +152,9 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
|
|||||||
final E addValue = addSetValue();
|
final E addValue = addSetValue();
|
||||||
if (!supportsAdd()) {
|
if (!supportsAdd()) {
|
||||||
// check for UnsupportedOperationException if not supported
|
// check for UnsupportedOperationException if not supported
|
||||||
try {
|
ListIterator<E> finalIt0 = it;
|
||||||
it.add(addValue);
|
assertThrows(UnsupportedOperationException.class, () -> finalIt0.add(addValue),
|
||||||
fail("UnsupportedOperationException must be thrown from add of " + it.getClass().getSimpleName());
|
"UnsupportedOperationException must be thrown from add of " + it.getClass().getSimpleName());
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,18 +187,13 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
|
|||||||
|
|
||||||
if (!supportsSet()) {
|
if (!supportsSet()) {
|
||||||
// check for UnsupportedOperationException if not supported
|
// check for UnsupportedOperationException if not supported
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> it.set(addSetValue()),
|
||||||
it.set(addSetValue());
|
"UnsupportedOperationException must be thrown from set in " + it.getClass().getSimpleName());
|
||||||
fail("UnsupportedOperationException must be thrown from set in " + it.getClass().getSimpleName());
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// should throw IllegalStateException before next() called
|
// should throw IllegalStateException before next() called
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.set(addSetValue()));
|
||||||
it.set(addSetValue());
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ex) {}
|
|
||||||
|
|
||||||
// set after next should be fine
|
// set after next should be fine
|
||||||
it.next();
|
it.next();
|
||||||
@ -225,11 +209,8 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
|
|||||||
if (supportsRemove() && supportsSet()) {
|
if (supportsRemove() && supportsSet()) {
|
||||||
it.next();
|
it.next();
|
||||||
it.remove();
|
it.remove();
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.set(addSetValue()),
|
||||||
it.set(addSetValue());
|
"IllegalStateException must be thrown from set after remove");
|
||||||
fail("IllegalStateException must be thrown from set after remove");
|
|
||||||
} catch (final IllegalStateException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,11 +220,8 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
|
|||||||
if (supportsAdd() && supportsSet()) {
|
if (supportsAdd() && supportsSet()) {
|
||||||
it.next();
|
it.next();
|
||||||
it.add(addSetValue());
|
it.add(addSetValue());
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.set(addSetValue()),
|
||||||
it.set(addSetValue());
|
"IllegalStateException must be thrown from set after add");
|
||||||
fail("IllegalStateException must be thrown from set after add");
|
|
||||||
} catch (final IllegalStateException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,11 +235,8 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
|
|||||||
if (supportsAdd() && supportsRemove()) {
|
if (supportsAdd() && supportsRemove()) {
|
||||||
it.next();
|
it.next();
|
||||||
it.add(addSetValue());
|
it.add(addSetValue());
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.remove(),
|
||||||
it.remove();
|
"IllegalStateException must be thrown from remove after add");
|
||||||
fail("IllegalStateException must be thrown from remove after add");
|
|
||||||
} catch (final IllegalStateException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.iterators;
|
package org.apache.commons.collections4.iterators;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
@ -117,22 +119,13 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
|
|||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
|
|
||||||
// next() should throw a NoSuchElementException
|
// next() should throw a NoSuchElementException
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> it.next());
|
||||||
it.next();
|
|
||||||
fail();
|
|
||||||
} catch (final NoSuchElementException ex) {}
|
|
||||||
|
|
||||||
// getKey() should throw an IllegalStateException
|
// getKey() should throw an IllegalStateException
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.getKey());
|
||||||
it.getKey();
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ex) {}
|
|
||||||
|
|
||||||
// getValue() should throw an IllegalStateException
|
// getValue() should throw an IllegalStateException
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.getValue());
|
||||||
it.getValue();
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ex) {}
|
|
||||||
|
|
||||||
if (!supportsSetValue()) {
|
if (!supportsSetValue()) {
|
||||||
// setValue() should throw an UnsupportedOperationException/IllegalStateException
|
// setValue() should throw an UnsupportedOperationException/IllegalStateException
|
||||||
@ -144,10 +137,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// setValue() should throw an IllegalStateException
|
// setValue() should throw an IllegalStateException
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.setValue(addSetValues()[0]));
|
||||||
it.setValue(addSetValues()[0]);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ex) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,10 +188,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
|
|||||||
final V value = it.getValue();
|
final V value = it.getValue();
|
||||||
|
|
||||||
if (!supportsSetValue()) {
|
if (!supportsSetValue()) {
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> it.setValue(newValue));
|
||||||
it.setValue(newValue);
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final V old = it.setValue(newValue);
|
final V old = it.setValue(newValue);
|
||||||
@ -238,11 +225,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
|
|||||||
final K key = it.next();
|
final K key = it.next();
|
||||||
|
|
||||||
if (!supportsRemove()) {
|
if (!supportsRemove()) {
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> it.remove());
|
||||||
it.remove();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException ex) {
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,10 +257,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
|
|||||||
confirmed.remove(key);
|
confirmed.remove(key);
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.setValue(newValue));
|
||||||
it.setValue(newValue);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ex) {}
|
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,10 +275,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
|
|||||||
confirmed.remove(key);
|
confirmed.remove(key);
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.getKey());
|
||||||
it.getKey();
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ex) {}
|
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,10 +293,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
|
|||||||
confirmed.remove(key);
|
confirmed.remove(key);
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.getValue());
|
||||||
it.getValue();
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ex) {}
|
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,11 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.list;
|
package org.apache.commons.collections4.list;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case for {@link AbstractLinkedList}.
|
* Test case for {@link AbstractLinkedList}.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
|
public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
|
||||||
|
|
||||||
@ -138,36 +139,20 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
|
|||||||
final AbstractLinkedList<E> list = getCollection();
|
final AbstractLinkedList<E> list = getCollection();
|
||||||
// get marker
|
// get marker
|
||||||
assertEquals(list.getNode(0, true).previous, list.getNode(0, true).next);
|
assertEquals(list.getNode(0, true).previous, list.getNode(0, true).next);
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(0, false),
|
||||||
list.getNode(0, false);
|
"Expecting IndexOutOfBoundsException.");
|
||||||
fail("Expecting IndexOutOfBoundsException.");
|
|
||||||
} catch (final IndexOutOfBoundsException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
list.addAll( Arrays.asList((E[]) new String[]{"value1", "value2"}));
|
list.addAll( Arrays.asList((E[]) new String[]{"value1", "value2"}));
|
||||||
checkNodes();
|
checkNodes();
|
||||||
list.addFirst((E) "value0");
|
list.addFirst((E) "value0");
|
||||||
checkNodes();
|
checkNodes();
|
||||||
list.removeNode(list.getNode(1, false));
|
list.removeNode(list.getNode(1, false));
|
||||||
checkNodes();
|
checkNodes();
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(2, false),
|
||||||
list.getNode(2, false);
|
"Expecting IndexOutOfBoundsException.");
|
||||||
fail("Expecting IndexOutOfBoundsException.");
|
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(-1, false),
|
||||||
} catch (final IndexOutOfBoundsException ex) {
|
"Expecting IndexOutOfBoundsException.");
|
||||||
// expected
|
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(3, true),
|
||||||
}
|
"Expecting IndexOutOfBoundsException.");
|
||||||
try {
|
|
||||||
list.getNode(-1, false);
|
|
||||||
fail("Expecting IndexOutOfBoundsException.");
|
|
||||||
} catch (final IndexOutOfBoundsException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
list.getNode(3, true);
|
|
||||||
fail("Expecting IndexOutOfBoundsException.");
|
|
||||||
} catch (final IndexOutOfBoundsException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkNodes() {
|
protected void checkNodes() {
|
||||||
@ -188,4 +173,5 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
|
|||||||
public AbstractLinkedList<E> getCollection() {
|
public AbstractLinkedList<E> getCollection() {
|
||||||
return (AbstractLinkedList<E>) super.getCollection();
|
return (AbstractLinkedList<E>) super.getCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.list;
|
package org.apache.commons.collections4.list;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -34,6 +36,7 @@ import java.util.NoSuchElementException;
|
|||||||
import org.apache.commons.collections4.BulkTest;
|
import org.apache.commons.collections4.BulkTest;
|
||||||
import org.apache.commons.collections4.collection.AbstractCollectionTest;
|
import org.apache.commons.collections4.collection.AbstractCollectionTest;
|
||||||
import org.apache.commons.collections4.iterators.AbstractListIteratorTest;
|
import org.apache.commons.collections4.iterators.AbstractListIteratorTest;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract test class for {@link java.util.List} methods and contracts.
|
* Abstract test class for {@link java.util.List} methods and contracts.
|
||||||
@ -45,7 +48,6 @@ import org.apache.commons.collections4.iterators.AbstractListIteratorTest;
|
|||||||
* you may still use this base set of cases. Simply override the
|
* you may still use this base set of cases. Simply override the
|
||||||
* test case (method) your {@link List} fails or override one of the
|
* test case (method) your {@link List} fails or override one of the
|
||||||
* protected methods from AbstractCollectionTest.
|
* protected methods from AbstractCollectionTest.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
||||||
|
|
||||||
@ -176,40 +178,23 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<E> list;
|
|
||||||
final E element = getOtherElements()[0];
|
final E element = getOtherElements()[0];
|
||||||
|
|
||||||
try {
|
List<E> finalList0 = makeObject();
|
||||||
list = makeObject();
|
assertThrows(IndexOutOfBoundsException.class, () -> finalList0.add(Integer.MIN_VALUE, element),
|
||||||
list.add(Integer.MIN_VALUE, element);
|
"List.add should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
||||||
fail("List.add should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
List<E> finalList1 = makeObject();
|
||||||
list = makeObject();
|
assertThrows(IndexOutOfBoundsException.class, () -> finalList1.add(-1, element),
|
||||||
list.add(-1, element);
|
"List.add should throw IndexOutOfBoundsException [-1]");
|
||||||
fail("List.add should throw IndexOutOfBoundsException [-1]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
List<E> finalList2 = makeObject();
|
||||||
list = makeObject();
|
assertThrows(IndexOutOfBoundsException.class, () -> finalList2.add(1, element),
|
||||||
list.add(1, element);
|
"List.add should throw IndexOutOfBoundsException [1]");
|
||||||
fail("List.add should throw IndexOutOfBoundsException [1]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
List<E> finalList3 = makeObject();
|
||||||
list = makeObject();
|
assertThrows(IndexOutOfBoundsException.class, () -> finalList3.add(Integer.MAX_VALUE, element),
|
||||||
list.add(Integer.MAX_VALUE, element);
|
"List.add should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
||||||
fail("List.add should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,40 +206,23 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<E> list;
|
|
||||||
final E element = getOtherElements()[0];
|
final E element = getOtherElements()[0];
|
||||||
|
|
||||||
try {
|
List<E> finalList0 = makeFullCollection();
|
||||||
list = makeFullCollection();
|
assertThrows(IndexOutOfBoundsException.class, () -> finalList0.add(Integer.MIN_VALUE, element),
|
||||||
list.add(Integer.MIN_VALUE, element);
|
"List.add should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
||||||
fail("List.add should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
List<E> finalList1 = makeFullCollection();
|
||||||
list = makeFullCollection();
|
assertThrows(IndexOutOfBoundsException.class, () -> finalList1.add(-1, element),
|
||||||
list.add(-1, element);
|
"List.add should throw IndexOutOfBoundsException [-1]");
|
||||||
fail("List.add should throw IndexOutOfBoundsException [-1]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
List<E> finalList2 = makeFullCollection();
|
||||||
list = makeFullCollection();
|
assertThrows(IndexOutOfBoundsException.class, () -> finalList2.add(finalList2.size() + 1, element),
|
||||||
list.add(list.size() + 1, element);
|
"List.add should throw IndexOutOfBoundsException [size + 1]");
|
||||||
fail("List.add should throw IndexOutOfBoundsException [size + 1]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
List<E> finalList3 = makeFullCollection();
|
||||||
list = makeFullCollection();
|
assertThrows(IndexOutOfBoundsException.class, () -> finalList3.add(Integer.MAX_VALUE, element),
|
||||||
list.add(Integer.MAX_VALUE, element);
|
"List.add should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
||||||
fail("List.add should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -383,40 +351,20 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
public void testListGetByIndexBoundsChecking() {
|
public void testListGetByIndexBoundsChecking() {
|
||||||
final List<E> list = makeObject();
|
final List<E> list = makeObject();
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.get(Integer.MIN_VALUE),
|
||||||
list.get(Integer.MIN_VALUE);
|
"List.get should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
||||||
fail("List.get should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.get(-1),
|
||||||
list.get(-1);
|
"List.get should throw IndexOutOfBoundsException [-1]");
|
||||||
fail("List.get should throw IndexOutOfBoundsException [-1]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.get(0),
|
||||||
list.get(0);
|
"List.get should throw IndexOutOfBoundsException [0]");
|
||||||
fail("List.get should throw IndexOutOfBoundsException [0]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.get(1),
|
||||||
list.get(1);
|
"List.get should throw IndexOutOfBoundsException [1]");
|
||||||
fail("List.get should throw IndexOutOfBoundsException [1]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.get(Integer.MAX_VALUE),
|
||||||
list.get(Integer.MAX_VALUE);
|
"List.get should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
||||||
fail("List.get should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -426,33 +374,17 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
public void testListGetByIndexBoundsChecking2() {
|
public void testListGetByIndexBoundsChecking2() {
|
||||||
final List<E> list = makeFullCollection();
|
final List<E> list = makeFullCollection();
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.get(Integer.MIN_VALUE),
|
||||||
list.get(Integer.MIN_VALUE);
|
"List.get should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
||||||
fail("List.get should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.get(-1),
|
||||||
list.get(-1);
|
"List.get should throw IndexOutOfBoundsException [-1]");
|
||||||
fail("List.get should throw IndexOutOfBoundsException [-1]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.get(getFullElements().length),
|
||||||
list.get(getFullElements().length);
|
"List.get should throw IndexOutOfBoundsException [size]");
|
||||||
fail("List.get should throw IndexOutOfBoundsException [size]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.get(Integer.MAX_VALUE),
|
||||||
list.get(Integer.MAX_VALUE);
|
"List.get should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
||||||
fail("List.get should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -513,42 +445,21 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
final List<E> list = makeObject();
|
final List<E> list = makeObject();
|
||||||
final E element = getOtherElements()[0];
|
final E element = getOtherElements()[0];
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.set(Integer.MIN_VALUE, element),
|
||||||
list.set(Integer.MIN_VALUE, element);
|
"List.set should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
||||||
fail("List.set should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.set(-1, element),
|
||||||
list.set(-1, element);
|
"List.set should throw IndexOutOfBoundsException [-1]");
|
||||||
fail("List.set should throw IndexOutOfBoundsException [-1]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.set(0, element),
|
||||||
list.set(0, element);
|
"List.set should throw IndexOutOfBoundsException [0]");
|
||||||
fail("List.set should throw IndexOutOfBoundsException [0]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.set(1, element),
|
||||||
list.set(1, element);
|
"List.set should throw IndexOutOfBoundsException [1]");
|
||||||
fail("List.set should throw IndexOutOfBoundsException [1]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.set(Integer.MAX_VALUE, element),
|
||||||
list.set(Integer.MAX_VALUE, element);
|
"List.set should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
||||||
fail("List.set should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests bounds checking for {@link List#set(int,Object)} on a
|
* Tests bounds checking for {@link List#set(int,Object)} on a
|
||||||
@ -562,37 +473,18 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
final List<E> list = makeFullCollection();
|
final List<E> list = makeFullCollection();
|
||||||
final E element = getOtherElements()[0];
|
final E element = getOtherElements()[0];
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.set(Integer.MIN_VALUE, element),
|
||||||
list.set(Integer.MIN_VALUE, element);
|
"List.set should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
||||||
fail("List.set should throw IndexOutOfBoundsException " +
|
|
||||||
"[Integer.MIN_VALUE]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.set(-1, element),
|
||||||
list.set(-1, element);
|
"List.set should throw IndexOutOfBoundsException [-1]");
|
||||||
fail("List.set should throw IndexOutOfBoundsException [-1]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.set(getFullElements().length, element),
|
||||||
list.set(getFullElements().length, element);
|
"List.set should throw IndexOutOfBoundsException [size]");
|
||||||
fail("List.set should throw IndexOutOfBoundsException [size]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.set(Integer.MAX_VALUE, element),
|
||||||
list.set(Integer.MAX_VALUE, element);
|
"List.set should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
||||||
fail("List.set should throw IndexOutOfBoundsException " +
|
|
||||||
"[Integer.MAX_VALUE]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link List#set(int,Object)}.
|
* Test {@link List#set(int,Object)}.
|
||||||
@ -625,12 +517,8 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getCollection().set(0, getFullElements()[0]),
|
||||||
getCollection().set(0, getFullElements()[0]);
|
"Empty collection should not support set.");
|
||||||
fail("Empty collection should not support set.");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
// make sure things didn't change even if the expected exception was
|
// make sure things didn't change even if the expected exception was
|
||||||
// thrown.
|
// thrown.
|
||||||
verify();
|
verify();
|
||||||
@ -647,40 +535,20 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
|
|
||||||
final List<E> list = makeObject();
|
final List<E> list = makeObject();
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(Integer.MIN_VALUE),
|
||||||
list.remove(Integer.MIN_VALUE);
|
"List.remove should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
||||||
fail("List.remove should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(-1),
|
||||||
list.remove(-1);
|
"List.remove should throw IndexOutOfBoundsException [-1]");
|
||||||
fail("List.remove should throw IndexOutOfBoundsException [-1]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(0),
|
||||||
list.remove(0);
|
"List.remove should throw IndexOutOfBoundsException [0]");
|
||||||
fail("List.remove should throw IndexOutOfBoundsException [0]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(1),
|
||||||
list.remove(1);
|
"List.remove should throw IndexOutOfBoundsException [1]");
|
||||||
fail("List.remove should throw IndexOutOfBoundsException [1]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(Integer.MAX_VALUE),
|
||||||
list.remove(Integer.MAX_VALUE);
|
"List.remove should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
||||||
fail("List.remove should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -694,37 +562,18 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
|
|
||||||
final List<E> list = makeFullCollection();
|
final List<E> list = makeFullCollection();
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(Integer.MIN_VALUE),
|
||||||
list.remove(Integer.MIN_VALUE);
|
"List.remove should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
||||||
fail("List.remove should throw IndexOutOfBoundsException " +
|
|
||||||
"[Integer.MIN_VALUE]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(-1),
|
||||||
list.remove(-1);
|
"List.remove should throw IndexOutOfBoundsException [-1]");
|
||||||
fail("List.remove should throw IndexOutOfBoundsException [-1]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(getFullElements().length),
|
||||||
list.remove(getFullElements().length);
|
"List.remove should throw IndexOutOfBoundsException [size]");
|
||||||
fail("List.remove should throw IndexOutOfBoundsException [size]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(Integer.MAX_VALUE),
|
||||||
list.remove(Integer.MAX_VALUE);
|
"List.remove should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
||||||
fail("List.remove should throw IndexOutOfBoundsException " +
|
|
||||||
"[Integer.MAX_VALUE]");
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link List#remove(int)}.
|
* Tests {@link List#remove(int)}.
|
||||||
@ -922,12 +771,8 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
assertEquals("nextIndex should be size", max, iter.nextIndex());
|
assertEquals("nextIndex should be size", max, iter.nextIndex());
|
||||||
assertEquals("previousIndex should be size - 1", max - 1, iter.previousIndex());
|
assertEquals("previousIndex should be size - 1", max - 1, iter.previousIndex());
|
||||||
|
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> iter.next(),
|
||||||
iter.next();
|
"Exhausted iterator should raise NoSuchElement");
|
||||||
fail("Exhausted iterator should raise NoSuchElement");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -958,13 +803,8 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
final int prevIndex = iter.previousIndex();
|
final int prevIndex = iter.previousIndex();
|
||||||
assertEquals("previousIndex should be -1", -1, prevIndex);
|
assertEquals("previousIndex should be -1", -1, prevIndex);
|
||||||
|
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> iter.previous(),
|
||||||
iter.previous();
|
"Exhausted iterator should raise NoSuchElement");
|
||||||
fail("Exhausted iterator should raise NoSuchElement");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1315,19 +1155,10 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
final InvocationTargetException thrown = assertThrows(InvocationTargetException.class, () -> m.invoke(list, params),
|
||||||
m.invoke(list, params);
|
m.getName() + " should raise ConcurrentModification");
|
||||||
fail(m.getName() + " should raise ConcurrentModification");
|
Assertions.assertTrue(thrown.getTargetException() instanceof ConcurrentModificationException,
|
||||||
} catch (final IllegalAccessException e) {
|
m.getName() + " raised unexpected " + thrown.getTargetException());
|
||||||
// impossible
|
|
||||||
} catch (final InvocationTargetException e) {
|
|
||||||
final Throwable t = e.getTargetException();
|
|
||||||
if (t instanceof ConcurrentModificationException) {
|
|
||||||
// expected
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fail(m.getName() + " raised unexpected " + e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@ -1372,4 +1203,5 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
return AbstractListTest.this.getCollection().listIterator();
|
return AbstractListTest.this.getCollection().listIterator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.map;
|
package org.apache.commons.collections4.map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.ConcurrentModificationException;
|
import java.util.ConcurrentModificationException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -27,7 +29,6 @@ import org.apache.commons.collections4.iterators.AbstractMapIteratorTest;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract test class for {@link IterableMap} methods and contracts.
|
* Abstract test class for {@link IterableMap} methods and contracts.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V> {
|
public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V> {
|
||||||
|
|
||||||
@ -65,19 +66,15 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
|
|||||||
Iterator<Map.Entry<K, V>> it = getMap().entrySet().iterator();
|
Iterator<Map.Entry<K, V>> it = getMap().entrySet().iterator();
|
||||||
final Map.Entry<K, V> val = it.next();
|
final Map.Entry<K, V> val = it.next();
|
||||||
getMap().remove(val.getKey());
|
getMap().remove(val.getKey());
|
||||||
try {
|
Iterator<Map.Entry<K, V>> finalIt0 = it;
|
||||||
it.next();
|
assertThrows(ConcurrentModificationException.class, () -> finalIt0.next());
|
||||||
fail();
|
|
||||||
} catch (final ConcurrentModificationException ex) {}
|
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
it = getMap().entrySet().iterator();
|
it = getMap().entrySet().iterator();
|
||||||
it.next();
|
it.next();
|
||||||
getMap().clear();
|
getMap().clear();
|
||||||
try {
|
Iterator<Map.Entry<K, V>> finalIt1 = it;
|
||||||
it.next();
|
assertThrows(ConcurrentModificationException.class, () -> finalIt1.next());
|
||||||
fail();
|
|
||||||
} catch (final ConcurrentModificationException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFailFastKeySet() {
|
public void testFailFastKeySet() {
|
||||||
@ -91,19 +88,15 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
|
|||||||
Iterator<K> it = getMap().keySet().iterator();
|
Iterator<K> it = getMap().keySet().iterator();
|
||||||
final K val = it.next();
|
final K val = it.next();
|
||||||
getMap().remove(val);
|
getMap().remove(val);
|
||||||
try {
|
Iterator<K> finalIt0 = it;
|
||||||
it.next();
|
assertThrows(ConcurrentModificationException.class, () -> finalIt0.next());
|
||||||
fail();
|
|
||||||
} catch (final ConcurrentModificationException ex) {}
|
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
it = getMap().keySet().iterator();
|
it = getMap().keySet().iterator();
|
||||||
it.next();
|
it.next();
|
||||||
getMap().clear();
|
getMap().clear();
|
||||||
try {
|
Iterator<K> finalIt1 = it;
|
||||||
it.next();
|
assertThrows(ConcurrentModificationException.class, () -> finalIt1.next());
|
||||||
fail();
|
|
||||||
} catch (final ConcurrentModificationException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFailFastValues() {
|
public void testFailFastValues() {
|
||||||
@ -117,19 +110,15 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
|
|||||||
Iterator<V> it = getMap().values().iterator();
|
Iterator<V> it = getMap().values().iterator();
|
||||||
it.next();
|
it.next();
|
||||||
getMap().remove(getMap().keySet().iterator().next());
|
getMap().remove(getMap().keySet().iterator().next());
|
||||||
try {
|
Iterator<V> finalIt0 = it;
|
||||||
it.next();
|
assertThrows(ConcurrentModificationException.class, () -> finalIt0.next());
|
||||||
fail();
|
|
||||||
} catch (final ConcurrentModificationException ex) {}
|
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
it = getMap().values().iterator();
|
it = getMap().values().iterator();
|
||||||
it.next();
|
it.next();
|
||||||
getMap().clear();
|
getMap().clear();
|
||||||
try {
|
Iterator<V> finalIt1 = it;
|
||||||
it.next();
|
assertThrows(ConcurrentModificationException.class, () -> finalIt1.next());
|
||||||
fail();
|
|
||||||
} catch (final ConcurrentModificationException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BulkTest bulkTestMapIterator() {
|
public BulkTest bulkTestMapIterator() {
|
||||||
@ -206,4 +195,5 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
|
|||||||
public IterableMap<K, V> getMap() {
|
public IterableMap<K, V> getMap() {
|
||||||
return (IterableMap<K, V>) super.getMap();
|
return (IterableMap<K, V>) super.getMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.map;
|
package org.apache.commons.collections4.map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -118,7 +120,6 @@ import org.apache.commons.collections4.set.AbstractSetTest;
|
|||||||
* fails and/or the methods that define the assumptions used by the test
|
* fails and/or the methods that define the assumptions used by the test
|
||||||
* cases. For example, if your map does not allow duplicate values, override
|
* cases. For example, if your map does not allow duplicate values, override
|
||||||
* {@link #isAllowDuplicateValues()} and have it return {@code false}
|
* {@link #isAllowDuplicateValues()} and have it return {@code false}
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
||||||
|
|
||||||
@ -588,11 +589,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||||||
*/
|
*/
|
||||||
public void testMapClear() {
|
public void testMapClear() {
|
||||||
if (!isRemoveSupported()) {
|
if (!isRemoveSupported()) {
|
||||||
try {
|
|
||||||
resetFull();
|
resetFull();
|
||||||
getMap().clear();
|
assertThrows(UnsupportedOperationException.class, () -> getMap().clear(),
|
||||||
fail("Expected UnsupportedOperationException on clear");
|
"Expected UnsupportedOperationException on clear");
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -849,10 +848,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getMap().put(keys[0], values[0]),
|
||||||
getMap().put(keys[0], values[0]);
|
"Expected UnsupportedOperationException on put (add)");
|
||||||
fail("Expected UnsupportedOperationException on put (add)");
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -902,10 +899,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||||||
if (!isPutChangeSupported()) {
|
if (!isPutChangeSupported()) {
|
||||||
final Map<K, V> temp = makeFullMap();
|
final Map<K, V> temp = makeFullMap();
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getMap().putAll(temp),
|
||||||
getMap().putAll(temp);
|
"Expected UnsupportedOperationException on putAll");
|
||||||
fail("Expected UnsupportedOperationException on putAll");
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -960,11 +955,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||||||
*/
|
*/
|
||||||
public void testMapRemove() {
|
public void testMapRemove() {
|
||||||
if (!isRemoveSupported()) {
|
if (!isRemoveSupported()) {
|
||||||
try {
|
|
||||||
resetFull();
|
resetFull();
|
||||||
getMap().remove(getMap().keySet().iterator().next());
|
assertThrows(UnsupportedOperationException.class, () -> getMap().remove(getMap().keySet().iterator().next()),
|
||||||
fail("Expected UnsupportedOperationException on remove");
|
"Expected UnsupportedOperationException on remove");
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2031,4 +2024,5 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||||||
public Map<K, V> getConfirmed() {
|
public Map<K, V> getConfirmed() {
|
||||||
return confirmed;
|
return confirmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.map;
|
package org.apache.commons.collections4.map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -33,7 +35,6 @@ import org.apache.commons.collections4.iterators.AbstractOrderedMapIteratorTest;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract test class for {@link OrderedMap} methods and contracts.
|
* Abstract test class for {@link OrderedMap} methods and contracts.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
||||||
|
|
||||||
@ -85,10 +86,8 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
|
|||||||
public void testFirstKey() {
|
public void testFirstKey() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
OrderedMap<K, V> ordered = getMap();
|
OrderedMap<K, V> ordered = getMap();
|
||||||
try {
|
OrderedMap<K, V> finalOrdered = ordered;
|
||||||
ordered.firstKey();
|
assertThrows(NoSuchElementException.class, () -> finalOrdered.firstKey());
|
||||||
fail();
|
|
||||||
} catch (final NoSuchElementException ex) {}
|
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
ordered = getMap();
|
ordered = getMap();
|
||||||
@ -99,10 +98,8 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
|
|||||||
public void testLastKey() {
|
public void testLastKey() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
OrderedMap<K, V> ordered = getMap();
|
OrderedMap<K, V> ordered = getMap();
|
||||||
try {
|
OrderedMap<K, V> finalOrdered = ordered;
|
||||||
ordered.lastKey();
|
assertThrows(NoSuchElementException.class, () -> finalOrdered.lastKey());
|
||||||
fail();
|
|
||||||
} catch (final NoSuchElementException ex) {}
|
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
ordered = getMap();
|
ordered = getMap();
|
||||||
@ -137,10 +134,8 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
|
|||||||
assertNull(ordered.nextKey(confirmedLast));
|
assertNull(ordered.nextKey(confirmedLast));
|
||||||
|
|
||||||
if (!isAllowNullKey()) {
|
if (!isAllowNullKey()) {
|
||||||
try {
|
OrderedMap<K, V> finalOrdered = ordered;
|
||||||
ordered.nextKey(null);
|
assertThrows(NullPointerException.class, () -> finalOrdered.nextKey(null));
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
} else {
|
} else {
|
||||||
assertNull(ordered.nextKey(null));
|
assertNull(ordered.nextKey(null));
|
||||||
}
|
}
|
||||||
@ -172,10 +167,8 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
|
|||||||
assertNull(ordered.previousKey(confirmedLast));
|
assertNull(ordered.previousKey(confirmedLast));
|
||||||
|
|
||||||
if (!isAllowNullKey()) {
|
if (!isAllowNullKey()) {
|
||||||
try {
|
OrderedMap<K, V> finalOrdered = ordered;
|
||||||
ordered.previousKey(null);
|
assertThrows(NullPointerException.class, () -> finalOrdered.previousKey(null));
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
} else {
|
} else {
|
||||||
if (!isAllowNullKey()) {
|
if (!isAllowNullKey()) {
|
||||||
assertNull(ordered.previousKey(null));
|
assertNull(ordered.previousKey(null));
|
||||||
@ -245,4 +238,5 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
|
|||||||
public OrderedMap<K, V> getMap() {
|
public OrderedMap<K, V> getMap() {
|
||||||
return (OrderedMap<K, V>) super.getMap();
|
return (OrderedMap<K, V>) super.getMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.map;
|
package org.apache.commons.collections4.map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -28,7 +30,6 @@ import org.apache.commons.collections4.BulkTest;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract test class for {@link java.util.SortedMap} methods and contracts.
|
* Abstract test class for {@link java.util.SortedMap} methods and contracts.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V> {
|
public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V> {
|
||||||
|
|
||||||
@ -235,10 +236,7 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> getMap().put(toKey, subSortedValues.get(0)));
|
||||||
getMap().put(toKey, subSortedValues.get(0));
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@ -290,10 +288,7 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> getMap().put(invalidKey, subSortedValues.get(0)));
|
||||||
getMap().put(invalidKey, subSortedValues.get(0));
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@ -352,10 +347,7 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> getMap().put(toKey, subSortedValues.get(0)));
|
||||||
getMap().put(toKey, subSortedValues.get(0));
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@ -390,4 +382,5 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
|
|||||||
public SortedMap<K, V> getConfirmed() {
|
public SortedMap<K, V> getConfirmed() {
|
||||||
return (SortedMap<K, V>) super.getConfirmed();
|
return (SortedMap<K, V>) super.getConfirmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.map;
|
package org.apache.commons.collections4.map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -67,19 +69,11 @@ public class PredicatedMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testPut() {
|
public void testPut() {
|
||||||
final Map<K, V> map = makeTestMap();
|
final Map<K, V> map = makeTestMap();
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> map.put((K) "Hi", (V) Integer.valueOf(3)),
|
||||||
map.put((K) "Hi", (V) Integer.valueOf(3));
|
"Illegal value should raise IllegalArgument");
|
||||||
fail("Illegal value should raise IllegalArgument");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> map.put((K) Integer.valueOf(3), (V) "Hi"),
|
||||||
map.put((K) Integer.valueOf(3), (V) "Hi");
|
"Illegal key should raise IllegalArgument");
|
||||||
fail("Illegal key should raise IllegalArgument");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertFalse(map.containsKey(Integer.valueOf(3)));
|
assertFalse(map.containsKey(Integer.valueOf(3)));
|
||||||
assertFalse(map.containsValue(Integer.valueOf(3)));
|
assertFalse(map.containsValue(Integer.valueOf(3)));
|
||||||
@ -90,28 +84,20 @@ public class PredicatedMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
|||||||
map2.put((K) "C", (V) "c");
|
map2.put((K) "C", (V) "c");
|
||||||
map2.put((K) "c", (V) Integer.valueOf(3));
|
map2.put((K) "c", (V) Integer.valueOf(3));
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> map.putAll(map2),
|
||||||
map.putAll(map2);
|
"Illegal value should raise IllegalArgument");
|
||||||
fail("Illegal value should raise IllegalArgument");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
map.put((K) "E", (V) "e");
|
map.put((K) "E", (V) "e");
|
||||||
Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
|
Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
|
||||||
try {
|
Map.Entry<K, V> entry = iterator.next();
|
||||||
final Map.Entry<K, V> entry = iterator.next();
|
Map.Entry<K, V> finalEntry = entry;
|
||||||
entry.setValue((V) Integer.valueOf(3));
|
assertThrows(IllegalArgumentException.class, () -> finalEntry.setValue((V) Integer.valueOf(3)),
|
||||||
fail("Illegal value should raise IllegalArgument");
|
"Illegal value should raise IllegalArgument");
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
map.put((K) "F", (V) "f");
|
map.put((K) "F", (V) "f");
|
||||||
iterator = map.entrySet().iterator();
|
iterator = map.entrySet().iterator();
|
||||||
final Map.Entry<K, V> entry = iterator.next();
|
entry = iterator.next();
|
||||||
entry.setValue((V) "x");
|
entry.setValue((V) "x");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.map;
|
package org.apache.commons.collections4.map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -95,19 +97,11 @@ public class PredicatedSortedMapTest<K, V> extends AbstractSortedMapTest<K, V> {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testPut() {
|
public void testPut() {
|
||||||
final Map<K, V> map = makeTestMap();
|
final Map<K, V> map = makeTestMap();
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> map.put((K) "Hi", (V) Integer.valueOf(3)),
|
||||||
map.put((K) "Hi", (V) Integer.valueOf(3));
|
"Illegal value should raise IllegalArgument");
|
||||||
fail("Illegal value should raise IllegalArgument");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> map.put((K) Integer.valueOf(3), (V) "Hi"),
|
||||||
map.put((K) Integer.valueOf(3), (V) "Hi");
|
"Illegal key should raise IllegalArgument");
|
||||||
fail("Illegal key should raise IllegalArgument");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertFalse(map.containsKey(Integer.valueOf(3)));
|
assertFalse(map.containsKey(Integer.valueOf(3)));
|
||||||
assertFalse(map.containsValue(Integer.valueOf(3)));
|
assertFalse(map.containsValue(Integer.valueOf(3)));
|
||||||
@ -118,26 +112,19 @@ public class PredicatedSortedMapTest<K, V> extends AbstractSortedMapTest<K, V> {
|
|||||||
map2.put((K) "C", (V) "c");
|
map2.put((K) "C", (V) "c");
|
||||||
map2.put((K) "c", (V) Integer.valueOf(3));
|
map2.put((K) "c", (V) Integer.valueOf(3));
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> map.putAll(map2),
|
||||||
map.putAll(map2);
|
"Illegal value should raise IllegalArgument");
|
||||||
fail("Illegal value should raise IllegalArgument");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
map.put((K) "E", (V) "e");
|
map.put((K) "E", (V) "e");
|
||||||
Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
|
Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
|
||||||
try {
|
Map.Entry<K, V> entry = iterator.next();
|
||||||
final Map.Entry<K, V> entry = iterator.next();
|
Map.Entry<K, V> finalEntry = entry;
|
||||||
entry.setValue((V) Integer.valueOf(3));
|
assertThrows(IllegalArgumentException.class, () -> finalEntry.setValue((V) Integer.valueOf(3)),
|
||||||
fail("Illegal value should raise IllegalArgument");
|
"Illegal value should raise IllegalArgument");
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
map.put((K) "F", (V) "f");
|
map.put((K) "F", (V) "f");
|
||||||
iterator = map.entrySet().iterator();
|
iterator = map.entrySet().iterator();
|
||||||
final Map.Entry<K, V> entry = iterator.next();
|
entry = iterator.next();
|
||||||
entry.setValue((V) "x");
|
entry.setValue((V) "x");
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -147,19 +134,11 @@ public class PredicatedSortedMapTest<K, V> extends AbstractSortedMapTest<K, V> {
|
|||||||
final SortedMap<K, V> map = makeTestMap();
|
final SortedMap<K, V> map = makeTestMap();
|
||||||
map.put((K) "A", (V) "a");
|
map.put((K) "A", (V) "a");
|
||||||
map.put((K) "B", (V) "b");
|
map.put((K) "B", (V) "b");
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> map.put(null, (V) "c"),
|
||||||
map.put(null, (V) "c");
|
"Null key should raise IllegalArgument");
|
||||||
fail("Null key should raise IllegalArgument");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
map.put((K) "C", (V) "c");
|
map.put((K) "C", (V) "c");
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> map.put((K) "D", null),
|
||||||
map.put((K) "D", null);
|
"Null value should raise IllegalArgument");
|
||||||
fail("Null value should raise IllegalArgument");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertEquals("First key should be A", "A", map.firstKey());
|
assertEquals("First key should be A", "A", map.firstKey());
|
||||||
assertEquals("Last key should be C", "C", map.lastKey());
|
assertEquals("Last key should be C", "C", map.lastKey());
|
||||||
assertEquals("First key in tail map should be B",
|
assertEquals("First key in tail map should be B",
|
||||||
@ -178,19 +157,11 @@ public class PredicatedSortedMapTest<K, V> extends AbstractSortedMapTest<K, V> {
|
|||||||
final SortedMap<K, V> map = makeTestMapWithComparator();
|
final SortedMap<K, V> map = makeTestMapWithComparator();
|
||||||
map.put((K) "A", (V) "a");
|
map.put((K) "A", (V) "a");
|
||||||
map.put((K) "B", (V) "b");
|
map.put((K) "B", (V) "b");
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> map.put(null, (V) "c"),
|
||||||
map.put(null, (V) "c");
|
"Null key should raise IllegalArgument");
|
||||||
fail("Null key should raise IllegalArgument");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
map.put((K) "C", (V) "c");
|
map.put((K) "C", (V) "c");
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> map.put((K) "D", null),
|
||||||
map.put((K) "D", null);
|
"Null value should raise IllegalArgument");
|
||||||
fail("Null value should raise IllegalArgument");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertEquals("Last key should be A", "A", map.lastKey());
|
assertEquals("Last key should be A", "A", map.lastKey());
|
||||||
assertEquals("First key should be C", "C", map.firstKey());
|
assertEquals("First key should be C", "C", map.firstKey());
|
||||||
assertEquals("First key in tail map should be B",
|
assertEquals("First key in tail map should be B",
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.map;
|
package org.apache.commons.collections4.map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -28,7 +30,6 @@ import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrengt
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for ReferenceIdentityMap.
|
* Tests for ReferenceIdentityMap.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ReferenceIdentityMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
public class ReferenceIdentityMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
||||||
|
|
||||||
@ -286,18 +287,9 @@ public class ReferenceIdentityMapTest<K, V> extends AbstractIterableMapTest<K, V
|
|||||||
assertFalse(getMap().entrySet().contains(null));
|
assertFalse(getMap().entrySet().contains(null));
|
||||||
assertFalse(getMap().keySet().contains(null));
|
assertFalse(getMap().keySet().contains(null));
|
||||||
assertFalse(getMap().values().contains(null));
|
assertFalse(getMap().values().contains(null));
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> getMap().put(null, null));
|
||||||
getMap().put(null, null);
|
assertThrows(NullPointerException.class, () -> getMap().put((K) new Object(), null));
|
||||||
fail();
|
assertThrows(NullPointerException.class, () -> getMap().put(null, (V) new Object()));
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
try {
|
|
||||||
getMap().put((K) new Object(), null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
try {
|
|
||||||
getMap().put(null, (V) new Object());
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tests whether purge values setting works */
|
/** Tests whether purge values setting works */
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.map;
|
package org.apache.commons.collections4.map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -37,7 +39,6 @@ import junit.framework.Test;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for ReferenceMap.
|
* Tests for ReferenceMap.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ReferenceMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
public class ReferenceMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
||||||
|
|
||||||
@ -90,18 +91,9 @@ public class ReferenceMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
|||||||
assertFalse(map.entrySet().contains(null));
|
assertFalse(map.entrySet().contains(null));
|
||||||
assertFalse(map.containsKey(null));
|
assertFalse(map.containsKey(null));
|
||||||
assertFalse(map.containsValue(null));
|
assertFalse(map.containsValue(null));
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> map.put(null, null));
|
||||||
map.put(null, null);
|
assertThrows(NullPointerException.class, () -> map.put((K) new Object(), null));
|
||||||
fail();
|
assertThrows(NullPointerException.class, () -> map.put(null, (V) new Object()));
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
try {
|
|
||||||
map.put((K) new Object(), null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
try {
|
|
||||||
map.put(null, (V) new Object());
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -345,4 +337,5 @@ public class ReferenceMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.map;
|
package org.apache.commons.collections4.map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
@ -77,18 +79,15 @@ public class TransformedSortedMapTest<K, V> extends AbstractSortedMapTest<K, V>
|
|||||||
map.put((K) els[i], (V) els[i]);
|
map.put((K) els[i], (V) els[i]);
|
||||||
assertEquals(i + 1, map.size());
|
assertEquals(i + 1, map.size());
|
||||||
assertTrue(map.containsKey(Integer.valueOf((String) els[i])));
|
assertTrue(map.containsKey(Integer.valueOf((String) els[i])));
|
||||||
try {
|
SortedMap<K, V> finalMap1 = map;
|
||||||
map.containsKey(els[i]);
|
int finalI = i;
|
||||||
fail();
|
assertThrows(ClassCastException.class, () -> finalMap1.containsKey(els[finalI]));
|
||||||
} catch (final ClassCastException ex) {}
|
|
||||||
assertTrue(map.containsValue(els[i]));
|
assertTrue(map.containsValue(els[i]));
|
||||||
assertEquals(els[i], map.get(Integer.valueOf((String) els[i])));
|
assertEquals(els[i], map.get(Integer.valueOf((String) els[i])));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
SortedMap<K, V> finalMap = map;
|
||||||
map.remove(els[0]);
|
assertThrows(ClassCastException.class, () -> finalMap.remove(els[0]));
|
||||||
fail();
|
|
||||||
} catch (final ClassCastException ex) {}
|
|
||||||
assertEquals(els[0], map.remove(Integer.valueOf((String) els[0])));
|
assertEquals(els[0], map.remove(Integer.valueOf((String) els[0])));
|
||||||
|
|
||||||
map = TransformedSortedMap
|
map = TransformedSortedMap
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.multimap;
|
package org.apache.commons.collections4.multimap;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -555,13 +557,9 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
test.put((K) "key", (V) "object0");
|
test.put((K) "key", (V) "object0");
|
||||||
test.putAll(original);
|
test.putAll(original);
|
||||||
|
|
||||||
try {
|
|
||||||
final MultiValuedMap<K, V> originalNull = null;
|
final MultiValuedMap<K, V> originalNull = null;
|
||||||
test.putAll(originalNull);
|
assertThrows(NullPointerException.class, () -> test.putAll(originalNull),
|
||||||
fail("expecting NullPointerException");
|
"expecting NullPointerException");
|
||||||
} catch (final NullPointerException npe) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(2, test.keySet().size());
|
assertEquals(2, test.keySet().size());
|
||||||
assertEquals(4, test.size());
|
assertEquals(4, test.size());
|
||||||
@ -587,13 +585,9 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
test.put((K) "keyX", (V) "object0");
|
test.put((K) "keyX", (V) "object0");
|
||||||
test.putAll(original);
|
test.putAll(original);
|
||||||
|
|
||||||
try {
|
|
||||||
final Map<K, V> originalNull = null;
|
final Map<K, V> originalNull = null;
|
||||||
test.putAll(originalNull);
|
assertThrows(NullPointerException.class, () -> test.putAll(originalNull),
|
||||||
fail("expecting NullPointerException");
|
"expecting NullPointerException");
|
||||||
} catch (final NullPointerException npe) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(3, test.keySet().size());
|
assertEquals(3, test.keySet().size());
|
||||||
assertEquals(4, test.size());
|
assertEquals(4, test.size());
|
||||||
@ -620,12 +614,8 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
assertTrue(map.containsMapping("A", "Y"));
|
assertTrue(map.containsMapping("A", "Y"));
|
||||||
assertTrue(map.containsMapping("A", "Z"));
|
assertTrue(map.containsMapping("A", "Z"));
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> map.putAll((K) "A", null),
|
||||||
map.putAll((K) "A", null);
|
"expecting NullPointerException");
|
||||||
fail("expecting NullPointerException");
|
|
||||||
} catch (final NullPointerException npe) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(3, map.get((K) "A").size());
|
assertEquals(3, map.get((K) "A").size());
|
||||||
assertTrue(map.containsMapping("A", "X"));
|
assertTrue(map.containsMapping("A", "X"));
|
||||||
@ -680,13 +670,9 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
"{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString())
|
"{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString())
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
|
||||||
final MultiValuedMap<K, V> originalNull = null;
|
final MultiValuedMap<K, V> originalNull = null;
|
||||||
map.putAll(originalNull);
|
assertThrows(NullPointerException.class, () -> map.putAll(originalNull),
|
||||||
fail("expecting NullPointerException");
|
"expecting NullPointerException");
|
||||||
} catch (final NullPointerException npe) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"{A=[X, Y, Z], B=[U, V, W]}".equals(map.toString()) ||
|
"{A=[X, Y, Z], B=[U, V, W]}".equals(map.toString()) ||
|
||||||
"{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString())
|
"{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString())
|
||||||
@ -786,33 +772,17 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
resetFull();
|
resetFull();
|
||||||
final MapIterator<K, V> mapIt = getMap().mapIterator();
|
final MapIterator<K, V> mapIt = getMap().mapIterator();
|
||||||
mapIt.next();
|
mapIt.next();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> mapIt.setValue((V) "some value"));
|
||||||
mapIt.setValue((V) "some value");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultiValuedMapIterator() {
|
public void testMultiValuedMapIterator() {
|
||||||
final MultiValuedMap<K, V> map = makeFullMap();
|
final MultiValuedMap<K, V> map = makeFullMap();
|
||||||
final MapIterator<K, V> it = map.mapIterator();
|
final MapIterator<K, V> it = map.mapIterator();
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.getKey());
|
||||||
it.getKey();
|
assertThrows(IllegalStateException.class, () -> it.getValue());
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ise) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
it.getValue();
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ise) {
|
|
||||||
}
|
|
||||||
if (isAddSupported()) {
|
if (isAddSupported()) {
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.setValue((V) "V"));
|
||||||
it.setValue((V) "V");
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalStateException ise) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isHashSetValue() && isAddSupported()) {
|
if (!isHashSetValue() && isAddSupported()) {
|
||||||
@ -835,11 +805,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
assertEquals("three", it.next());
|
assertEquals("three", it.next());
|
||||||
assertEquals("three", it.getKey());
|
assertEquals("three", it.getKey());
|
||||||
assertEquals("trois", it.getValue());
|
assertEquals("trois", it.getValue());
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> it.setValue((V) "threetrois"));
|
||||||
it.setValue((V) "threetrois");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1259,4 +1225,5 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.multimap;
|
package org.apache.commons.collections4.multimap;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -93,57 +95,34 @@ public class UnmodifiableMultiValuedMapTest<K, V> extends AbstractMultiValuedMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testDecoratorFactoryNullMap() {
|
public void testDecoratorFactoryNullMap() {
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> UnmodifiableMultiValuedMap.unmodifiableMultiValuedMap(null),
|
||||||
UnmodifiableMultiValuedMap.unmodifiableMultiValuedMap(null);
|
"map must not be null");
|
||||||
fail("map must not be null");
|
|
||||||
} catch (final NullPointerException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testAddException() {
|
public void testAddException() {
|
||||||
final MultiValuedMap<K, V> map = makeObject();
|
final MultiValuedMap<K, V> map = makeObject();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> map.put((K) "one", (V) "uno"));
|
||||||
map.put((K) "one", (V) "uno");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveException() {
|
public void testRemoveException() {
|
||||||
final MultiValuedMap<K, V> map = makeFullMap();
|
final MultiValuedMap<K, V> map = makeFullMap();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> map.remove("one"),
|
||||||
map.remove("one");
|
"not support remove() method UnmodifiableMultiValuedMap does not support change");
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected, not support remove() method
|
|
||||||
// UnmodifiableMultiValuedMap does not support change
|
|
||||||
}
|
|
||||||
this.assertMapContainsAllValues(map);
|
this.assertMapContainsAllValues(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveMappingException() {
|
public void testRemoveMappingException() {
|
||||||
final MultiValuedMap<K, V> map = makeFullMap();
|
final MultiValuedMap<K, V> map = makeFullMap();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> map.removeMapping("one", "uno"),
|
||||||
map.removeMapping("one", "uno");
|
"expected, not support removeMapping() method UnmodifiableMultiValuedMap does not support change");
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected, not support removeMapping() method
|
|
||||||
// UnmodifiableMultiValuedMap does not support change
|
|
||||||
}
|
|
||||||
this.assertMapContainsAllValues(map);
|
this.assertMapContainsAllValues(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClearException() {
|
public void testClearException() {
|
||||||
final MultiValuedMap<K, V> map = makeFullMap();
|
final MultiValuedMap<K, V> map = makeFullMap();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> map.clear(),
|
||||||
map.clear();
|
"expected, not support clear() method UnmodifiableMultiValuedMap does not support change");
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected, not support clear() method
|
|
||||||
// UnmodifiableMultiValuedMap does not support change
|
|
||||||
}
|
|
||||||
this.assertMapContainsAllValues(map);
|
this.assertMapContainsAllValues(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,29 +136,14 @@ public class UnmodifiableMultiValuedMapTest<K, V> extends AbstractMultiValuedMap
|
|||||||
originalMap.put((K) "keyX", (V) "object1");
|
originalMap.put((K) "keyX", (V) "object1");
|
||||||
originalMap.put((K) "keyY", (V) "object2");
|
originalMap.put((K) "keyY", (V) "object2");
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> map.putAll(original),
|
||||||
map.putAll(original);
|
"expected, not support putAll() method UnmodifiableMultiValuedMap does not support change");
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected, not support putAll() method
|
|
||||||
// UnmodifiableMultiValuedMap does not support change
|
|
||||||
}
|
|
||||||
assertEquals("{}", map.toString());
|
assertEquals("{}", map.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> map.putAll(originalMap));
|
||||||
map.putAll(originalMap);
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertEquals("{}", map.toString());
|
assertEquals("{}", map.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> map.putAll((K) "A", coll));
|
||||||
map.putAll((K) "A", coll);
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertEquals("{}", map.toString());
|
assertEquals("{}", map.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,161 +151,77 @@ public class UnmodifiableMultiValuedMapTest<K, V> extends AbstractMultiValuedMap
|
|||||||
public void testUnmodifiableEntries() {
|
public void testUnmodifiableEntries() {
|
||||||
resetFull();
|
resetFull();
|
||||||
final Collection<Entry<K, V>> entries = getMap().entries();
|
final Collection<Entry<K, V>> entries = getMap().entries();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> entries.clear());
|
||||||
entries.clear();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
final Iterator<Entry<K, V>> it = entries.iterator();
|
final Iterator<Entry<K, V>> it = entries.iterator();
|
||||||
final Entry<K, V> entry = it.next();
|
final Entry<K, V> entry = it.next();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> it.remove());
|
||||||
it.remove();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> entry.setValue((V) "three"));
|
||||||
entry.setValue((V) "three");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnmodifiableMapIterator() {
|
public void testUnmodifiableMapIterator() {
|
||||||
resetFull();
|
resetFull();
|
||||||
final MapIterator<K, V> mapIt = getMap().mapIterator();
|
final MapIterator<K, V> mapIt = getMap().mapIterator();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> mapIt.remove());
|
||||||
mapIt.remove();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> mapIt.setValue((V) "three"));
|
||||||
mapIt.setValue((V) "three");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnmodifiableKeySet() {
|
public void testUnmodifiableKeySet() {
|
||||||
resetFull();
|
resetFull();
|
||||||
final Set<K> keySet = getMap().keySet();
|
final Set<K> keySet = getMap().keySet();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> keySet.add((K) "four"));
|
||||||
keySet.add((K) "four");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> keySet.remove("four"));
|
||||||
keySet.remove("four");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> keySet.clear());
|
||||||
keySet.clear();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
final Iterator<K> it = keySet.iterator();
|
final Iterator<K> it = keySet.iterator();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> it.remove());
|
||||||
it.remove();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnmodifiableValues() {
|
public void testUnmodifiableValues() {
|
||||||
resetFull();
|
resetFull();
|
||||||
final Collection<V> values = getMap().values();
|
final Collection<V> values = getMap().values();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> values.add((V) "four"));
|
||||||
values.add((V) "four");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> values.remove("four"));
|
||||||
values.remove("four");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> values.clear());
|
||||||
values.clear();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
final Iterator<V> it = values.iterator();
|
final Iterator<V> it = values.iterator();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> it.remove());
|
||||||
it.remove();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnmodifiableAsMap() {
|
public void testUnmodifiableAsMap() {
|
||||||
resetFull();
|
resetFull();
|
||||||
final Map<K, Collection<V>> mapCol = getMap().asMap();
|
final Map<K, Collection<V>> mapCol = getMap().asMap();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> mapCol.put((K) "four", (Collection<V>) Arrays.asList("four")));
|
||||||
mapCol.put((K) "four", (Collection<V>) Arrays.asList("four"));
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> mapCol.remove("four"));
|
||||||
mapCol.remove("four");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> mapCol.clear());
|
||||||
mapCol.clear();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> mapCol.clear());
|
||||||
mapCol.clear();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnmodifiableKeys() {
|
public void testUnmodifiableKeys() {
|
||||||
resetFull();
|
resetFull();
|
||||||
final MultiSet<K> keys = getMap().keys();
|
final MultiSet<K> keys = getMap().keys();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> keys.add((K) "four"));
|
||||||
keys.add((K) "four");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> keys.remove("four"));
|
||||||
keys.remove("four");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> keys.clear());
|
||||||
keys.clear();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
final Iterator<K> it = keys.iterator();
|
final Iterator<K> it = keys.iterator();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> it.remove());
|
||||||
it.remove();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void testCreate() throws Exception {
|
// public void testCreate() throws Exception {
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.multiset;
|
package org.apache.commons.collections4.multiset;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -374,12 +376,8 @@ public abstract class AbstractMultiSetTest<T> extends AbstractCollectionTest<T>
|
|||||||
final Iterator<T> it = multiset.iterator();
|
final Iterator<T> it = multiset.iterator();
|
||||||
it.next();
|
it.next();
|
||||||
multiset.remove("A");
|
multiset.remove("A");
|
||||||
try {
|
assertThrows(ConcurrentModificationException.class, () -> it.next(),
|
||||||
it.next();
|
"Should throw ConcurrentModificationException");
|
||||||
fail("Should throw ConcurrentModificationException");
|
|
||||||
} catch (final ConcurrentModificationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -396,12 +394,8 @@ public abstract class AbstractMultiSetTest<T> extends AbstractCollectionTest<T>
|
|||||||
it.next();
|
it.next();
|
||||||
it.next();
|
it.next();
|
||||||
it.next();
|
it.next();
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> it.next(),
|
||||||
it.next();
|
"Should throw NoSuchElementException");
|
||||||
fail("Should throw NoSuchElementException");
|
|
||||||
} catch (final NoSuchElementException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -420,12 +414,8 @@ public abstract class AbstractMultiSetTest<T> extends AbstractCollectionTest<T>
|
|||||||
assertEquals(3, multiset.size());
|
assertEquals(3, multiset.size());
|
||||||
it.remove();
|
it.remove();
|
||||||
assertEquals(2, multiset.size());
|
assertEquals(2, multiset.size());
|
||||||
try {
|
assertThrows(IllegalStateException.class, () -> it.remove(),
|
||||||
it.remove();
|
"Should throw IllegalStateException");
|
||||||
fail("Should throw IllegalStateException");
|
|
||||||
} catch (final IllegalStateException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertEquals(2, multiset.size());
|
assertEquals(2, multiset.size());
|
||||||
it.next();
|
it.next();
|
||||||
it.remove();
|
it.remove();
|
||||||
@ -707,4 +697,5 @@ public abstract class AbstractMultiSetTest<T> extends AbstractCollectionTest<T>
|
|||||||
assertEquals(multiset, multiset2);
|
assertEquals(multiset, multiset2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.multiset;
|
package org.apache.commons.collections4.multiset;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
@ -86,12 +88,8 @@ public class PredicatedMultiSetTest<T> extends AbstractMultiSetTest<T> {
|
|||||||
public void testIllegalAdd() {
|
public void testIllegalAdd() {
|
||||||
final MultiSet<T> multiset = makeTestMultiSet();
|
final MultiSet<T> multiset = makeTestMultiSet();
|
||||||
final Integer i = Integer.valueOf(3);
|
final Integer i = Integer.valueOf(3);
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> multiset.add((T) i),
|
||||||
multiset.add((T) i);
|
"Integer should fail string predicate.");
|
||||||
fail("Integer should fail string predicate.");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertFalse("Collection shouldn't contain illegal element", multiset.contains(i));
|
assertFalse("Collection shouldn't contain illegal element", multiset.contains(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,18 +100,10 @@ public class PredicatedMultiSetTest<T> extends AbstractMultiSetTest<T> {
|
|||||||
elements.add("two");
|
elements.add("two");
|
||||||
elements.add(Integer.valueOf(3));
|
elements.add(Integer.valueOf(3));
|
||||||
elements.add("four");
|
elements.add("four");
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> decorateMultiSet((HashMultiSet<T>) elements, stringPredicate()),
|
||||||
decorateMultiSet((HashMultiSet<T>) elements, stringPredicate());
|
"MultiSet contains an element that should fail the predicate.");
|
||||||
fail("MultiSet contains an element that should fail the predicate.");
|
assertThrows(NullPointerException.class, () -> decorateMultiSet(new HashMultiSet<T>(), null),
|
||||||
} catch (final IllegalArgumentException e) {
|
"Expecting NullPointerException for null predicate.");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
decorateMultiSet(new HashMultiSet<T>(), null);
|
|
||||||
fail("Expecting NullPointerException for null predicate.");
|
|
||||||
} catch (final NullPointerException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.multiset;
|
package org.apache.commons.collections4.multiset;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
@ -82,38 +84,26 @@ public class UnmodifiableMultiSetTest<E> extends AbstractMultiSetTest<E> {
|
|||||||
final MultiSet<E> multiset = makeFullCollection();
|
final MultiSet<E> multiset = makeFullCollection();
|
||||||
assertSame(multiset, UnmodifiableMultiSet.unmodifiableMultiSet(multiset));
|
assertSame(multiset, UnmodifiableMultiSet.unmodifiableMultiSet(multiset));
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> UnmodifiableMultiSet.unmodifiableMultiSet(null));
|
||||||
UnmodifiableMultiSet.unmodifiableMultiSet(null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testAdd() {
|
public void testAdd() {
|
||||||
final MultiSet<E> multiset = makeFullCollection();
|
final MultiSet<E> multiset = makeFullCollection();
|
||||||
final MultiSet<E> unmodifiableMultiSet = UnmodifiableMultiSet.unmodifiableMultiSet(multiset);
|
final MultiSet<E> unmodifiableMultiSet = UnmodifiableMultiSet.unmodifiableMultiSet(multiset);
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> unmodifiableMultiSet.add((E) "One", 1));
|
||||||
unmodifiableMultiSet.add((E) "One", 1);
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemove() {
|
public void testRemove() {
|
||||||
final MultiSet<E> multiset = makeFullCollection();
|
final MultiSet<E> multiset = makeFullCollection();
|
||||||
final MultiSet<E> unmodifiableMultiSet = UnmodifiableMultiSet.unmodifiableMultiSet(multiset);
|
final MultiSet<E> unmodifiableMultiSet = UnmodifiableMultiSet.unmodifiableMultiSet(multiset);
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> unmodifiableMultiSet.remove("One", 1));
|
||||||
unmodifiableMultiSet.remove("One", 1);
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetCount() {
|
public void testSetCount() {
|
||||||
final MultiSet<E> multiset = makeFullCollection();
|
final MultiSet<E> multiset = makeFullCollection();
|
||||||
final MultiSet<E> unmodifiableMultiSet = UnmodifiableMultiSet.unmodifiableMultiSet(multiset);
|
final MultiSet<E> unmodifiableMultiSet = UnmodifiableMultiSet.unmodifiableMultiSet(multiset);
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> unmodifiableMultiSet.setCount((E) "One", 2));
|
||||||
unmodifiableMultiSet.setCount((E) "One", 2);
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEntrySet() {
|
public void testEntrySet() {
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.queue;
|
package org.apache.commons.collections4.queue;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -161,12 +163,8 @@ public abstract class AbstractQueueTest<E> extends AbstractCollectionTest<E> {
|
|||||||
public void testQueueElement() {
|
public void testQueueElement() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
|
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> getCollection().element(),
|
||||||
getCollection().element();
|
"Queue.element should throw NoSuchElementException");
|
||||||
fail("Queue.element should throw NoSuchElementException");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
|
|
||||||
@ -192,12 +190,8 @@ public abstract class AbstractQueueTest<E> extends AbstractCollectionTest<E> {
|
|||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> getCollection().element(),
|
||||||
getCollection().element();
|
"Queue.element should throw NoSuchElementException");
|
||||||
fail("Queue.element should throw NoSuchElementException");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -245,12 +239,8 @@ public abstract class AbstractQueueTest<E> extends AbstractCollectionTest<E> {
|
|||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
|
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> getCollection().remove(),
|
||||||
getCollection().remove();
|
"Queue.remove should throw NoSuchElementException");
|
||||||
fail("Queue.remove should throw NoSuchElementException");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
|
|
||||||
@ -262,12 +252,8 @@ public abstract class AbstractQueueTest<E> extends AbstractCollectionTest<E> {
|
|||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> getCollection().element(),
|
||||||
getCollection().element();
|
"Queue.remove should throw NoSuchElementException");
|
||||||
fail("Queue.remove should throw NoSuchElementException");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.queue;
|
package org.apache.commons.collections4.queue;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
@ -146,48 +148,29 @@ public class CircularFifoQueueTest<E> extends AbstractQueueTest<E> {
|
|||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> getCollection().remove(),
|
||||||
getCollection().remove();
|
"Empty queue should raise Underflow.");
|
||||||
fail("Empty queue should raise Underflow.");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that the constructor correctly throws an exception.
|
* Tests that the constructor correctly throws an exception.
|
||||||
*/
|
*/
|
||||||
public void testConstructorException1() {
|
public void testConstructorException1() {
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> new CircularFifoQueue<E>(0));
|
||||||
new CircularFifoQueue<E>(0);
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that the constructor correctly throws an exception.
|
* Tests that the constructor correctly throws an exception.
|
||||||
*/
|
*/
|
||||||
public void testConstructorException2() {
|
public void testConstructorException2() {
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> new CircularFifoQueue<E>(-20));
|
||||||
new CircularFifoQueue<E>(-20);
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that the constructor correctly throws an exception.
|
* Tests that the constructor correctly throws an exception.
|
||||||
*/
|
*/
|
||||||
public void testConstructorException3() {
|
public void testConstructorException3() {
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> new CircularFifoQueue<E>(null));
|
||||||
new CircularFifoQueue<E>(null);
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -419,13 +402,7 @@ public class CircularFifoQueueTest<E> extends AbstractQueueTest<E> {
|
|||||||
|
|
||||||
public void testAddNull() {
|
public void testAddNull() {
|
||||||
final CircularFifoQueue<E> b = new CircularFifoQueue<>(2);
|
final CircularFifoQueue<E> b = new CircularFifoQueue<>(2);
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> b.add(null));
|
||||||
b.add(null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultSizeAndGetError1() {
|
public void testDefaultSizeAndGetError1() {
|
||||||
@ -437,12 +414,7 @@ public class CircularFifoQueueTest<E> extends AbstractQueueTest<E> {
|
|||||||
fifo.add((E) "4");
|
fifo.add((E) "4");
|
||||||
fifo.add((E) "5");
|
fifo.add((E) "5");
|
||||||
assertEquals(5, fifo.size());
|
assertEquals(5, fifo.size());
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> fifo.get(5));
|
||||||
fifo.get(5);
|
|
||||||
} catch (final NoSuchElementException ex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultSizeAndGetError2() {
|
public void testDefaultSizeAndGetError2() {
|
||||||
@ -454,12 +426,7 @@ public class CircularFifoQueueTest<E> extends AbstractQueueTest<E> {
|
|||||||
fifo.add((E) "4");
|
fifo.add((E) "4");
|
||||||
fifo.add((E) "5");
|
fifo.add((E) "5");
|
||||||
assertEquals(5, fifo.size());
|
assertEquals(5, fifo.size());
|
||||||
try {
|
assertThrows(NoSuchElementException.class, () -> fifo.get(-2));
|
||||||
fifo.get(-2);
|
|
||||||
} catch (final NoSuchElementException ex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.queue;
|
package org.apache.commons.collections4.queue;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -80,10 +82,7 @@ public class UnmodifiableQueueTest<E> extends AbstractQueueTest<E> {
|
|||||||
@Override
|
@Override
|
||||||
public void testQueueRemove() {
|
public void testQueueRemove() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> getCollection().remove());
|
||||||
getCollection().remove();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUnmodifiable() {
|
public void testUnmodifiable() {
|
||||||
@ -95,27 +94,18 @@ public class UnmodifiableQueueTest<E> extends AbstractQueueTest<E> {
|
|||||||
final Queue<E> queue = makeFullCollection();
|
final Queue<E> queue = makeFullCollection();
|
||||||
assertSame(queue, UnmodifiableQueue.unmodifiableQueue(queue));
|
assertSame(queue, UnmodifiableQueue.unmodifiableQueue(queue));
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> UnmodifiableQueue.unmodifiableQueue(null));
|
||||||
UnmodifiableQueue.unmodifiableQueue(null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOffer() {
|
public void testOffer() {
|
||||||
final Queue<E> queue = makeFullCollection();
|
final Queue<E> queue = makeFullCollection();
|
||||||
final E e = null;
|
final E e = null;
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> queue.offer(e));
|
||||||
queue.offer(e);
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPoll() {
|
public void testPoll() {
|
||||||
final Queue<E> queue = makeFullCollection();
|
final Queue<E> queue = makeFullCollection();
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> queue.poll());
|
||||||
queue.poll();
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.set;
|
package org.apache.commons.collections4.set;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -30,6 +32,7 @@ import org.apache.commons.collections4.set.CompositeSet.SetMutator;
|
|||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class CompositeSetTest<E> extends AbstractSetTest<E> {
|
public class CompositeSetTest<E> extends AbstractSetTest<E> {
|
||||||
|
|
||||||
public CompositeSetTest(final String name) {
|
public CompositeSetTest(final String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
@ -129,12 +132,8 @@ public class CompositeSetTest<E> extends AbstractSetTest<E> {
|
|||||||
|
|
||||||
final HashSet<E> three = new HashSet<>();
|
final HashSet<E> three = new HashSet<>();
|
||||||
three.add((E) "1");
|
three.add((E) "1");
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> set.addComposited(three),
|
||||||
set.addComposited(three);
|
"IllegalArgumentException should have been thrown");
|
||||||
fail("IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -159,12 +158,8 @@ public class CompositeSetTest<E> extends AbstractSetTest<E> {
|
|||||||
final CompositeSet<E> set5 = new CompositeSet<>(set3);
|
final CompositeSet<E> set5 = new CompositeSet<>(set3);
|
||||||
set5.addComposited(set4);
|
set5.addComposited(set4);
|
||||||
assertEquals(set, set5);
|
assertEquals(set, set5);
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> set.addComposited(set3),
|
||||||
set.addComposited(set3);
|
"Expecting UnsupportedOperationException.");
|
||||||
fail("Expecting UnsupportedOperationException.");
|
|
||||||
} catch (final UnsupportedOperationException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -176,18 +171,10 @@ public class CompositeSetTest<E> extends AbstractSetTest<E> {
|
|||||||
final HashSet<E> set2 = new HashSet<>();
|
final HashSet<E> set2 = new HashSet<>();
|
||||||
set2.add((E) "4");
|
set2.add((E) "4");
|
||||||
final CompositeSet<E> set3 = new CompositeSet<>(set1);
|
final CompositeSet<E> set3 = new CompositeSet<>(set1);
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> set3.addComposited(set1, buildOne()),
|
||||||
set3.addComposited(set1, buildOne());
|
"Expecting UnsupportedOperationException.");
|
||||||
fail("Expecting UnsupportedOperationException.");
|
assertThrows(UnsupportedOperationException.class, () -> set3.addComposited(set1, buildOne(), buildTwo()),
|
||||||
} catch (final UnsupportedOperationException ex) {
|
"Expecting UnsupportedOperationException.");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
set3.addComposited(set1, buildOne(), buildTwo());
|
|
||||||
fail("Expecting UnsupportedOperationException.");
|
|
||||||
} catch (final UnsupportedOperationException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.set;
|
package org.apache.commons.collections4.set;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -249,31 +252,13 @@ public class ListOrderedSetTest<E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testDecorator() {
|
public void testDecorator() {
|
||||||
try {
|
assertAll(
|
||||||
ListOrderedSet.listOrderedSet((List<E>) null);
|
() -> assertThrows(NullPointerException.class, () -> ListOrderedSet.listOrderedSet((List<E>) null)),
|
||||||
fail();
|
() -> assertThrows(NullPointerException.class, () -> ListOrderedSet.listOrderedSet((Set<E>) null)),
|
||||||
} catch (final NullPointerException ex) {
|
() -> assertThrows(NullPointerException.class, () -> ListOrderedSet.listOrderedSet(null, null)),
|
||||||
}
|
() -> assertThrows(NullPointerException.class, () -> ListOrderedSet.listOrderedSet(new HashSet<E>(), null)),
|
||||||
try {
|
() -> assertThrows(NullPointerException.class, () -> ListOrderedSet.listOrderedSet(null, new ArrayList<E>()))
|
||||||
ListOrderedSet.listOrderedSet((Set<E>) null);
|
);
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ListOrderedSet.listOrderedSet(null, null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ListOrderedSet.listOrderedSet(new HashSet<E>(), null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ListOrderedSet.listOrderedSet(null, new ArrayList<E>());
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.set;
|
package org.apache.commons.collections4.set;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.NavigableSet;
|
import java.util.NavigableSet;
|
||||||
@ -76,12 +78,8 @@ public class PredicatedNavigableSetTest<E> extends AbstractNavigableSetTest<E> {
|
|||||||
public void testIllegalAdd() {
|
public void testIllegalAdd() {
|
||||||
final NavigableSet<E> set = makeTestSet();
|
final NavigableSet<E> set = makeTestSet();
|
||||||
final String testString = "B";
|
final String testString = "B";
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> set.add((E) testString),
|
||||||
set.add((E) testString);
|
"Should fail string predicate.");
|
||||||
fail("Should fail string predicate.");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertFalse("Collection shouldn't contain illegal element", set.contains(testString));
|
assertFalse("Collection shouldn't contain illegal element", set.contains(testString));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,12 +91,8 @@ public class PredicatedNavigableSetTest<E> extends AbstractNavigableSetTest<E> {
|
|||||||
elements.add((E) "Atwo");
|
elements.add((E) "Atwo");
|
||||||
elements.add((E) "Bthree");
|
elements.add((E) "Bthree");
|
||||||
elements.add((E) "Afour");
|
elements.add((E) "Afour");
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> set.addAll(elements),
|
||||||
set.addAll(elements);
|
"Should fail string predicate.");
|
||||||
fail("Should fail string predicate.");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertFalse("Set shouldn't contain illegal element", set.contains("Aone"));
|
assertFalse("Set shouldn't contain illegal element", set.contains("Aone"));
|
||||||
assertFalse("Set shouldn't contain illegal element", set.contains("Atwo"));
|
assertFalse("Set shouldn't contain illegal element", set.contains("Atwo"));
|
||||||
assertFalse("Set shouldn't contain illegal element", set.contains("Bthree"));
|
assertFalse("Set shouldn't contain illegal element", set.contains("Bthree"));
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.set;
|
package org.apache.commons.collections4.set;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -71,12 +73,8 @@ public class PredicatedSetTest<E> extends AbstractSetTest<E> {
|
|||||||
public void testIllegalAdd() {
|
public void testIllegalAdd() {
|
||||||
final Set<E> set = makeTestSet();
|
final Set<E> set = makeTestSet();
|
||||||
final Integer i = Integer.valueOf(3);
|
final Integer i = Integer.valueOf(3);
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> set.add((E) i),
|
||||||
set.add((E) i);
|
"Integer should fail string predicate.");
|
||||||
fail("Integer should fail string predicate.");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertFalse("Collection shouldn't contain illegal element", set.contains(i));
|
assertFalse("Collection shouldn't contain illegal element", set.contains(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,12 +86,8 @@ public class PredicatedSetTest<E> extends AbstractSetTest<E> {
|
|||||||
elements.add((E) "two");
|
elements.add((E) "two");
|
||||||
elements.add((E) Integer.valueOf(3));
|
elements.add((E) Integer.valueOf(3));
|
||||||
elements.add((E) "four");
|
elements.add((E) "four");
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> set.addAll(elements),
|
||||||
set.addAll(elements);
|
"Integer should fail string predicate.");
|
||||||
fail("Integer should fail string predicate.");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertFalse("Set shouldn't contain illegal element", set.contains("one"));
|
assertFalse("Set shouldn't contain illegal element", set.contains("one"));
|
||||||
assertFalse("Set shouldn't contain illegal element", set.contains("two"));
|
assertFalse("Set shouldn't contain illegal element", set.contains("two"));
|
||||||
assertFalse("Set shouldn't contain illegal element", set.contains(Integer.valueOf(3)));
|
assertFalse("Set shouldn't contain illegal element", set.contains(Integer.valueOf(3)));
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.set;
|
package org.apache.commons.collections4.set;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -73,12 +75,8 @@ public class PredicatedSortedSetTest<E> extends AbstractSortedSetTest<E> {
|
|||||||
public void testIllegalAdd() {
|
public void testIllegalAdd() {
|
||||||
final SortedSet<E> set = makeTestSet();
|
final SortedSet<E> set = makeTestSet();
|
||||||
final String testString = "B";
|
final String testString = "B";
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> set.add((E) testString),
|
||||||
set.add((E) testString);
|
"Should fail string predicate.");
|
||||||
fail("Should fail string predicate.");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertFalse("Collection shouldn't contain illegal element", set.contains(testString));
|
assertFalse("Collection shouldn't contain illegal element", set.contains(testString));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,12 +88,8 @@ public class PredicatedSortedSetTest<E> extends AbstractSortedSetTest<E> {
|
|||||||
elements.add((E) "Atwo");
|
elements.add((E) "Atwo");
|
||||||
elements.add((E) "Bthree");
|
elements.add((E) "Bthree");
|
||||||
elements.add((E) "Afour");
|
elements.add((E) "Afour");
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> set.addAll(elements),
|
||||||
set.addAll(elements);
|
"Should fail string predicate.");
|
||||||
fail("Should fail string predicate.");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertFalse("Set shouldn't contain illegal element", set.contains("Aone"));
|
assertFalse("Set shouldn't contain illegal element", set.contains("Aone"));
|
||||||
assertFalse("Set shouldn't contain illegal element", set.contains("Atwo"));
|
assertFalse("Set shouldn't contain illegal element", set.contains("Atwo"));
|
||||||
assertFalse("Set shouldn't contain illegal element", set.contains("Bthree"));
|
assertFalse("Set shouldn't contain illegal element", set.contains("Bthree"));
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.set;
|
package org.apache.commons.collections4.set;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -91,10 +94,7 @@ public class UnmodifiableSortedSetTest<E> extends AbstractSortedSetTest<E> {
|
|||||||
final SortedSet<E> set = makeFullCollection();
|
final SortedSet<E> set = makeFullCollection();
|
||||||
assertSame(set, UnmodifiableSortedSet.unmodifiableSortedSet(set));
|
assertSame(set, UnmodifiableSortedSet.unmodifiableSortedSet(set));
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> UnmodifiableSortedSet.unmodifiableSortedSet(null));
|
||||||
UnmodifiableSortedSet.unmodifiableSortedSet(null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,42 +102,20 @@ public class UnmodifiableSortedSetTest<E> extends AbstractSortedSetTest<E> {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void verifyUnmodifiable(final Set<E> set) {
|
public void verifyUnmodifiable(final Set<E> set) {
|
||||||
try {
|
assertAll(
|
||||||
set.add((E) "value");
|
() -> assertThrows(UnsupportedOperationException.class, () -> set.add((E) "value"),
|
||||||
fail("Expecting UnsupportedOperationException.");
|
"Expecting UnsupportedOperationException."),
|
||||||
} catch (final UnsupportedOperationException e) {
|
() -> assertThrows(UnsupportedOperationException.class, () -> set.addAll(new TreeSet<E>()),
|
||||||
// expected
|
"Expecting UnsupportedOperationException."),
|
||||||
}
|
() -> assertThrows(UnsupportedOperationException.class, () -> set.clear(),
|
||||||
try {
|
"Expecting UnsupportedOperationException."),
|
||||||
set.addAll(new TreeSet<E>());
|
() -> assertThrows(UnsupportedOperationException.class, () -> set.remove("x"),
|
||||||
fail("Expecting UnsupportedOperationException.");
|
"Expecting UnsupportedOperationException."),
|
||||||
} catch (final UnsupportedOperationException e) {
|
() -> assertThrows(UnsupportedOperationException.class, () -> set.removeAll(array),
|
||||||
// expected
|
"Expecting UnsupportedOperationException."),
|
||||||
}
|
() -> assertThrows(UnsupportedOperationException.class, () -> set.retainAll(array),
|
||||||
try {
|
"Expecting UnsupportedOperationException.")
|
||||||
set.clear();
|
);
|
||||||
fail("Expecting UnsupportedOperationException.");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
set.remove("x");
|
|
||||||
fail("Expecting UnsupportedOperationException.");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
set.removeAll(array);
|
|
||||||
fail("Expecting UnsupportedOperationException.");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
set.retainAll(array);
|
|
||||||
fail("Expecting UnsupportedOperationException.");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testComparator() {
|
public void testComparator() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user