Skip to content

Commit

Permalink
[COLLECTIONS-809] JUnit v5 assertThrows (#291)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nhojpatrick committed Mar 16, 2022
1 parent eab0aa0 commit f55268b
Show file tree
Hide file tree
Showing 34 changed files with 532 additions and 1,280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1280,15 +1280,15 @@ public void testContainsAnyNullColl2() {
final Collection<String> list = new ArrayList<>(1);
list.add("1");
final Collection<String> list2 = null;
assertThrows(NullPointerException.class, () -> CollectionUtils.containsAny(list, list2));
assertThrows(NullPointerException.class, () -> CollectionUtils.containsAny(list, list2));
}

@Test
public void testContainsAnyNullColl3() {
final Collection<String> list = new ArrayList<>(1);
list.add("1");
final String[] array = null;
assertThrows(NullPointerException.class, () -> CollectionUtils.containsAny(list, array));
assertThrows(NullPointerException.class, () -> CollectionUtils.containsAny(list, array));
}

@Test
Expand All @@ -1311,19 +1311,19 @@ public void testDisjunctionAsUnionMinusIntersection() {
public void testDisjunctionNullColl1() {
final Collection<String> list = new ArrayList<>(1);
list.add("1");
assertThrows(NullPointerException.class, () -> CollectionUtils.disjunction(null, list));
assertThrows(NullPointerException.class, () -> CollectionUtils.disjunction(null, list));
}

@Test
public void testDisjunctionNullColl2() {
final Collection<String> list = new ArrayList<>(1);
list.add("1");
assertThrows(NullPointerException.class, () -> CollectionUtils.disjunction(list, null));
assertThrows(NullPointerException.class, () -> CollectionUtils.disjunction(list, null));
}

@Test
public void testGetCardinalityMapNull() {
assertThrows(NullPointerException.class, () -> CollectionUtils.getCardinalityMap(null));
assertThrows(NullPointerException.class, () -> CollectionUtils.getCardinalityMap(null));
}

@Test
Expand Down Expand Up @@ -1369,21 +1369,21 @@ public int hash(final Integer o) {

@Test
public void testHashCodeNullEquator() {
assertThrows(NullPointerException.class, () -> CollectionUtils.hashCode(collectionB, null));
assertThrows(NullPointerException.class, () -> CollectionUtils.hashCode(collectionB, null));
}

@Test
public void testIntersectionNullColl1() {
final Collection<String> list = new ArrayList<>(1);
list.add("1");
assertThrows(NullPointerException.class, () -> CollectionUtils.intersection(null, list));
assertThrows(NullPointerException.class, () -> CollectionUtils.intersection(null, list));
}

@Test
public void testIntersectionNullColl2() {
final Collection<String> list = new ArrayList<>(1);
list.add("1");
assertThrows(NullPointerException.class, () -> CollectionUtils.intersection(list, null));
assertThrows(NullPointerException.class, () -> CollectionUtils.intersection(list, null));
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -1482,7 +1482,7 @@ public int hash(final Integer o) {
return o.intValue() % 2 == 0 ? Integer.valueOf(0).hashCode() : Integer.valueOf(1).hashCode();
}
};
assertThrows(NullPointerException.class, () -> CollectionUtils.isEqualCollection(null, list, e));
assertThrows(NullPointerException.class, () -> CollectionUtils.isEqualCollection(null, list, e));
}

@Test
Expand All @@ -1504,12 +1504,12 @@ public int hash(final Integer o) {
return o.intValue() % 2 == 0 ? Integer.valueOf(0).hashCode() : Integer.valueOf(1).hashCode();
}
};
assertThrows(NullPointerException.class, () -> CollectionUtils.isEqualCollection(list, null, e));
assertThrows(NullPointerException.class, () -> CollectionUtils.isEqualCollection(list, null, e));
}

@Test
public void testIsEqualCollectionNullEquator() {
assertThrows(NullPointerException.class, () -> CollectionUtils.isEqualCollection(collectionA, collectionA, null));
assertThrows(NullPointerException.class, () -> CollectionUtils.isEqualCollection(collectionA, collectionA, null));
}

@Test
Expand All @@ -1530,7 +1530,7 @@ public void testIsEqualCollectionToSelf() {

@Test
public void testIsFullNullColl() {
assertThrows(NullPointerException.class, () -> CollectionUtils.isFull(null));
assertThrows(NullPointerException.class, () -> CollectionUtils.isFull(null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,27 +556,23 @@ public void testBidiMapIteratorSet() {

// at this point
// key1=newValue1, key2=newValue2
try {
it.setValue(newValue1); // should remove key1
fail();
} catch (final IllegalArgumentException ex) {
return; // simplest way of dealing with tricky situation
}
confirmed.put(key2, newValue1);
AbstractBidiMapTest.this.getConfirmed().remove(key1);
assertEquals(newValue1, it.getValue());
assertTrue(bidi.containsKey(it.getKey()));
assertTrue(bidi.containsValue(newValue1));
assertEquals(newValue1, bidi.get(it.getKey()));
assertFalse(bidi.containsKey(key1));
assertFalse(bidi.containsValue(newValue2));
verify();

// check for ConcurrentModification
it.next(); // if you fail here, maybe you should be throwing an IAE, see above
if (isRemoveSupported()) {
it.remove();
}
assertThrows(IllegalArgumentException.class, () -> it.setValue(newValue1)); // should remove key1
// below code was previously never executed
// confirmed.put(key2, newValue1);
// AbstractBidiMapTest.this.getConfirmed().remove(key1);
// assertEquals(newValue1, it.getValue());
// assertTrue(bidi.containsKey(it.getKey()));
// assertTrue(bidi.containsValue(newValue1));
// assertEquals(newValue1, bidi.get(it.getKey()));
// assertFalse(bidi.containsKey(key1));
// assertFalse(bidi.containsValue(newValue2));
// verify();
//
// // check for ConcurrentModification
// it.next(); // if you fail here, maybe you should be throwing an IAE, see above
// if (isRemoveSupported()) {
// it.remove();
// }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

/**
* JUnit tests.
*
*/
public class DualHashBidiMapTest<K, V> extends AbstractBidiMapTest<K, V> {

Expand Down Expand Up @@ -56,4 +55,5 @@ public String[] ignoredTests() {
// resetFull();
// writeExternalFormToDisk((java.io.Serializable) map, "src/test/resources/data/test/DualHashBidiMap.fullCollection.version4.obj");
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
*/
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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.List;
import java.util.PrimitiveIterator.OfInt;
Expand Down Expand Up @@ -261,12 +262,8 @@ public final void constructorTest_WrongShape() {

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);
try {
createFilter(hasher, shape);
fail("Should throw IllegalArgumentException");
} catch (final IllegalArgumentException expected) {
// do nothing.
}
assertThrows(IllegalArgumentException.class, () -> createFilter(hasher, shape),
"Should throw IllegalArgumentException");
}

/**
Expand Down Expand Up @@ -297,12 +294,8 @@ public final void containsTest_BloomFilter_WrongShape() {
final Shape anotherShape = new Shape(testFunctionX, 3, 72, 17);
final Hasher hasher2 = new StaticHasher(lst.iterator(), anotherShape);
final BloomFilter bf2 = createFilter(hasher2, anotherShape);
try {
bf.contains(bf2);
fail("Should throw IllegalArgumentException");
} catch (final IllegalArgumentException expected) {
// do nothing.
}
assertThrows(IllegalArgumentException.class, () -> bf.contains(bf2),
"Should throw IllegalArgumentException");
}

/**
Expand Down Expand Up @@ -340,12 +333,8 @@ public final void containsTest_Hasher_WrongShape() {

final List<Integer> lst2 = Arrays.asList(4, 5, 6, 7, 8, 9, 10);
final Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape);
try {
bf.contains(hasher2);
fail("Should have thrown IllegalArgumentException");
} catch (final IllegalArgumentException expected) {
// do nothing
}
assertThrows(IllegalArgumentException.class, () -> bf.contains(hasher2),
"Should have thrown IllegalArgumentException");
}

/**
Expand Down Expand Up @@ -485,12 +474,8 @@ public final void mergeTest_BloomFilter_WrongShape() {
final Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape);
final BloomFilter bf2 = createFilter(hasher2, anotherShape);

try {
bf.merge(bf2);
fail("Should throw IllegalArgumentException");
} catch (final IllegalArgumentException expected) {
// do nothing.
}
assertThrows(IllegalArgumentException.class, () -> bf.merge(bf2),
"Should throw IllegalArgumentException");
}

/**
Expand Down Expand Up @@ -524,12 +509,8 @@ public final void mergeTest_Hasher_WrongShape() {
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);

try {
bf.merge(hasher2);
fail("Should throw IllegalArgumentException");
} catch (final IllegalArgumentException expected) {
// do nothing.
}
assertThrows(IllegalArgumentException.class, () -> bf.merge(hasher2),
"Should throw IllegalArgumentException");
}

/**
Expand Down Expand Up @@ -638,4 +619,5 @@ public final void xorCardinalityTest_ExtraLongs() {
assertEquals(20, bf.xorCardinality(bf2));
assertEquals(20, bf2.xorCardinality(bf));
}

}
Loading

0 comments on commit f55268b

Please sign in to comment.