Skip to content

Commit

Permalink
Use Assertions.assertInstanceOf()
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Sep 1, 2024
1 parent e205e07 commit 03e5b0e
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 35 deletions.
18 changes: 9 additions & 9 deletions src/test/java/org/apache/commons/collections4/BagUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package org.apache.commons.collections4;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.commons.collections4.bag.HashBag;
import org.apache.commons.collections4.bag.PredicatedBag;
Expand All @@ -45,7 +45,7 @@ public class BagUtilsTest {
@Test
public void testPredicatedBag() {
final Bag<Object> bag = BagUtils.predicatedBag(new HashBag<>(), truePredicate);
assertTrue(bag instanceof PredicatedBag, "Returned object should be a PredicatedBag.");
assertInstanceOf(PredicatedBag.class, bag, "Returned object should be a PredicatedBag.");
assertAll(
() -> assertThrows(NullPointerException.class, () -> BagUtils.predicatedBag(null, truePredicate),
"Expecting NullPointerException for null bag."),
Expand All @@ -57,7 +57,7 @@ public void testPredicatedBag() {
@Test
public void testPredicatedSortedBag() {
final Bag<Object> bag = BagUtils.predicatedSortedBag(new TreeBag<>(), truePredicate);
assertTrue(bag instanceof PredicatedSortedBag, "Returned object should be a PredicatedSortedBag.");
assertInstanceOf(PredicatedSortedBag.class, bag, "Returned object should be a PredicatedSortedBag.");
assertAll(
() -> assertThrows(NullPointerException.class, () -> BagUtils.predicatedSortedBag(null, truePredicate),
"Expecting NullPointerException for null bag."),
Expand All @@ -69,23 +69,23 @@ public void testPredicatedSortedBag() {
@Test
public void testSynchronizedBag() {
final Bag<Object> bag = BagUtils.synchronizedBag(new HashBag<>());
assertTrue(bag instanceof SynchronizedBag, "Returned object should be a SynchronizedBag.");
assertInstanceOf(SynchronizedBag.class, bag, "Returned object should be a SynchronizedBag.");
assertThrows(NullPointerException.class, () -> BagUtils.synchronizedBag(null),
"Expecting NullPointerException for null bag.");
}

@Test
public void testSynchronizedSortedBag() {
final Bag<Object> bag = BagUtils.synchronizedSortedBag(new TreeBag<>());
assertTrue(bag instanceof SynchronizedSortedBag, "Returned object should be a SynchronizedSortedBag.");
assertInstanceOf(SynchronizedSortedBag.class, bag, "Returned object should be a SynchronizedSortedBag.");
assertThrows(NullPointerException.class, () -> BagUtils.synchronizedSortedBag(null),
"Expecting NullPointerException for null bag.");
}

@Test
public void testTransformedBag() {
final Bag<Object> bag = BagUtils.transformingBag(new HashBag<>(), nopTransformer);
assertTrue(bag instanceof TransformedBag, "Returned object should be an TransformedBag.");
assertInstanceOf(TransformedBag.class, bag, "Returned object should be an TransformedBag.");
assertAll(
() -> assertThrows(NullPointerException.class, () -> BagUtils.transformingBag(null, nopTransformer),
"Expecting NullPointerException for null bag."),
Expand All @@ -97,7 +97,7 @@ public void testTransformedBag() {
@Test
public void testTransformedSortedBag() {
final Bag<Object> bag = BagUtils.transformingSortedBag(new TreeBag<>(), nopTransformer);
assertTrue(bag instanceof TransformedSortedBag, "Returned object should be an TransformedSortedBag");
assertInstanceOf(TransformedSortedBag.class, bag, "Returned object should be an TransformedSortedBag");
assertAll(
() -> assertThrows(NullPointerException.class, () -> BagUtils.transformingSortedBag(null, nopTransformer),
"Expecting NullPointerException for null bag."),
Expand All @@ -109,7 +109,7 @@ public void testTransformedSortedBag() {
@Test
public void testUnmodifiableBag() {
final Bag<Object> bag = BagUtils.unmodifiableBag(new HashBag<>());
assertTrue(bag instanceof UnmodifiableBag, "Returned object should be an UnmodifiableBag.");
assertInstanceOf(UnmodifiableBag.class, bag, "Returned object should be an UnmodifiableBag.");
assertThrows(NullPointerException.class, () -> BagUtils.unmodifiableBag(null),
"Expecting NullPointerException for null bag.");
assertSame(bag, BagUtils.unmodifiableBag(bag), "UnmodifiableBag shall not be decorated");
Expand All @@ -118,7 +118,7 @@ public void testUnmodifiableBag() {
@Test
public void testUnmodifiableSortedBag() {
final SortedBag<Object> bag = BagUtils.unmodifiableSortedBag(new TreeBag<>());
assertTrue(bag instanceof UnmodifiableSortedBag, "Returned object should be an UnmodifiableSortedBag.");
assertInstanceOf(UnmodifiableSortedBag.class, bag, "Returned object should be an UnmodifiableSortedBag.");
assertThrows(NullPointerException.class, () -> BagUtils.unmodifiableSortedBag(null),
"Expecting NullPointerException for null bag.");
assertSame(bag, BagUtils.unmodifiableSortedBag(bag), "UnmodifiableSortedBag shall not be decorated");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -1746,7 +1747,7 @@ public void testPermutationsWithNullCollection() {
public void testPredicatedCollection() {
final Predicate<Object> predicate = PredicateUtils.instanceofPredicate(Integer.class);
final Collection<Number> collection = CollectionUtils.predicatedCollection(new ArrayList<>(), predicate);
assertTrue(collection instanceof PredicatedCollection, "returned object should be a PredicatedCollection");
assertInstanceOf(PredicatedCollection.class, collection, "returned object should be a PredicatedCollection");
}

@Test
Expand Down Expand Up @@ -2321,7 +2322,7 @@ public void testSubtractWithPredicate() {
@Deprecated
public void testSynchronizedCollection() {
final Collection<Object> col = CollectionUtils.synchronizedCollection(new ArrayList<>());
assertTrue(col instanceof SynchronizedCollection, "Returned object should be a SynchronizedCollection.");
assertInstanceOf(SynchronizedCollection.class, col, "Returned object should be a SynchronizedCollection.");

assertThrows(NullPointerException.class, () -> CollectionUtils.synchronizedCollection(null),
"Expecting NullPointerException for null collection.");
Expand Down Expand Up @@ -2366,7 +2367,7 @@ public void testTransform2() {
public void testTransformedCollection() {
final Transformer<Object, Object> transformer = TransformerUtils.nopTransformer();
final Collection<Object> collection = CollectionUtils.transformingCollection(new ArrayList<>(), transformer);
assertTrue(collection instanceof TransformedCollection, "returned object should be a TransformedCollection");
assertInstanceOf(TransformedCollection.class, collection, "returned object should be a TransformedCollection");
}

@Test
Expand Down Expand Up @@ -2430,7 +2431,7 @@ public void testUnionNullColl2() {
@Deprecated
public void testUnmodifiableCollection() {
final Collection<Object> col = CollectionUtils.unmodifiableCollection(new ArrayList<>());
assertTrue(col instanceof UnmodifiableCollection, "Returned object should be a UnmodifiableCollection.");
assertInstanceOf(UnmodifiableCollection.class, col, "Returned object should be a UnmodifiableCollection.");

assertThrows(NullPointerException.class, () -> CollectionUtils.unmodifiableCollection(null),
"Expecting NullPointerException for null collection.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
Expand Down Expand Up @@ -365,7 +366,7 @@ public void testPartition() {
public void testPredicatedList() {
final Predicate<Object> predicate = String.class::isInstance;
final List<Object> list = ListUtils.predicatedList(new ArrayList<>(), predicate);
assertTrue(list instanceof PredicatedList, "returned object should be a PredicatedList");
assertInstanceOf(PredicatedList.class, list, "returned object should be a PredicatedList");
assertAll(
() -> assertThrows(NullPointerException.class, () -> ListUtils.predicatedList(new ArrayList<>(), null),
"Expecting IllegalArgumentException for null predicate."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
Expand Down Expand Up @@ -737,7 +738,7 @@ public void testLazyMap() {
public void testLazyMapFactory() {
final Factory<Integer> factory = FactoryUtils.constantFactory(Integer.valueOf(5));
Map<Object, Object> map = MapUtils.lazyMap(new HashMap<>(), factory);
assertTrue(map instanceof LazyMap);
assertInstanceOf(LazyMap.class, map);
assertAll(
() -> assertThrows(NullPointerException.class, () -> MapUtils.lazyMap(new HashMap<>(), (Factory<Object>) null),
"Expecting NullPointerException for null factory"),
Expand All @@ -747,7 +748,7 @@ public void testLazyMapFactory() {

final Transformer<Object, Integer> transformer = TransformerUtils.asTransformer(factory);
map = MapUtils.lazyMap(new HashMap<>(), transformer);
assertTrue(map instanceof LazyMap);
assertInstanceOf(LazyMap.class, map);
assertAll(
() -> assertThrows(NullPointerException.class, () -> MapUtils.lazyMap(new HashMap<>(), (Transformer<Object, Object>) null),
"Expecting NullPointerException for null transformer"),
Expand Down Expand Up @@ -811,7 +812,7 @@ public void testOrderedMap() {
inMap.put("key1", "value1");
inMap.put("key2", "value2");
final Map<String, String> map = MapUtils.orderedMap(inMap);
assertTrue(map instanceof OrderedMap);
assertInstanceOf(OrderedMap.class, map);
}

@Test
Expand Down Expand Up @@ -876,7 +877,7 @@ public void testPopulateMultiMap() {
public void testPredicatedMap() {
final Predicate<Object> p = getPredicate();
final Map<Object, Object> map = MapUtils.predicatedMap(new HashMap<>(), p, p);
assertTrue(map instanceof PredicatedMap);
assertInstanceOf(PredicatedMap.class, map);

assertThrows(NullPointerException.class, () -> MapUtils.predicatedMap(null, p, p),
"Expecting NullPointerException for null map.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.commons.collections4;

import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -41,7 +42,7 @@ public class QueueUtilsTest {
@Test
public void testEmptyQueue() {
final Queue<Object> queue = QueueUtils.emptyQueue();
assertTrue(queue instanceof UnmodifiableQueue, "Returned object should be an UnmodifiableQueue.");
assertInstanceOf(UnmodifiableQueue.class, queue, "Returned object should be an UnmodifiableQueue.");
assertTrue(queue.isEmpty(), "Returned queue is not empty.");

assertThrows(UnsupportedOperationException.class, () -> queue.add(new Object()),
Expand All @@ -51,7 +52,7 @@ public void testEmptyQueue() {
@Test
public void testPredicatedQueue() {
final Queue<Object> queue = QueueUtils.predicatedQueue(new LinkedList<>(), truePredicate);
assertTrue(queue instanceof PredicatedQueue, "Returned object should be a PredicatedQueue.");
assertInstanceOf(PredicatedQueue.class, queue, "Returned object should be a PredicatedQueue.");

assertThrows(NullPointerException.class, () -> QueueUtils.predicatedQueue(null, truePredicate),
"Expecting NullPointerException for null queue.");
Expand All @@ -63,7 +64,7 @@ public void testPredicatedQueue() {
@Test
public void testSynchronizedQueue() {
final Queue<Object> queue = QueueUtils.synchronizedQueue(new LinkedList<>());
assertTrue(queue instanceof SynchronizedQueue, "Returned object should be a SynchronizedQueue.");
assertInstanceOf(SynchronizedQueue.class, queue, "Returned object should be a SynchronizedQueue.");

assertThrows(NullPointerException.class, () -> QueueUtils.synchronizedQueue(null),
"Expecting NullPointerException for null queue.");
Expand All @@ -72,7 +73,7 @@ public void testSynchronizedQueue() {
@Test
public void testTransformedQueue() {
final Queue<Object> queue = QueueUtils.transformingQueue(new LinkedList<>(), nopTransformer);
assertTrue(queue instanceof TransformedQueue, "Returned object should be an TransformedQueue.");
assertInstanceOf(TransformedQueue.class, queue, "Returned object should be an TransformedQueue.");

assertThrows(NullPointerException.class, () -> QueueUtils.transformingQueue(null, nopTransformer),
"Expecting NullPointerException for null queue.");
Expand All @@ -84,7 +85,7 @@ public void testTransformedQueue() {
@Test
public void testUnmodifiableQueue() {
final Queue<Object> queue = QueueUtils.unmodifiableQueue(new LinkedList<>());
assertTrue(queue instanceof UnmodifiableQueue, "Returned object should be an UnmodifiableQueue.");
assertInstanceOf(UnmodifiableQueue.class, queue, "Returned object should be an UnmodifiableQueue.");

assertThrows(NullPointerException.class, () -> QueueUtils.unmodifiableQueue(null),
"Expecting NullPointerException for null queue.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
Expand Down Expand Up @@ -210,7 +211,7 @@ public void testNewIdentityHashSet() {
public void testpredicatedSet() {
final Predicate<Object> predicate = String.class::isInstance;
final Set<Object> set = SetUtils.predicatedSet(new HashSet<>(), predicate);
assertTrue(set instanceof PredicatedSet, "returned object should be a PredicatedSet");
assertInstanceOf(PredicatedSet.class, set, "returned object should be a PredicatedSet");
assertAll(
() -> assertThrows(NullPointerException.class, () -> SetUtils.predicatedSet(new HashSet<>(), null),
"Expecting NullPointerException for null predicate."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -93,7 +94,7 @@ public void testReadableMap() {
}

// unmodifiable
assertTrue(map instanceof Unmodifiable);
assertInstanceOf(Unmodifiable.class, map);

// check individual operations
int sz = map.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package org.apache.commons.collections4;

import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.commons.collections4.trie.PatriciaTrie;
import org.apache.commons.collections4.trie.UnmodifiableTrie;
Expand All @@ -32,7 +32,7 @@ public class TrieUtilsTest {
@Test
public void testUnmodifiableTrie() {
final Trie<String, Object> trie = TrieUtils.unmodifiableTrie(new PatriciaTrie<>());
assertTrue(trie instanceof UnmodifiableTrie, "Returned object should be an UnmodifiableTrie.");
assertInstanceOf(UnmodifiableTrie.class, trie, "Returned object should be an UnmodifiableTrie.");

assertThrows(NullPointerException.class, () -> TrieUtils.unmodifiableTrie(null));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.apache.commons.collections4.comparators;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.FileNotFoundException;
Expand Down Expand Up @@ -159,7 +159,7 @@ public void testComparatorCompatibility() throws IOException, ClassNotFoundExcep
@Test
public void testComparatorIsSerializable() {
final Comparator<T> comparator = makeObject();
assertTrue(comparator instanceof Serializable,
assertInstanceOf(Serializable.class, comparator,
"This comparator should be Serializable.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package org.apache.commons.collections4.keyvalue;

import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Map;

Expand Down Expand Up @@ -89,7 +89,7 @@ public void testConstructors() {
assertSame(key, entry2.getKey());
assertSame(value, entry2.getValue());

assertTrue(entry instanceof Unmodifiable);
assertInstanceOf(Unmodifiable.class, entry);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import static org.apache.commons.collections4.map.LazySortedMap.lazySortedMap;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Comparator;
import java.util.Map;
Expand Down Expand Up @@ -133,7 +133,7 @@ public void testSortOrder() {
public void testTransformerDecorate() {
final Transformer<Object, Integer> transformer = TransformerUtils.asTransformer(oneFactory);
final SortedMap<Integer, Number> map = lazySortedMap(new TreeMap<>(), transformer);
assertTrue(map instanceof LazySortedMap);
assertInstanceOf(LazySortedMap.class, map);
assertAll(
() -> assertThrows(NullPointerException.class, () -> lazySortedMap(new TreeMap<>(), (Transformer<Integer, Number>) null),
"Expecting NullPointerException for null transformer"),
Expand Down
Loading

0 comments on commit 03e5b0e

Please sign in to comment.