[nobug] move API tests to JUnit...
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
diff --git a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/IndirectListTestAPI.java b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/transparentindirection/IndirectListTest.java
similarity index 88%
rename from foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/IndirectListTestAPI.java
rename to foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/transparentindirection/IndirectListTest.java
index 2ad9d18..1a10b60 100644
--- a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/IndirectListTestAPI.java
+++ b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/transparentindirection/IndirectListTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -10,22 +10,26 @@
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
******************************************************************************/
-package org.eclipse.persistence.testing.tests.transparentindirection;
+package org.eclipse.persistence.testing.tests.junit.transparentindirection;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.StringWriter;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Comparator;
-import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;
import java.util.stream.StreamSupport;
-import junit.framework.TestSuite;
-
import org.eclipse.persistence.descriptors.changetracking.CollectionChangeEvent;
import org.eclipse.persistence.indirection.IndirectCollectionsFactory;
import org.eclipse.persistence.indirection.IndirectList;
@@ -33,12 +37,22 @@
import org.eclipse.persistence.internal.indirection.QueryBasedValueHolder;
import org.eclipse.persistence.queries.ReadAllQuery;
import org.eclipse.persistence.sessions.DatabaseRecord;
+import org.eclipse.persistence.testing.tests.transparentindirection.TestSession;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
/**
* Test a simple IndirectList.
* @author: Big Country
*/
-public class IndirectListTestAPI extends ZTestCase {
+@RunWith(Parameterized.class)
+public class IndirectListTest {
+
+ public static final class L<E> extends IndirectList<E> {}
private Vector<String> list;
private IndirectList<String> testList;
@@ -46,36 +60,24 @@ public class IndirectListTestAPI extends ZTestCase {
private Class<? extends IndirectList> cls;
private boolean useListener;
- /**
- * Constructor
- * @param name java.lang.String
- */
- public IndirectListTestAPI(String name) {
- this(name, null, true);
+ @Parameters(name = "{0}, {1}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { IndirectList.class, true }, { IndirectList.class, false }, { L.class, true }, { L.class, false }
+ });
}
- public IndirectListTestAPI(String name, Class<? extends IndirectList> cls, boolean useListener) {
- super(name);
+ public IndirectListTest(Class<? extends IndirectList> cls, boolean useListener) {
this.cls = cls;
this.useListener = useListener;
}
- public static TestSuite getTestSuiteFor(Class<? extends IndirectList> cls, boolean useListener) {
- ZTestSuite ts = new ZTestSuite("Suite for " + cls.getName() + "(useListener: " + useListener + ")");
- Enumeration<String> tests = ts.methodNamesStartingWithTestFor(IndirectListTestAPI.class);
- while (tests.hasMoreElements()) {
- ts.addTest(new IndirectListTestAPI(tests.nextElement(), cls, useListener));
- }
- return ts;
- }
-
/**
* set up the test fixture:
* 1. an IndirectList based on a Vector
*/
- @Override
- protected void setUp() {
- super.setUp();
+ @Before
+ public void setUp() {
list = setUpList();
Object temp = new Vector<>(list);
@@ -114,14 +116,14 @@ protected Vector setUpList() {
/**
* nothing for now...
*/
- @Override
- protected void tearDown() {
- super.tearDown();
+ @After
+ public void tearDown() {
if (useListener) {
testListLsn.events.clear();
}
}
+ @Test
public void testAdd1() {
String temp = "foo";
@@ -132,6 +134,7 @@ public void testAdd1() {
assertAddEvents(1);
}
+ @Test
public void testAdd2() {
String temp = "foo";
@@ -142,6 +145,7 @@ public void testAdd2() {
assertAddEvents(1);
}
+ @Test
public void testAddAll1() {
Vector temp = new Vector();
temp.addElement("foo");
@@ -154,6 +158,7 @@ public void testAddAll1() {
assertAddEvents(2);
}
+ @Test
public void testAddAll2() {
Vector temp = new Vector();
temp.addElement("foo");
@@ -166,6 +171,7 @@ public void testAddAll2() {
assertAddEvents(2);
}
+ @Test
public void testAddElement() {
String temp = "foo";
list.addElement(temp);
@@ -175,6 +181,7 @@ public void testAddElement() {
assertAddEvents(1);
}
+ @Test
public void testClear() {
int originalSize = testList.size();
list.clear();
@@ -185,58 +192,69 @@ public void testClear() {
}
+ @Test
public void testContains() {
assertTrue(testList.contains(list.elementAt(1)));
assertNoEvents();
}
+ @Test
public void testContainsAll() {
assertTrue(testList.containsAll(list.subList(1, 5)));
assertNoEvents();
}
+ @Test
public void testElementAt() {
assertEquals(list.elementAt(1), testList.elementAt(1));
assertNoEvents();
}
+ @Test
public void testElements() {
assertEquals(list.elements().nextElement(), testList.elements().nextElement());
assertNoEvents();
}
+ @Test
public void testEquals() {
assertTrue(testList.equals(list));
assertNoEvents();
}
+ @Test
public void testFirstElement() {
assertEquals(list.firstElement(), testList.firstElement());
assertNoEvents();
}
+ @Test
public void testGet() {
assertEquals(list.get(1), testList.get(1));
assertNoEvents();
}
+ @Test
public void testHashCode() {
assertEquals(list.hashCode(), testList.hashCode());
assertNoEvents();
}
+ @Test
public void testIndexOf1() {
String temp = "one";
assertEquals(list.indexOf(temp), testList.indexOf(temp));
assertNoEvents();
}
+ @Test
public void testIndexOf2() {
String temp = "seven";
assertEquals(list.indexOf(temp, 3), testList.indexOf(temp, 3));
assertNoEvents();
}
+ @Test
public void testInsertElementAt() {
String temp = "foo";
list.insertElementAt(temp, 3);
@@ -246,11 +264,13 @@ public void testInsertElementAt() {
assertAddEvents(1);
}
+ @Test
public void testIsEmpty() {
assertTrue(!testList.isEmpty());
assertNoEvents();
}
+ @Test
public void testIterator() {
int i = 0;
@@ -261,23 +281,27 @@ public void testIterator() {
assertNoEvents();
}
+ @Test
public void testLastElement() {
assertEquals(list.lastElement(), testList.lastElement());
assertNoEvents();
}
+ @Test
public void testLastIndexOf1() {
String temp = "one";
assertEquals(list.lastIndexOf(temp), testList.lastIndexOf(temp));
assertNoEvents();
}
+ @Test
public void testLastIndexOf2() {
String temp = "one";
assertEquals(list.lastIndexOf(temp, 7), testList.lastIndexOf(temp, 7));
assertNoEvents();
}
+ @Test
public void testListIterator1() {
int i = 0;
@@ -288,6 +312,7 @@ public void testListIterator1() {
assertNoEvents();
}
+ @Test
public void testListIterator2() {
int i = 0;
@@ -298,6 +323,7 @@ public void testListIterator2() {
assertNoEvents();
}
+ @Test
public void testRemove1() {
Object temp = list.remove(1);
assertEquals(temp, testList.remove(1));
@@ -306,6 +332,7 @@ public void testRemove1() {
assertRemoveEvents(1);
}
+ @Test
public void testRemove2() {
Object temp = "one";
@@ -316,6 +343,7 @@ public void testRemove2() {
assertRemoveEvents(1);
}
+ @Test
public void testRemoveAll() {
Vector temp = new Vector();
temp.addElement("one");
@@ -328,6 +356,7 @@ public void testRemoveAll() {
assertRemoveEvents(2);
}
+ @Test
public void testRemoveAllElements() {
int originalSize = testList.size();
list.removeAllElements();
@@ -337,6 +366,7 @@ public void testRemoveAllElements() {
assertRemoveEvents(originalSize);
}
+ @Test
public void testRemoveElement() {
Object temp = "one";
assertTrue(list.removeElement(temp));
@@ -346,6 +376,7 @@ public void testRemoveElement() {
assertRemoveEvents(1);
}
+ @Test
public void testRemoveElementAt() {
Object temp = testList.elementAt(1);
list.removeElementAt(1);
@@ -355,6 +386,7 @@ public void testRemoveElementAt() {
assertRemoveEvents(1);
}
+ @Test
public void testRetainAll() {
int originalSize = testList.size();
Vector temp = new Vector();
@@ -369,6 +401,7 @@ public void testRetainAll() {
assertRemoveEvents(originalSize - temp.size());
}
+ @Test
public void testSet() {
String temp = "foo";
@@ -379,6 +412,7 @@ public void testSet() {
assertRemoveAddEvents(1);
}
+ @Test
public void testSetElementAt() {
String temp = "foo";
list.setElementAt(temp, 3);
@@ -388,16 +422,19 @@ public void testSetElementAt() {
assertRemoveAddEvents(1);
}
+ @Test
public void testSize() {
assertEquals(list.size(), testList.size());
assertNoEvents();
}
+ @Test
public void testSubList() {
assertEquals(list.subList(2, 5), testList.subList(2, 5));
assertNoEvents();
}
+ @Test
public void testToArray1() {
Object[] temp = list.toArray();
Vector v1 = new Vector(temp.length);
@@ -414,6 +451,7 @@ public void testToArray1() {
assertNoEvents();
}
+ @Test
public void testToArray2() {
String[] temp = list.toArray(new String[0]);
Vector v1 = new Vector(temp.length);
@@ -431,8 +469,9 @@ public void testToArray2() {
}
//Java SE 8 API
+ @Test
public void testSort() {
- assertElementsEqual(list, testList);
+ assertArrayEquals(list.toArray(), testList.toArray());
Comparator<String> c = new Comparator<String>() {
@Override
@@ -442,10 +481,11 @@ public int compare(String o1, String o2) {
};
list.sort(c);
testList.sort(c);
- assertElementsEqual(list, testList);
+ assertArrayEquals(list.toArray(), testList.toArray());
assertNoEvents();
}
+ @Test
public void testSpliterator() {
assertTrue(StreamSupport.stream(testList.spliterator(), true).allMatch(item -> list.contains(item)));
assertTrue(StreamSupport.stream(list.spliterator(), true).allMatch(item -> testList.contains(item)));
@@ -453,6 +493,7 @@ public void testSpliterator() {
assertNoEvents();
}
+ @Test
public void testStream() {
assertTrue(testList.stream().allMatch(item -> list.contains(item)));
assertTrue(list.stream().allMatch(item -> testList.contains(item)));
@@ -460,6 +501,7 @@ public void testStream() {
assertNoEvents();
}
+ @Test
public void testParallelStream() {
assertTrue(testList.parallelStream().allMatch(item -> list.contains(item)));
assertTrue(list.parallelStream().allMatch(item -> testList.contains(item)));
@@ -467,28 +509,31 @@ public void testParallelStream() {
assertNoEvents();
}
+ @Test
public void testRemoveIf() {
// remove 'six' and 'seven'
assertTrue(list.removeIf(item -> item.startsWith("s")));
assertTrue(testList.removeIf(item -> item.startsWith("s")));
assertEquals("size do not match", 8, testList.size());
- assertElementsEqual(list, testList);
+ assertArrayEquals(list.toArray(), testList.toArray());
assertRemoveEvents(2);
}
+ @Test
public void testReplaceAll() {
list.replaceAll(String::toUpperCase);
testList.replaceAll(String::toUpperCase);
- assertElementsEqual(list, testList);
+ assertArrayEquals(list.toArray(), testList.toArray());
assertRemoveAddEvents(testList.size());
}
+ @Test
public void testForEach() {
final StringWriter sw1 = new StringWriter();
final StringWriter sw2 = new StringWriter();
list.forEach(sw1::append);
testList.forEach(sw2::append);
- assertElementsEqual(list, testList);
+ assertArrayEquals(list.toArray(), testList.toArray());
assertEquals(sw1.toString(), sw2.toString());
assertNoEvents();
}
diff --git a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/IndirectMapTestAPI.java b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/transparentindirection/IndirectMapTest.java
similarity index 92%
rename from foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/IndirectMapTestAPI.java
rename to foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/transparentindirection/IndirectMapTest.java
index cbb2ad0..b7e0e39 100644
--- a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/IndirectMapTestAPI.java
+++ b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/transparentindirection/IndirectMapTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -10,11 +10,19 @@
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
******************************************************************************/
-package org.eclipse.persistence.testing.tests.transparentindirection;
+package org.eclipse.persistence.testing.tests.junit.transparentindirection;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
@@ -26,8 +34,6 @@
import java.util.Set;
import java.util.Vector;
-import junit.framework.TestSuite;
-
import org.eclipse.persistence.descriptors.changetracking.CollectionChangeEvent;
import org.eclipse.persistence.descriptors.changetracking.MapChangeEvent;
import org.eclipse.persistence.indirection.IndirectCollectionsFactory;
@@ -36,38 +42,42 @@
import org.eclipse.persistence.internal.indirection.QueryBasedValueHolder;
import org.eclipse.persistence.queries.ReadAllQuery;
import org.eclipse.persistence.sessions.DatabaseRecord;
+import org.eclipse.persistence.testing.tests.transparentindirection.TestSession;
+import org.eclipse.persistence.testing.tests.transparentindirection.ZTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
/**
* Test a simple IndirectMap.
* @author: Big Country
*/
-public class IndirectMapTestAPI extends ZTestCase {
+@RunWith(Parameterized.class)
+public class IndirectMapTest {
+
+ public static final class M<K, V> extends IndirectMap<K, V> {}
+
private Hashtable<String, String> map;
private IndirectMap<String, String> testMap;
private Listener testMapLsn;
private Class<? extends IndirectMap> cls;
private boolean useListener;
- public IndirectMapTestAPI(String name) {
- this(name, null, true);
+ @Parameters(name = "{0}, {1}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { IndirectMap.class, true }, { IndirectMap.class, false }, { M.class, true }, { M.class, false }
+ });
}
- public IndirectMapTestAPI(String name, Class<? extends IndirectMap> cls, boolean useListener) {
- super(name);
+ public IndirectMapTest(Class<? extends IndirectMap> cls, boolean useListener) {
this.cls = cls;
this.useListener = useListener;
}
- public static TestSuite getTestSuiteFor(Class<? extends IndirectMap> cls, boolean useListener) {
- ZTestSuite ts = new ZTestSuite("Suite for " + cls.getName() + "(useListener: " + useListener + ")");
- Enumeration<String> tests = ts.methodNamesStartingWithTestFor(IndirectMapTestAPI.class);
- while (tests.hasMoreElements()) {
- ts.addTest(new IndirectMapTestAPI(tests.nextElement(), cls, useListener));
- }
- return ts;
- }
-
-
/**
* Assert that the elements in two dictionaries are equal. If they are not,
* throw an AssertionFailedError. Order of the elements is significant.
@@ -80,12 +90,12 @@ protected void assertElementsEqual(String message, Map expected, Map actual) {
return;
}
if (expected.size() != actual.size()) {
- assertTrue(notEqualsMessage(message, expected, actual), false);
+ assertTrue(ZTestCase.notEqualsMessage(message, expected, actual), false);
}
for (Iterator stream = expected.keySet().iterator(); stream.hasNext();) {
Object key = stream.next();
if (!expected.get(key).equals(actual.get(key))) {
- assertTrue(notEqualsMessage(message, expected, actual), false);
+ assertTrue(ZTestCase.notEqualsMessage(message, expected, actual), false);
}
}
}
@@ -104,9 +114,8 @@ protected void assertElementsEqual(Map expected, Map actual) {
* set up the test fixture:
* 1. an IndirectMap based on a Hashtable
*/
- @Override
- protected void setUp() {
- super.setUp();
+ @Before
+ public void setUp() {
map = this.setUpMap();
Object temp = new Hashtable(map);
@@ -145,14 +154,14 @@ protected Hashtable<String, String> setUpMap() {
/**
* nothing for now...
*/
- @Override
- protected void tearDown() {
- super.tearDown();
+ @After
+ public void tearDown() {
if (useListener) {
testMapLsn.events.clear();
}
}
+ @Test
public void testClear() {
int originalSize = testMap.size();
map.clear();
@@ -163,31 +172,37 @@ public void testClear() {
assertRemoveEvents(originalSize);
}
+ @Test
public void testContains() {
assertTrue(testMap.contains(map.elements().nextElement()));
assertNoEvents();
}
+ @Test
public void testContainsKey() {
assertTrue(testMap.containsKey(map.keys().nextElement()));
assertNoEvents();
}
+ @Test
public void testContainsValue() {
assertTrue(testMap.containsValue(map.elements().nextElement()));
assertNoEvents();
}
+ @Test
public void testElements() {
assertTrue("Map Does not contain elements from test", map.contains(testMap.elements().nextElement()));
assertNoEvents();
}
+ @Test
public void testEntrySet() {
assertEquals(map.entrySet(), testMap.entrySet());
assertNoEvents();
}
+ @Test
public void testEntrySetAdd() {
Set<Map.Entry<String, String>> entrySet = map.entrySet();
Set<Map.Entry<String, String>> testEntrySet = testMap.entrySet();
@@ -209,6 +224,7 @@ public void testEntrySetAdd() {
assertNoEvents();
}
+ @Test
public void testEntrySetAddAll() {
Collection<Map.Entry<String, String>> collection = new HashSet<>();
collection.add(new MapEntry("sampleKey1", "sampleValue1"));
@@ -233,6 +249,7 @@ public void testEntrySetAddAll() {
assertNoEvents();
}
+ @Test
public void testEntrySetClear() {
Set<Map.Entry<String, String>> entrySet = map.entrySet();
Set<Map.Entry<String, String>> testEntrySet = testMap.entrySet();
@@ -243,6 +260,7 @@ public void testEntrySetClear() {
assertRemoveEvents(10);
}
+ @Test
public void testEntrySetSize() {
Set<Map.Entry<String, String>> entrySet = map.entrySet();
Set<Map.Entry<String, String>> testEntrySet = testMap.entrySet();
@@ -251,6 +269,7 @@ public void testEntrySetSize() {
assertNoEvents();
}
+ @Test
public void testEntrySetRemove() {
Set<Map.Entry<String, String>> entrySet = map.entrySet();
Set<Map.Entry<String, String>> testEntrySet = testMap.entrySet();
@@ -271,6 +290,7 @@ public void testEntrySetRemove() {
assertRemoveEvents(1);
}
+ @Test
public void testEntrySetRemoveAll() {
Set<Map.Entry<String, String>> entrySet = map.entrySet();
Set<Map.Entry<String, String>> testEntrySet = testMap.entrySet();
@@ -293,6 +313,7 @@ public void testEntrySetRemoveAll() {
assertRemoveEvents(2);
}
+ @Test
public void testEntrySetRemoveIf() {
Set<Map.Entry<String, String>> entrySet = map.entrySet();
Set<Map.Entry<String, String>> testEntrySet = testMap.entrySet();
@@ -304,6 +325,7 @@ public void testEntrySetRemoveIf() {
assertRemoveEvents(1);
}
+ @Test
public void testEntrySetRetainAll() {
Set<Map.Entry<String, String>> entrySet = map.entrySet();
Set<Map.Entry<String, String>> testEntrySet = testMap.entrySet();
@@ -327,37 +349,44 @@ public void testEntrySetRetainAll() {
assertRemoveEvents(8);
}
+ @Test
public void testEquals() {
assertFalse(testMap == map);
assertTrue(testMap.equals(map));
assertNoEvents();
}
+ @Test
public void testGet() {
assertEquals(map.get("six"), testMap.get("six"));
assertNoEvents();
}
+ @Test
public void testHashCode() {
assertEquals(map.hashCode(), testMap.hashCode());
assertNoEvents();
}
+ @Test
public void testIsEmpty() {
assertTrue(!testMap.isEmpty());
assertNoEvents();
}
+ @Test
public void testKeys() {
assertFalse("Map Does not contain keys from test", map.contains(testMap.keys().nextElement()));
assertNoEvents();
}
+ @Test
public void testKeySet() {
assertEquals(map.entrySet(), testMap.entrySet());
assertNoEvents();
}
+ @Test
public void testKeySetAdd() {
Set<String> keySet = map.keySet();
Set<String> testKeySet = testMap.keySet();
@@ -379,6 +408,7 @@ public void testKeySetAdd() {
assertNoEvents();
}
+ @Test
public void testKeySetAddAll() {
Collection<String> collection = new HashSet<>();
collection.add("sampleKey1");
@@ -403,6 +433,7 @@ public void testKeySetAddAll() {
assertNoEvents();
}
+ @Test
public void testKeySetClear() {
Set<String> keySet = map.keySet();
Set<String> testKeySet = testMap.keySet();
@@ -413,6 +444,7 @@ public void testKeySetClear() {
assertRemoveEvents(10);
}
+ @Test
public void testKeySetSize() {
Set<String> keySet = map.keySet();
Set<String> testKeySet = testMap.keySet();
@@ -421,6 +453,7 @@ public void testKeySetSize() {
assertNoEvents();
}
+ @Test
public void testKeySetRemove() {
Set<String> keySet = map.keySet();
Set<String> testKeySet = testMap.keySet();
@@ -432,6 +465,7 @@ public void testKeySetRemove() {
assertRemoveEvents(1);
}
+ @Test
public void testKeySetRemoveAll() {
Set<String> keySet = map.keySet();
Set<String> testKeySet = testMap.keySet();
@@ -446,6 +480,7 @@ public void testKeySetRemoveAll() {
assertRemoveEvents(2);
}
+ @Test
public void testKeySetRemoveIf() {
// remove 2 items - 'six' and 'seven'
Set<String> keySet = map.keySet();
@@ -458,6 +493,7 @@ public void testKeySetRemoveIf() {
assertRemoveEvents(2);
}
+ @Test
public void testKeySetRetainAll() {
Set<String> keySet = map.keySet();
Set<String> testKeySet = testMap.keySet();
@@ -473,6 +509,7 @@ public void testKeySetRetainAll() {
assertRemoveEvents(8);
}
+ @Test
public void testPut() {
String key = "foo";
String value = "bar";
@@ -486,6 +523,7 @@ public void testPut() {
assertAddEvents(1);
}
+ @Test
public void testPutAll() {
Hashtable<String, String> temp = new Hashtable<>();
temp.put("foo", "bar");
@@ -503,6 +541,7 @@ public void testPutAll() {
assertAddEvents(2);
}
+ @Test
public void testRemove() {
String temp = "one";
String result1 = map.remove(temp);
@@ -514,11 +553,13 @@ public void testRemove() {
assertRemoveEvents(1);
}
+ @Test
public void testSize() {
assertEquals(map.size(), testMap.size());
assertNoEvents();
}
+ @Test
public void testValues() {
assertEquals(map.size(), testMap.values().size());
@@ -530,6 +571,7 @@ public void testValues() {
assertNoEvents();
}
+ @Test
public void testValuesAdd() {
Collection<String> keySet = map.values();
Collection<String> testKeySet = testMap.values();
@@ -551,6 +593,7 @@ public void testValuesAdd() {
assertNoEvents();
}
+ @Test
public void testValuesAddAll() {
Collection<String> collection = new HashSet<>();
collection.add("newValue1");
@@ -575,6 +618,7 @@ public void testValuesAddAll() {
assertNoEvents();
}
+ @Test
public void testValuesClear() {
Collection<String> keySet = map.values();
Collection<String> testKeySet = testMap.values();
@@ -585,6 +629,7 @@ public void testValuesClear() {
assertRemoveEvents(10);
}
+ @Test
public void testValuesSize() {
Collection<String> keySet = map.values();
Collection<String> testKeySet = testMap.values();
@@ -593,6 +638,7 @@ public void testValuesSize() {
assertNoEvents();
}
+ @Test
public void testValuesRemove() {
Collection<String> keySet = map.values();
Collection<String> testKeySet = testMap.values();
@@ -604,6 +650,7 @@ public void testValuesRemove() {
assertRemoveEvents(1);
}
+ @Test
public void testValuesRemoveAll() {
Collection<String> keySet = map.values();
Collection<String> testKeySet = testMap.values();
@@ -618,6 +665,7 @@ public void testValuesRemoveAll() {
assertRemoveEvents(2);
}
+ @Test
public void testValuesRemoveIf() {
// remove 2 items - 'six' and 'seven'
Collection<String> keySet = map.values();
@@ -631,6 +679,7 @@ public void testValuesRemoveIf() {
}
+ @Test
public void testValueRetainAll() {
Collection<String> keySet = map.values();
Collection<String> testKeySet = testMap.values();
@@ -647,6 +696,7 @@ public void testValueRetainAll() {
}
//Java SE 8 API
+ @Test
public void testReplace() {
assertEquals(map, testMap);
Object o = testMap.replace("one", "1");
@@ -663,6 +713,7 @@ public void testReplace() {
assertRemoveAddEvents(1);
}
+ @Test
public void testReplaceWithDefault() {
assertEquals("111", testMap.get("one"));
Object o = testMap.replace("one", "1", "1234");
@@ -681,6 +732,7 @@ public void testReplaceWithDefault() {
assertRemoveAddEvents(1);
}
+ @Test
public void testGetOrDefault() {
assertFalse(testMap.containsKey("temp"));
Object o = testMap.getOrDefault("temp", "1234");
@@ -694,6 +746,7 @@ public void testGetOrDefault() {
assertNoEvents();
}
+ @Test
public void testPutIfAbsent() {
assertFalse(testMap.containsKey("temp"));
Object o = testMap.putIfAbsent("temp", "1234");
@@ -707,6 +760,7 @@ public void testPutIfAbsent() {
assertAddEvents(1);
}
+ @Test
public void testRemoveTwoArgs() {
assertEquals("111", testMap.get("one"));
Object o = testMap.remove("one", "1234");
@@ -720,16 +774,18 @@ public void testRemoveTwoArgs() {
assertRemoveEvents(1);
}
+ @Test
public void testForEach() {
final Vector<String> v1 = new Vector<>();
final Vector<String> v2 = new Vector<>();
map.forEach((k, v) -> {v1.add(k);v1.add(v);});
testMap.forEach((k, v) -> {v2.add(k);v2.add(v);});
- assertUnorderedElementsEqual(v1, v2);
+ ZTestCase.assertUnorderedElementsEqual(v1, v2);
assertEquals(map, testMap);
assertNoEvents();
}
+ @Test
public void testReplaceAll() {
assertEquals(map, testMap);
map.replaceAll((k,v) -> v += "sufix");
@@ -738,6 +794,7 @@ public void testReplaceAll() {
assertRemoveAddEvents(testMap.size());
}
+ @Test
public void testCompute() {
assertEquals(map, testMap);
String s1 = map.compute("one", (k,v) -> v += "suffix");
@@ -748,6 +805,7 @@ public void testCompute() {
assertRemoveAddEvents(1);
}
+ @Test
public void testCompute2() {
assertEquals(map, testMap);
String s1 = map.compute("notExist", (k,v) -> v += "suffix");
@@ -758,6 +816,7 @@ public void testCompute2() {
assertAddEvents(1);
}
+ @Test
public void testComputeIfPresent() {
assertEquals(map, testMap);
String s1 = map.computeIfPresent("one", (k,v) -> v += "suffix");
@@ -768,6 +827,7 @@ public void testComputeIfPresent() {
assertRemoveAddEvents(1);
}
+ @Test
public void testComputeIfPresent2() {
assertEquals(map, testMap);
String s1 = map.computeIfPresent("notExist", (k,v) -> v += "suffix");
@@ -778,6 +838,7 @@ public void testComputeIfPresent2() {
assertNoEvents();;
}
+ @Test
public void testComputeIfAbsent() {
assertEquals(map, testMap);
String s1 = map.computeIfAbsent("one", k -> "newitem");
@@ -788,6 +849,7 @@ public void testComputeIfAbsent() {
assertNoEvents();
}
+ @Test
public void testComputeIfAbsent2() {
assertEquals(map, testMap);
String s1 = map.computeIfAbsent("notExist", k -> "newitem");
@@ -797,6 +859,7 @@ public void testComputeIfAbsent2() {
assertAddEvents(1);
}
+ @Test
public void testMerge() {
assertEquals(map, testMap);
String s1 = map.merge("one", "custom", String::concat);
@@ -807,6 +870,7 @@ public void testMerge() {
assertRemoveAddEvents(1);
}
+ @Test
public void testMerge2() {
assertEquals(map, testMap);
String s1 = map.merge("notExist", "custom", String::concat);
diff --git a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/IndirectSetTestAPI.java b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/transparentindirection/IndirectSetTest.java
similarity index 81%
rename from foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/IndirectSetTestAPI.java
rename to foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/transparentindirection/IndirectSetTest.java
index 9d7d3f8..f442d79 100644
--- a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/IndirectSetTestAPI.java
+++ b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/transparentindirection/IndirectSetTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -10,20 +10,22 @@
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
******************************************************************************/
-package org.eclipse.persistence.testing.tests.transparentindirection;
+package org.eclipse.persistence.testing.tests.junit.transparentindirection;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
-import java.util.Enumeration;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.stream.StreamSupport;
-import junit.framework.TestSuite;
-
import org.eclipse.persistence.descriptors.changetracking.CollectionChangeEvent;
import org.eclipse.persistence.indirection.IndirectCollectionsFactory;
import org.eclipse.persistence.indirection.IndirectSet;
@@ -31,48 +33,48 @@
import org.eclipse.persistence.internal.indirection.QueryBasedValueHolder;
import org.eclipse.persistence.queries.ReadAllQuery;
import org.eclipse.persistence.sessions.DatabaseRecord;
+import org.eclipse.persistence.testing.tests.transparentindirection.TestSession;
+import org.eclipse.persistence.testing.tests.transparentindirection.ZTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
/**
* Test a simple IndirectSet.
* this should only be used in jdk1.2+
* @author: Big Country
*/
-public class IndirectSetTestAPI extends ZTestCase {
+@RunWith(Parameterized.class)
+public class IndirectSetTest {
+
+ public static final class S<E> extends IndirectSet<E> {}
+
private Vector<String> list;
private IndirectSet<String> testList;
private Listener testListLsn;
private Class<? extends IndirectSet> cls;
private boolean useListener;
- /**
- * Constructor
- * @param name java.lang.String
- */
- public IndirectSetTestAPI(String name) {
- this(name, null, true);
+ @Parameters(name = "{0}, {1}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { IndirectSet.class, true }, { IndirectSet.class, false }, { S.class, true }, { S.class, false }
+ });
}
- public IndirectSetTestAPI(String name, Class<? extends IndirectSet> cls, boolean useListener) {
- super(name);
+ public IndirectSetTest(Class<? extends IndirectSet> cls, boolean useListener) {
this.cls = cls;
this.useListener = useListener;
}
- public static TestSuite getTestSuiteFor(Class<? extends IndirectSet> cls, boolean useListener) {
- ZTestSuite ts = new ZTestSuite("Suite for " + cls.getName() + "(useListener: " + useListener + ")");
- Enumeration<String> tests = ts.methodNamesStartingWithTestFor(IndirectSetTestAPI.class);
- while (tests.hasMoreElements()) {
- ts.addTest(new IndirectSetTestAPI(tests.nextElement(), cls, useListener));
- }
- return ts;
- }
-
/**
* set up the test fixture:
*/
- @Override
- protected void setUp() {
- super.setUp();
+ @Before
+ public void setUp() {
list = setUpList();
Object temp = new HashSet<>(list);
@@ -111,23 +113,24 @@ protected Vector setUpList() {
/**
* nothing for now...
*/
- @Override
- protected void tearDown() {
- super.tearDown();
+ @After
+ public void tearDown() {
if (useListener) {
testListLsn.events.clear();
}
}
+ @Test
public void testAdd() {
String temp = "foo";
list.add(temp);
testList.add(temp);
- assertUnorderedElementsEqual(list, new Vector(testList));
+ ZTestCase.assertUnorderedElementsEqual(list, new Vector(testList));
assertTrue(testList.contains(temp));
assertAddEvents(1);
}
+ @Test
public void testAddAll() {
Vector<String> temp = new Vector<>();
temp.addElement("foo");
@@ -136,11 +139,12 @@ public void testAddAll() {
list.addAll(temp);
testList.addAll(temp);
- assertUnorderedElementsEqual(list, new Vector(testList));
+ ZTestCase.assertUnorderedElementsEqual(list, new Vector(testList));
assertTrue(testList.containsAll(temp));
assertAddEvents(2);
}
+ @Test
public void testClear() {
int originalSize = testList.size();
list.clear();
@@ -150,26 +154,31 @@ public void testClear() {
assertRemoveEvents(originalSize);
}
+ @Test
public void testContains() {
assertTrue(testList.contains(list.elementAt(1)));
assertNoEvents();
}
+ @Test
public void testContainsAll() {
assertTrue(testList.containsAll(list.subList(1, 5)));
assertNoEvents();
}
+ @Test
public void testEquals() {
assertTrue(testList.equals(new HashSet(list)));
assertNoEvents();
}
+ @Test
public void testIsEmpty() {
assertTrue(!testList.isEmpty());
assertNoEvents();
}
+ @Test
public void testIterator() {
int i = 0;
for (Iterator stream = testList.iterator(); stream.hasNext(); i++) {
@@ -179,15 +188,17 @@ public void testIterator() {
assertNoEvents();
}
+ @Test
public void testRemove() {
String temp = "one";
assertTrue(list.remove(temp));
assertTrue(testList.remove(temp));
- assertUnorderedElementsEqual(list, new Vector(testList));
+ ZTestCase.assertUnorderedElementsEqual(list, new Vector(testList));
assertTrue(!testList.contains(temp));
assertRemoveEvents(1);
}
+ @Test
public void testRemoveAll() {
Vector<String> temp = new Vector<>();
temp.addElement("one");
@@ -195,11 +206,12 @@ public void testRemoveAll() {
assertTrue(list.removeAll(temp));
assertTrue(testList.removeAll(temp));
- assertUnorderedElementsEqual(list, new Vector(testList));
+ ZTestCase.assertUnorderedElementsEqual(list, new Vector(testList));
assertTrue(!testList.containsAll(temp));
assertRemoveEvents(2);
}
+ @Test
public void testRetainAll() {
int originalSize = testList.size();
Vector<String> temp = new Vector<>();
@@ -209,18 +221,20 @@ public void testRetainAll() {
assertTrue(list.retainAll(temp));
assertTrue(testList.retainAll(temp));
- assertUnorderedElementsEqual(list, new Vector(testList));
+ ZTestCase.assertUnorderedElementsEqual(list, new Vector(testList));
assertTrue(testList.containsAll(temp));
assertEquals(temp.size(), testList.size());
assertRemoveEvents(originalSize - temp.size());
}
+ @Test
public void testSize() {
assertEquals(list.size(), testList.size());
assertNoEvents();
}
+ @Test
public void testToArray1() {
Object[] temp = list.toArray();
Vector v1 = new Vector(temp.length);
@@ -232,10 +246,11 @@ public void testToArray1() {
for (int i = 0; i < temp.length; i++) {
v2.addElement(temp[i]);
}
- assertUnorderedElementsEqual(v1, v2);
+ ZTestCase.assertUnorderedElementsEqual(v1, v2);
assertNoEvents();
}
+ @Test
public void testToArray2() {
String[] temp = list.toArray(new String[0]);
Vector v1 = new Vector(temp.length);
@@ -247,11 +262,12 @@ public void testToArray2() {
for (int i = 0; i < temp.length; i++) {
v2.addElement(temp[i]);
}
- assertUnorderedElementsEqual(v1, v2);
+ ZTestCase.assertUnorderedElementsEqual(v1, v2);
assertNoEvents();
}
//Java SE 8 API
+ @Test
public void testSpliterator() {
assertTrue(StreamSupport.stream(testList.spliterator(), true).allMatch(item -> list.contains(item)));
assertTrue(StreamSupport.stream(list.spliterator(), true).allMatch(item -> testList.contains(item)));
@@ -259,6 +275,7 @@ public void testSpliterator() {
assertNoEvents();
}
+ @Test
public void testStream() {
assertTrue(testList.stream().allMatch(item -> list.contains(item)));
assertTrue(list.stream().allMatch(item -> testList.contains(item)));
@@ -266,6 +283,7 @@ public void testStream() {
assertNoEvents();
}
+ @Test
public void testParallelStream() {
assertTrue(testList.parallelStream().allMatch(item -> list.contains(item)));
assertTrue(list.parallelStream().allMatch(item -> testList.contains(item)));
@@ -273,22 +291,24 @@ public void testParallelStream() {
assertNoEvents();
}
+ @Test
public void testRemoveIf() {
// remove 'six' and 'seven'
assertTrue(list.removeIf(item -> item.startsWith("s")));
assertTrue(testList.removeIf(item -> item.startsWith("s")));
assertEquals("size do not match", 8, testList.size());
- assertUnorderedElementsEqual(list, new Vector(testList));
+ ZTestCase.assertUnorderedElementsEqual(list, new Vector(testList));
assertRemoveEvents(2);
}
+ @Test
public void testForEach() {
final Vector<String> v1 = new Vector<>();
final Vector<String> v2 = new Vector<>();
list.forEach(v1::add);
testList.forEach(v2::add);
- assertUnorderedElementsEqual(list, new Vector(testList));
- assertUnorderedElementsEqual(v1, v2);
+ ZTestCase.assertUnorderedElementsEqual(list, new Vector(testList));
+ ZTestCase.assertUnorderedElementsEqual(v1, v2);
assertNoEvents();
}
diff --git a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/TransparentIndirectionModel.java b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/TransparentIndirectionModel.java
index 491cea3..9307aa6 100644
--- a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/TransparentIndirectionModel.java
+++ b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/TransparentIndirectionModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -43,25 +43,8 @@ public void addRequiredSystems() {
addRequiredSystem(new BidirectionalRelationshipSystem());
}
- public static final class X<E> extends IndirectList<E> {}
- public static final class Y<E> extends IndirectSet<E> {}
- public static final class Z<K, V> extends IndirectMap<K, V> {}
-
@Override
public void addTests() {
- addTest(new ZTestSuite(IndirectListTestAPI.class));
- addTest(IndirectListTestAPI.getTestSuiteFor(IndirectList.class, false));
- addTest(IndirectListTestAPI.getTestSuiteFor(X.class, false));
- addTest(IndirectListTestAPI.getTestSuiteFor(X.class, true));
- addTest(new ZTestSuite(IndirectMapTestAPI.class));
- addTest(IndirectMapTestAPI.getTestSuiteFor(IndirectMap.class, false));
- addTest(IndirectMapTestAPI.getTestSuiteFor(Z.class, false));
- addTest(IndirectMapTestAPI.getTestSuiteFor(Z.class, true));
- addTest(new ZTestSuite(IndirectSetTestAPI.class));
- addTest(IndirectSetTestAPI.getTestSuiteFor(IndirectSet.class, false));
- addTest(IndirectSetTestAPI.getTestSuiteFor(Y.class, false));
- addTest(IndirectSetTestAPI.getTestSuiteFor(Y.class, true));
-
addTest(new ZTestSuite(IndirectListTestDatabase.class));
addTest(new ZTestSuite(IndirectMapTestDatabase.class));
addTest(new ZTestSuite(IndirectSetTestDatabase.class));
diff --git a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/ZTestCase.java b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/ZTestCase.java
index 6d1fad9..84738e3 100644
--- a/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/ZTestCase.java
+++ b/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/transparentindirection/ZTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -44,18 +44,18 @@ protected void assertElementsEqual(String message, Vector expected, Vector actua
return;
}
if (expected.size() != actual.size()) {
- this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
+ assertTrue(notEqualsMessage(message, expected, actual), false);
}
for (int i = 0; i < expected.size(); i++) {
Object e1 = expected.elementAt(i);
Object e2 = actual.elementAt(i);
if (e1 == null) {// avoid null pointer exception
if (e2 != null) {
- this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
+ assertTrue(notEqualsMessage(message, expected, actual), false);
}
} else {
if (!e1.equals(e2)) {
- this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
+ assertTrue(notEqualsMessage(message, expected, actual), false);
}
}
}
@@ -78,23 +78,23 @@ protected void assertElementsEqual(Vector expected, Vector actual) {
* @param expected the expected value of an vector
* @param actual the actual value of an vector
*/
- protected void assertUnorderedElementsEqual(String message, Vector expected, Vector actual) {
+ protected static void assertUnorderedElementsEqual(String message, Vector expected, Vector actual) {
if (expected == actual) {
return;
}
if (expected.size() != actual.size()) {
- this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
+ assertTrue(notEqualsMessage(message, expected, actual), false);
}
Vector temp = (Vector)actual.clone();
for (int i = 0; i < expected.size(); i++) {
Object e1 = expected.elementAt(i);
if (e1 == null) {// avoid null pointer exception
- if (!this.removeNullElement(temp)) {
- this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
+ if (!removeNullElement(temp)) {
+ assertTrue(notEqualsMessage(message, expected, actual), false);
}
} else {
if (!temp.removeElement(e1)) {
- this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
+ assertTrue(notEqualsMessage(message, expected, actual), false);
}
}
}
@@ -106,8 +106,8 @@ protected void assertUnorderedElementsEqual(String message, Vector expected, Vec
* @param expected the expected value of an vector
* @param actual the actual value of an vector
*/
- protected void assertUnorderedElementsEqual(Vector expected, Vector actual) {
- this.assertUnorderedElementsEqual("", expected, actual);
+ public static void assertUnorderedElementsEqual(Vector expected, Vector actual) {
+ assertUnorderedElementsEqual("", expected, actual);
}
/**
@@ -153,7 +153,7 @@ private Method methodNamed(String name) {
* Return a nicely formatted message for when the actual value did not
* equal the expected one.
*/
- protected String notEqualsMessage(String message, Object expected, Object actual) {
+ public static String notEqualsMessage(String message, Object expected, Object actual) {
StringBuffer buffer = new StringBuffer(250);
if ((message != null) && (message.length() != 0)) {
buffer.append(message);
@@ -172,7 +172,7 @@ protected String notEqualsMessage(String message, Object expected, Object actual
* Return true if a null element was found and removed.
* Return false if a null element was not found.
*/
- private boolean removeNullElement(Vector v) {
+ private static boolean removeNullElement(Vector v) {
for (int i = 0; i < v.size(); i++) {
if (v.elementAt(i) == null) {
v.removeElementAt(i);