Merge branch 'master' of https://ggregory@gitbox.apache.org/repos/asf/commons-collections
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4dc438f..46475f2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -213,6 +213,9 @@
<action type="update" dev="ggregory" due-to="Dependabot">
Bump commons.junit.version from 5.6.2 to 5.7.0 #181.
</action>
+ <action type="update" dev="ggregory" due-to="Dependabot">
+ Bump maven-antrun-plugin from 1.8 to 3.0.0 #170.
+ </action>
</release>
<release version="4.4" date="2019-07-05" description="Maintenance release.">
<action issue="COLLECTIONS-710" dev="ggregory" type="fix" due-to="Yu Shi, Gary Gregory">
diff --git a/src/test/java/org/apache/commons/collections4/map/CaseInsensitiveMapTest.java b/src/test/java/org/apache/commons/collections4/map/CaseInsensitiveMapTest.java
index 5530bc9..1f6a0ef 100644
--- a/src/test/java/org/apache/commons/collections4/map/CaseInsensitiveMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/CaseInsensitiveMapTest.java
@@ -31,17 +31,12 @@
*/
public class CaseInsensitiveMapTest<K, V> extends AbstractIterableMapTest<K, V> {
- public CaseInsensitiveMapTest(final String testName) {
- super(testName);
- }
-
public static Test suite() {
return BulkTest.makeSuite(CaseInsensitiveMapTest.class);
}
- @Override
- public CaseInsensitiveMap<K, V> makeObject() {
- return new CaseInsensitiveMap<>();
+ public CaseInsensitiveMapTest(final String testName) {
+ super(testName);
}
@Override
@@ -49,7 +44,10 @@
return "4";
}
- //-------------------------------------------------------------------------
+ @Override
+ public CaseInsensitiveMap<K, V> makeObject() {
+ return new CaseInsensitiveMap<>();
+ }
@SuppressWarnings("unchecked")
public void testCaseInsensitive() {
@@ -63,6 +61,58 @@
}
@SuppressWarnings("unchecked")
+ public void testClone() {
+ final CaseInsensitiveMap<K, V> map = new CaseInsensitiveMap<>(10);
+ map.put((K) "1", (V) "1");
+ final CaseInsensitiveMap<K, V> cloned = map.clone();
+ assertEquals(map.size(), cloned.size());
+ assertSame(map.get("1"), cloned.get("1"));
+ }
+
+ /**
+ * Test for <a href="https://issues.apache.org/jira/browse/COLLECTIONS-323">COLLECTIONS-323</a>.
+ */
+ public void testInitialCapacityZero() {
+ final CaseInsensitiveMap<String, String> map = new CaseInsensitiveMap<>(0);
+ assertEquals(1, map.data.length);
+ }
+
+ // COLLECTIONS-294
+ public void testLocaleIndependence() {
+ final Locale orig = Locale.getDefault();
+
+ final Locale[] locales = { Locale.ENGLISH, new Locale("tr", "", ""), Locale.getDefault() };
+
+ final String[][] data = {
+ { "i", "I" },
+ { "\u03C2", "\u03C3" },
+ { "\u03A3", "\u03C2" },
+ { "\u03A3", "\u03C3" },
+ };
+
+ try {
+ for (final Locale locale : locales) {
+ Locale.setDefault(locale);
+ for (int j = 0; j < data.length; j++) {
+ assertTrue("Test data corrupt: " + j, data[j][0].equalsIgnoreCase(data[j][1]));
+ final CaseInsensitiveMap<String, String> map = new CaseInsensitiveMap<>();
+ map.put(data[j][0], "value");
+ assertEquals(Locale.getDefault() + ": " + j, "value", map.get(data[j][1]));
+ }
+ }
+ } finally {
+ Locale.setDefault(orig);
+ }
+ }
+
+// public void testCreate() throws Exception {
+// resetEmpty();
+// writeExternalFormToDisk((java.io.Serializable) map, "src/test/resources/data/test/CaseInsensitiveMap.emptyCollection.version4.obj");
+// resetFull();
+// writeExternalFormToDisk((java.io.Serializable) map, "src/test/resources/data/test/CaseInsensitiveMap.fullCollection.version4.obj");
+// }
+
+ @SuppressWarnings("unchecked")
public void testNullHandling() {
final Map<K, V> map = makeObject();
map.put((K) "One", (V) "One");
@@ -97,56 +147,4 @@
|| !caseInsensitiveMap.containsValue("Three")); // ones collapsed
assertEquals("Four", caseInsensitiveMap.get(null));
}
-
- @SuppressWarnings("unchecked")
- public void testClone() {
- final CaseInsensitiveMap<K, V> map = new CaseInsensitiveMap<>(10);
- map.put((K) "1", (V) "1");
- final CaseInsensitiveMap<K, V> cloned = map.clone();
- assertEquals(map.size(), cloned.size());
- assertSame(map.get("1"), cloned.get("1"));
- }
-
-// public void testCreate() throws Exception {
-// resetEmpty();
-// writeExternalFormToDisk((java.io.Serializable) map, "src/test/resources/data/test/CaseInsensitiveMap.emptyCollection.version4.obj");
-// resetFull();
-// writeExternalFormToDisk((java.io.Serializable) map, "src/test/resources/data/test/CaseInsensitiveMap.fullCollection.version4.obj");
-// }
-
- // COLLECTIONS-294
- public void testLocaleIndependence() {
- final Locale orig = Locale.getDefault();
-
- final Locale[] locales = { Locale.ENGLISH, new Locale("tr", "", ""), Locale.getDefault() };
-
- final String[][] data = {
- { "i", "I" },
- { "\u03C2", "\u03C3" },
- { "\u03A3", "\u03C2" },
- { "\u03A3", "\u03C3" },
- };
-
- try {
- for (final Locale locale : locales) {
- Locale.setDefault(locale);
- for (int j = 0; j < data.length; j++) {
- assertTrue("Test data corrupt: " + j, data[j][0].equalsIgnoreCase(data[j][1]));
- final CaseInsensitiveMap<String, String> map = new CaseInsensitiveMap<>();
- map.put(data[j][0], "value");
- assertEquals(Locale.getDefault() + ": " + j, "value", map.get(data[j][1]));
- }
- }
- } finally {
- Locale.setDefault(orig);
- }
- }
-
- /**
- * Test for <a href="https://issues.apache.org/jira/browse/COLLECTIONS-323">COLLECTIONS-323</a>.
- */
- public void testInitialCapacityZero() {
- final CaseInsensitiveMap<String, String> map = new CaseInsensitiveMap<>(0);
- assertEquals(1, map.data.length);
- }
}
diff --git a/src/test/java/org/apache/commons/collections4/map/ReferenceIdentityMapTest.java b/src/test/java/org/apache/commons/collections4/map/ReferenceIdentityMapTest.java
index 1ccc8ec..3389b4c 100644
--- a/src/test/java/org/apache/commons/collections4/map/ReferenceIdentityMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/ReferenceIdentityMapTest.java
@@ -37,35 +37,44 @@
private static final Integer I2A = new Integer(2);
private static final Integer I2B = new Integer(2);
- public ReferenceIdentityMapTest(final String testName) {
- super(testName);
+ @SuppressWarnings("unused")
+ private static void gc() {
+ try {
+ // trigger GC
+ final byte[][] tooLarge = new byte[1000000000][1000000000];
+ fail("you have too much RAM");
+ } catch (final OutOfMemoryError ex) {
+ System.gc(); // ignore
+ }
}
public static Test suite() {
return BulkTest.makeSuite(ReferenceIdentityMapTest.class);
}
- @Override
- public ReferenceIdentityMap<K, V> makeObject() {
- return new ReferenceIdentityMap<>(ReferenceStrength.WEAK, ReferenceStrength.WEAK);
+ WeakReference<K> keyReference;
+
+ WeakReference<V> valueReference;
+
+ public ReferenceIdentityMapTest(final String testName) {
+ super(testName);
}
- @Override
- public Map<K, V> makeConfirmedMap() {
- // Testing against another [collections] class generally isn't a good idea,
- // but the closest alternative is IdentityHashMap, which propagates reference-equality down to keySet and values.
- // arguably ReferenceIdentityMap should do the same but that's a later discussion.
- return new IdentityMap<>();
- }
+ @SuppressWarnings("unchecked")
+ private Map<K, V> buildRefMap() {
+ final K key = (K) new Object();
+ final V value = (V) new Object();
- @Override
- public boolean isAllowNullKey() {
- return false;
- }
+ keyReference = new WeakReference<>(key);
+ valueReference = new WeakReference<>(value);
- @Override
- public boolean isAllowNullValue() {
- return false;
+ final Map<K, V> testMap = new ReferenceIdentityMap<>(ReferenceStrength.WEAK, ReferenceStrength.HARD, true);
+ testMap.put(key, value);
+
+ assertEquals("In map", value, testMap.get(key));
+ assertNotNull("Weak reference released early (1)", keyReference.get());
+ assertNotNull("Weak reference released early (2)", valueReference.get());
+ return testMap;
}
@Override
@@ -84,84 +93,24 @@
// "src/test/resources/data/test/ReferenceIdentityMap.fullCollection.version4.obj");
// }
- //-----------------------------------------------------------------------
- @SuppressWarnings("unchecked")
- public void testBasics() {
- final IterableMap<K, V> map = new ReferenceIdentityMap<>(ReferenceStrength.HARD, ReferenceStrength.HARD);
- assertEquals(0, map.size());
-
- map.put((K) I1A, (V) I2A);
- assertEquals(1, map.size());
- assertSame(I2A, map.get(I1A));
- assertSame(null, map.get(I1B));
- assertEquals(true, map.containsKey(I1A));
- assertEquals(false, map.containsKey(I1B));
- assertEquals(true, map.containsValue(I2A));
- assertEquals(false, map.containsValue(I2B));
-
- map.put((K) I1A, (V) I2B);
- assertEquals(1, map.size());
- assertSame(I2B, map.get(I1A));
- assertSame(null, map.get(I1B));
- assertEquals(true, map.containsKey(I1A));
- assertEquals(false, map.containsKey(I1B));
- assertEquals(false, map.containsValue(I2A));
- assertEquals(true, map.containsValue(I2B));
-
- map.put((K) I1B, (V) I2B);
- assertEquals(2, map.size());
- assertSame(I2B, map.get(I1A));
- assertSame(I2B, map.get(I1B));
- assertEquals(true, map.containsKey(I1A));
- assertEquals(true, map.containsKey(I1B));
- assertEquals(false, map.containsValue(I2A));
- assertEquals(true, map.containsValue(I2B));
+ @Override
+ public boolean isAllowNullKey() {
+ return false;
}
- //-----------------------------------------------------------------------
- @SuppressWarnings("unchecked")
- public void testHashEntry() {
- final IterableMap<K, V> map = new ReferenceIdentityMap<>(ReferenceStrength.HARD, ReferenceStrength.HARD);
-
- map.put((K) I1A, (V) I2A);
- map.put((K) I1B, (V) I2A);
-
- final Map.Entry<K, V> entry1 = map.entrySet().iterator().next();
- final Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
- final Map.Entry<K, V> entry2 = it.next();
- final Map.Entry<K, V> entry3 = it.next();
-
- assertEquals(true, entry1.equals(entry2));
- assertEquals(true, entry2.equals(entry1));
- assertEquals(false, entry1.equals(entry3));
+ @Override
+ public boolean isAllowNullValue() {
+ return false;
}
- //-----------------------------------------------------------------------
- @SuppressWarnings("unchecked")
- public void testNullHandling() {
- resetFull();
- assertEquals(null, getMap().get(null));
- assertEquals(false, getMap().containsKey(null));
- assertEquals(false, getMap().containsValue(null));
- assertEquals(null, getMap().remove(null));
- assertEquals(false, getMap().entrySet().contains(null));
- assertEquals(false, getMap().keySet().contains(null));
- assertEquals(false, getMap().values().contains(null));
- try {
- getMap().put(null, null);
- fail();
- } 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) {}
+ @Override
+ public Map<K, V> makeConfirmedMap() {
+ // Testing against another [collections] class generally isn't a good idea,
+ // but the closest alternative is IdentityHashMap, which propagates reference-equality down to keySet and values.
+ // arguably ReferenceIdentityMap should do the same but that's a later discussion.
+ return new IdentityMap<>();
}
- //-----------------------------------------------------------------------
/*
// Tests often fail because gc is uncontrollable
@@ -272,24 +221,83 @@
}
*/
- WeakReference<K> keyReference;
- WeakReference<V> valueReference;
+ @Override
+ public ReferenceIdentityMap<K, V> makeObject() {
+ return new ReferenceIdentityMap<>(ReferenceStrength.WEAK, ReferenceStrength.WEAK);
+ }
@SuppressWarnings("unchecked")
- private Map<K, V> buildRefMap() {
- final K key = (K) new Object();
- final V value = (V) new Object();
+ public void testBasics() {
+ final IterableMap<K, V> map = new ReferenceIdentityMap<>(ReferenceStrength.HARD, ReferenceStrength.HARD);
+ assertEquals(0, map.size());
- keyReference = new WeakReference<>(key);
- valueReference = new WeakReference<>(value);
+ map.put((K) I1A, (V) I2A);
+ assertEquals(1, map.size());
+ assertSame(I2A, map.get(I1A));
+ assertSame(null, map.get(I1B));
+ assertEquals(true, map.containsKey(I1A));
+ assertEquals(false, map.containsKey(I1B));
+ assertEquals(true, map.containsValue(I2A));
+ assertEquals(false, map.containsValue(I2B));
- final Map<K, V> testMap = new ReferenceIdentityMap<>(ReferenceStrength.WEAK, ReferenceStrength.HARD, true);
- testMap.put(key, value);
+ map.put((K) I1A, (V) I2B);
+ assertEquals(1, map.size());
+ assertSame(I2B, map.get(I1A));
+ assertSame(null, map.get(I1B));
+ assertEquals(true, map.containsKey(I1A));
+ assertEquals(false, map.containsKey(I1B));
+ assertEquals(false, map.containsValue(I2A));
+ assertEquals(true, map.containsValue(I2B));
- assertEquals("In map", value, testMap.get(key));
- assertNotNull("Weak reference released early (1)", keyReference.get());
- assertNotNull("Weak reference released early (2)", valueReference.get());
- return testMap;
+ map.put((K) I1B, (V) I2B);
+ assertEquals(2, map.size());
+ assertSame(I2B, map.get(I1A));
+ assertSame(I2B, map.get(I1B));
+ assertEquals(true, map.containsKey(I1A));
+ assertEquals(true, map.containsKey(I1B));
+ assertEquals(false, map.containsValue(I2A));
+ assertEquals(true, map.containsValue(I2B));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testHashEntry() {
+ final IterableMap<K, V> map = new ReferenceIdentityMap<>(ReferenceStrength.HARD, ReferenceStrength.HARD);
+
+ map.put((K) I1A, (V) I2A);
+ map.put((K) I1B, (V) I2A);
+
+ final Map.Entry<K, V> entry1 = map.entrySet().iterator().next();
+ final Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
+ final Map.Entry<K, V> entry2 = it.next();
+ final Map.Entry<K, V> entry3 = it.next();
+
+ assertEquals(true, entry1.equals(entry2));
+ assertEquals(true, entry2.equals(entry1));
+ assertEquals(false, entry1.equals(entry3));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testNullHandling() {
+ resetFull();
+ assertEquals(null, getMap().get(null));
+ assertEquals(false, getMap().containsKey(null));
+ assertEquals(false, getMap().containsValue(null));
+ assertEquals(null, getMap().remove(null));
+ assertEquals(false, getMap().entrySet().contains(null));
+ assertEquals(false, getMap().keySet().contains(null));
+ assertEquals(false, getMap().values().contains(null));
+ try {
+ getMap().put(null, null);
+ fail();
+ } 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 */
@@ -318,15 +326,4 @@
}
}
- @SuppressWarnings("unused")
- private static void gc() {
- try {
- // trigger GC
- final byte[][] tooLarge = new byte[1000000000][1000000000];
- fail("you have too much RAM");
- } catch (final OutOfMemoryError ex) {
- System.gc(); // ignore
- }
- }
-
}