Skip to content

Commit

Permalink
[COLLECTIONS-810] Change JUnit v3 to JUnitv4 Annotations (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhojpatrick committed Mar 18, 2022
1 parent f55268b commit b4edfcc
Show file tree
Hide file tree
Showing 156 changed files with 1,130 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;

import org.apache.commons.collections4.list.AbstractListTest;
import org.junit.Test;

/**
* Abstract test class for ArrayList.
Expand All @@ -37,6 +38,7 @@ public AbstractArrayListTest(final String testName) {
@Override
public abstract ArrayList<E> makeObject();

@Test
public void testNewArrayList() {
final ArrayList<E> list = makeObject();
assertTrue("New list is empty", list.isEmpty());
Expand All @@ -45,6 +47,7 @@ public void testNewArrayList() {
assertThrows(IndexOutOfBoundsException.class, () -> list.get(1));
}

@Test
@SuppressWarnings("unchecked")
public void testSearch() {
final ArrayList<E> list = makeObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.NoSuchElementException;

import org.apache.commons.collections4.list.AbstractListTest;
import org.junit.Test;

/**
* Tests base {@link java.util.LinkedList} methods and contracts.
Expand Down Expand Up @@ -67,6 +68,7 @@ protected LinkedList<T> getConfirmedLinkedList() {
/**
* Tests {@link LinkedList#addFirst(Object)}.
*/
@Test
@SuppressWarnings("unchecked")
public void testLinkedListAddFirst() {
if (!isAddSupported()) {
Expand All @@ -88,6 +90,7 @@ public void testLinkedListAddFirst() {
/**
* Tests {@link LinkedList#addLast(Object)}.
*/
@Test
@SuppressWarnings("unchecked")
public void testLinkedListAddLast() {
if (!isAddSupported()) {
Expand All @@ -109,6 +112,7 @@ public void testLinkedListAddLast() {
/**
* Tests {@link LinkedList#getFirst()}.
*/
@Test
public void testLinkedListGetFirst() {
resetEmpty();
assertThrows(NoSuchElementException.class, () -> getCollection().getFirst(),
Expand All @@ -126,6 +130,7 @@ public void testLinkedListGetFirst() {
/**
* Tests {@link LinkedList#getLast()}.
*/
@Test
public void testLinkedListGetLast() {
resetEmpty();
assertThrows(NoSuchElementException.class, () -> getCollection().getLast(),
Expand All @@ -143,6 +148,7 @@ public void testLinkedListGetLast() {
/**
* Tests {@link LinkedList#removeFirst()}.
*/
@Test
public void testLinkedListRemoveFirst() {
if (!isRemoveSupported()) {
return;
Expand All @@ -164,6 +170,7 @@ public void testLinkedListRemoveFirst() {
/**
* Tests {@link LinkedList#removeLast()}.
*/
@Test
public void testLinkedListRemoveLast() {
if (!isRemoveSupported()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4;

import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down Expand Up @@ -97,21 +99,25 @@ public boolean isEqualsCheckable() {
return true;
}

@Test
public void testObjectEqualsSelf() {
final Object obj = makeObject();
assertEquals("A Object should equal itself", obj, obj);
}

@Test
public void testEqualsNull() {
final Object obj = makeObject();
assertFalse(obj.equals(null)); // make sure this doesn't throw NPE either
}

@Test
public void testObjectHashCodeEqualsSelfHashCode() {
final Object obj = makeObject();
assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
}

@Test
public void testObjectHashCodeEqualsContract() {
final Object obj1 = makeObject();
if (obj1.equals(obj1)) {
Expand Down Expand Up @@ -141,6 +147,7 @@ protected Object serializeDeserialize(final Object obj) throws Exception {
return dest;
}

@Test
public void testSerializeDeserializeThenCompare() throws Exception {
final Object obj = makeObject();
if (obj instanceof Serializable && isTestSerialization()) {
Expand All @@ -159,6 +166,7 @@ public void testSerializeDeserializeThenCompare() throws Exception {
* @throws IOException
* @throws ClassNotFoundException
*/
@Test
public void testSimpleSerialization() throws Exception {
final Object o = makeObject();
if (o instanceof Serializable && isTestSerialization()) {
Expand All @@ -171,6 +179,7 @@ public void testSimpleSerialization() throws Exception {
* Tests serialization by comparing against a previously stored version in SCM.
* If the test object is serializable, confirm that a canonical form exists.
*/
@Test
public void testCanonicalEmptyCollectionExists() {
if (supportsEmptyCollections() && isTestSerialization() && !skipSerializedCanonicalTests()) {
final Object object = makeObject();
Expand All @@ -187,6 +196,7 @@ public void testCanonicalEmptyCollectionExists() {
* Tests serialization by comparing against a previously stored version in SCM.
* If the test object is serializable, confirm that a canonical form exists.
*/
@Test
public void testCanonicalFullCollectionExists() {
if (supportsFullCollections() && isTestSerialization() && !skipSerializedCanonicalTests()) {
final Object object = makeObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.TreeMap;

import org.apache.commons.collections4.map.AbstractMapTest;
import org.junit.Test;

/**
* Tests TreeMap.
Expand All @@ -41,12 +42,14 @@ public boolean isAllowNullKey() {
@Override
public abstract TreeMap<K, V> makeObject();

@Test
public void testNewMap() {
final TreeMap<K, V> map = makeObject();
assertTrue("New map is empty", map.isEmpty());
assertEquals("New map has size zero", 0, map.size());
}

@Test
@SuppressWarnings("unchecked")
public void testSearch() {
final TreeMap<K, V> map = makeObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.EmptyStackException;

import junit.framework.Test;
import org.junit.Test;

/**
* Tests ArrayStack.
Expand All @@ -32,7 +32,7 @@ public ArrayStackTest(final String testName) {
super(testName);
}

public static Test suite() {
public static junit.framework.Test suite() {
return BulkTest.makeSuite(ArrayStackTest.class);
}

Expand All @@ -41,6 +41,7 @@ public ArrayStack<E> makeObject() {
return new ArrayStack<>();
}

@Test
public void testNewStack() {
final ArrayStack<E> stack = makeObject();
assertTrue("New stack is empty", stack.empty());
Expand All @@ -51,6 +52,7 @@ public void testNewStack() {
assertThrows(EmptyStackException.class, () -> stack.pop());
}

@Test
@SuppressWarnings("unchecked")
public void testPushPeekPop() {
final ArrayStack<E> stack = makeObject();
Expand Down Expand Up @@ -79,6 +81,7 @@ public void testPushPeekPop() {
assertEquals("Stack size is zero", 0, stack.size());
}

@Test
@Override
@SuppressWarnings("unchecked")
public void testSearch() {
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/apache/commons/collections4/BulkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
* this.set = set;
* }
*
* @Test
* public void testContains() {
* boolean r = set.contains(set.iterator().next()));
* assertTrue("Set should contain first element, r);
* }
*
* @Test
* public void testClear() {
* set.clear();
* assertTrue("Set should be empty after clear", set.isEmpty());
Expand All @@ -73,6 +75,7 @@
* return result;
* }
*
* @Test
* public void testClear() {
* Map map = makeFullMap();
* map.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ public void testAndPredicateEx() {
// allPredicate
//------------------------------------------------------------------

@SuppressWarnings("unchecked")
@Test
@SuppressWarnings("unchecked")
public void testAllPredicate() {
assertPredicateTrue(AllPredicate.allPredicate(), null);
assertTrue(AllPredicate.allPredicate(truePredicate(), truePredicate(), truePredicate()).evaluate(null));
Expand Down Expand Up @@ -195,8 +195,8 @@ public void testAllPredicateEx1() {
assertThrows(NullPointerException.class, () -> AllPredicate.allPredicate((Predicate<Object>[]) null));
}

@SuppressWarnings("unchecked")
@Test
@SuppressWarnings("unchecked")
public void testAllPredicateEx2() {
assertThrows(NullPointerException.class, () -> AllPredicate.<Object>allPredicate(new Predicate[] { null }));
}
Expand Down Expand Up @@ -243,8 +243,8 @@ public void testOrPredicateEx() {
// anyPredicate
//------------------------------------------------------------------

@SuppressWarnings("unchecked")
@Test
@SuppressWarnings("unchecked")
public void testAnyPredicate() {
assertPredicateFalse(PredicateUtils.anyPredicate(), null);

Expand Down Expand Up @@ -287,8 +287,8 @@ public void testAnyPredicateEx1() {
assertThrows(NullPointerException.class, () -> PredicateUtils.anyPredicate((Predicate<Object>[]) null));
}

@SuppressWarnings("unchecked")
@Test
@SuppressWarnings("unchecked")
public void testAnyPredicateEx2() {
assertThrows(NullPointerException.class, () -> PredicateUtils.anyPredicate(new Predicate[] {null}));
}
Expand Down Expand Up @@ -335,8 +335,8 @@ public void testEitherPredicateEx() {
// onePredicate
//------------------------------------------------------------------

@SuppressWarnings("unchecked")
@Test
@SuppressWarnings("unchecked")
public void testOnePredicate() {
assertPredicateFalse(PredicateUtils.onePredicate((Predicate<Object>[]) new Predicate[] {}), null);
assertFalse(PredicateUtils.onePredicate(truePredicate(), truePredicate(), truePredicate()).evaluate(null));
Expand Down Expand Up @@ -380,8 +380,8 @@ public void testOnePredicateEx1() {
assertThrows(NullPointerException.class, () -> PredicateUtils.onePredicate((Predicate<Object>[]) null));
}

@SuppressWarnings("unchecked")
@Test
@SuppressWarnings("unchecked")
public void testOnePredicateEx2() {
assertThrows(NullPointerException.class, () -> PredicateUtils.onePredicate(new Predicate[] {null}));
}
Expand All @@ -396,8 +396,8 @@ public void testOnePredicateEx4() {
assertThrows(NullPointerException.class, () -> PredicateUtils.onePredicate((Collection<Predicate<Object>>) null));
}

@SuppressWarnings("unchecked")
@Test
@SuppressWarnings("unchecked")
public void testOnePredicateEx5() {
PredicateUtils.onePredicate(Collections.EMPTY_LIST);
}
Expand Down Expand Up @@ -426,8 +426,8 @@ public void testNeitherPredicateEx() {
// nonePredicate
//------------------------------------------------------------------

@SuppressWarnings("unchecked")
@Test
@SuppressWarnings("unchecked")
public void testNonePredicate() {
assertPredicateTrue(PredicateUtils.nonePredicate(), null);
assertFalse(PredicateUtils.nonePredicate(truePredicate(), truePredicate(), truePredicate()).evaluate(null));
Expand Down Expand Up @@ -469,14 +469,14 @@ public void testNonePredicateEx1() {
assertThrows(NullPointerException.class, () -> PredicateUtils.nonePredicate((Predicate<Object>[]) null));
}

@SuppressWarnings("unchecked")
@Test
@SuppressWarnings("unchecked")
public void testNonePredicateEx2() {
assertThrows(NullPointerException.class, () -> PredicateUtils.nonePredicate(new Predicate[] {null}));
}

@SuppressWarnings("unchecked")
@Test
@SuppressWarnings("unchecked")
public void testNonePredicateEx3() {
assertThrows(NullPointerException.class, () -> PredicateUtils.nonePredicate(null, null));
}
Expand Down
Loading

0 comments on commit b4edfcc

Please sign in to comment.