You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/10/03 13:34:58 UTC

(commons-collections) branch master updated (65ce14b75 -> a685fae36)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git


    from 65ce14b75 Fix test: compute if present is a put.
     new 563034f78 Javadoc
     new a685fae36 Complete AbstractMapTest.testMapComputeIfPresent() implementation

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../commons/collections4/AbstractObjectTest.java   |  2 +-
 .../commons/collections4/bag/AbstractBagTest.java  |  2 +-
 .../collections4/bidimap/AbstractBidiMapTest.java  |  2 +-
 .../bidimap/AbstractOrderedBidiMapTest.java        |  2 +-
 .../bidimap/AbstractSortedBidiMapTest.java         |  2 +-
 .../collection/AbstractCollectionTest.java         |  2 +-
 .../collections4/list/AbstractListTest.java        |  2 +-
 .../collections4/map/AbstractIterableMapTest.java  |  2 +-
 .../commons/collections4/map/AbstractMapTest.java  | 67 ++++++++++++----------
 .../collections4/map/AbstractOrderedMapTest.java   |  2 +-
 .../collections4/map/AbstractSortedMapTest.java    |  2 +-
 .../collections4/map/UnmodifiableMapTest.java      |  3 +-
 .../collections4/queue/AbstractQueueTest.java      |  2 +-
 .../collections4/set/AbstractNavigableSetTest.java |  2 +-
 .../commons/collections4/set/AbstractSetTest.java  |  2 +-
 .../collections4/set/AbstractSortedSetTest.java    |  2 +-
 16 files changed, 52 insertions(+), 46 deletions(-)


(commons-collections) 01/02: Javadoc

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git

commit 563034f78d38bc9ad0e0519beaa1cfaf3a5e565e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Oct 3 09:29:11 2024 -0400

    Javadoc
---
 src/test/java/org/apache/commons/collections4/AbstractObjectTest.java  | 2 +-
 src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java | 2 +-
 .../org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java   | 2 +-
 .../commons/collections4/bidimap/AbstractOrderedBidiMapTest.java       | 2 +-
 .../apache/commons/collections4/bidimap/AbstractSortedBidiMapTest.java | 2 +-
 .../apache/commons/collections4/collection/AbstractCollectionTest.java | 2 +-
 .../java/org/apache/commons/collections4/list/AbstractListTest.java    | 2 +-
 .../org/apache/commons/collections4/map/AbstractIterableMapTest.java   | 2 +-
 .../org/apache/commons/collections4/map/AbstractOrderedMapTest.java    | 2 +-
 .../org/apache/commons/collections4/map/AbstractSortedMapTest.java     | 2 +-
 .../java/org/apache/commons/collections4/map/UnmodifiableMapTest.java  | 3 +--
 .../java/org/apache/commons/collections4/queue/AbstractQueueTest.java  | 2 +-
 .../org/apache/commons/collections4/set/AbstractNavigableSetTest.java  | 2 +-
 src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java | 2 +-
 .../org/apache/commons/collections4/set/AbstractSortedSetTest.java     | 2 +-
 15 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java b/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java
index bd0c297ef..c159c9e80 100644
--- a/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java
+++ b/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java
@@ -35,7 +35,7 @@ import java.io.Serializable;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link Object} methods and contracts.
+ * Tests {@link Object}.
  * <p>
  * To use, simply extend this class, and implement
  * the {@link #makeObject()} method.
diff --git a/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java b/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java
index 2b744be13..31236a413 100644
--- a/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java
+++ b/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java
@@ -43,7 +43,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link org.apache.commons.collections4.Bag Bag} methods and contracts.
+ * Tests {@link org.apache.commons.collections4.Bag Bag}.
  * <p>
  * To use, simply extend this class, and implement
  * the {@link #makeObject} method.
diff --git a/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java b/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java
index 079884fe9..3070902da 100644
--- a/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java
@@ -39,7 +39,7 @@ import org.junit.jupiter.api.Assumptions;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link BidiMap} methods and contracts.
+ * Tests {@link BidiMap}.
  */
 public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<K, V> {
 
diff --git a/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java b/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java
index 684d6a271..887fad690 100644
--- a/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java
@@ -34,7 +34,7 @@ import org.apache.commons.collections4.iterators.AbstractMapIteratorTest;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link OrderedBidiMap} methods and contracts.
+ * Tests {@link OrderedBidiMap}.
  */
 public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTest<K, V> {
 
diff --git a/src/test/java/org/apache/commons/collections4/bidimap/AbstractSortedBidiMapTest.java b/src/test/java/org/apache/commons/collections4/bidimap/AbstractSortedBidiMapTest.java
index 5ce297ded..2ec1a5d94 100644
--- a/src/test/java/org/apache/commons/collections4/bidimap/AbstractSortedBidiMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/bidimap/AbstractSortedBidiMapTest.java
@@ -37,7 +37,7 @@ import org.apache.commons.collections4.map.AbstractSortedMapTest;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link SortedBidiMap} methods and contracts.
+ * Tests {@link SortedBidiMap}.
  */
 public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V extends Comparable<V>> extends AbstractOrderedBidiMapTest<K, V> {
 
diff --git a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java
index 31117ab06..6152f4c0c 100644
--- a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java
+++ b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java
@@ -50,7 +50,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link java.util.Collection} methods and contracts.
+ * Tests {@link java.util.Collection}.
  * <p>
  * You should create a concrete subclass of this class to test any custom
  * {@link Collection} implementation.  At minimum, you'll have to
diff --git a/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java b/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java
index 3be2938cb..6bd558923 100644
--- a/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java
+++ b/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java
@@ -43,7 +43,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link java.util.List} methods and contracts.
+ * Tests {@link java.util.List}.
  * <p>
  * To use, simply extend this class, and implement
  * the {@link #makeObject} method.
diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractIterableMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractIterableMapTest.java
index e5ab73e36..cb2078444 100644
--- a/src/test/java/org/apache/commons/collections4/map/AbstractIterableMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/AbstractIterableMapTest.java
@@ -29,7 +29,7 @@ import org.apache.commons.collections4.iterators.AbstractMapIteratorTest;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link IterableMap} methods and contracts.
+ * Tests {@link IterableMap}.
  *
  * @param <K> the key type.
  * @param <V> the value type.
diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java
index c0583c909..ef86bb6d8 100644
--- a/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java
@@ -37,7 +37,7 @@ import org.apache.commons.collections4.iterators.AbstractOrderedMapIteratorTest;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link OrderedMap} methods and contracts.
+ * Tests {@link OrderedMap}.
  *
  * @param <K> the type of the keys in the maps tested.
  * @param <V> the type of the values in the maps tested.
diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractSortedMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractSortedMapTest.java
index 8b1e6a069..9d7047d84 100644
--- a/src/test/java/org/apache/commons/collections4/map/AbstractSortedMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/AbstractSortedMapTest.java
@@ -31,7 +31,7 @@ import org.apache.commons.collections4.BulkTest;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link java.util.SortedMap} methods and contracts.
+ * Tests {@link java.util.SortedMap}.
  *
  * @param <K> the key type.
  * @param <V> the value type.
diff --git a/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java b/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java
index 230c33f14..9874b511d 100644
--- a/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java
@@ -28,8 +28,7 @@ import org.apache.commons.collections4.Unmodifiable;
 import org.junit.jupiter.api.Test;
 
 /**
- * Extension of {@link AbstractMapTest} for exercising the
- * {@link UnmodifiableMap} implementation.
+ * Tests {@link UnmodifiableMap}.
  *
  * @param <K> the key type.
  * @param <V> the value type.
diff --git a/src/test/java/org/apache/commons/collections4/queue/AbstractQueueTest.java b/src/test/java/org/apache/commons/collections4/queue/AbstractQueueTest.java
index b7ef64b3b..31958b8ee 100644
--- a/src/test/java/org/apache/commons/collections4/queue/AbstractQueueTest.java
+++ b/src/test/java/org/apache/commons/collections4/queue/AbstractQueueTest.java
@@ -35,7 +35,7 @@ import org.apache.commons.collections4.collection.AbstractCollectionTest;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link java.util.Queue} methods and contracts.
+ * Tests {@link java.util.Queue}.
  * <p>
  * To use, simply extend this class, and implement
  * the {@link #makeObject} method.
diff --git a/src/test/java/org/apache/commons/collections4/set/AbstractNavigableSetTest.java b/src/test/java/org/apache/commons/collections4/set/AbstractNavigableSetTest.java
index be2e22b5a..86ae38d94 100644
--- a/src/test/java/org/apache/commons/collections4/set/AbstractNavigableSetTest.java
+++ b/src/test/java/org/apache/commons/collections4/set/AbstractNavigableSetTest.java
@@ -25,7 +25,7 @@ import java.util.TreeSet;
 import org.apache.commons.collections4.BulkTest;
 
 /**
- * Abstract test class for {@link NavigableSet} methods and contracts.
+ * Tests {@link NavigableSet}.
  * <p>
  * To use, subclass and override the {@link #makeObject()}
  * method.  You may have to override other protected methods if your
diff --git a/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java b/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java
index 5267c0a71..84df9d640 100644
--- a/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java
+++ b/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java
@@ -29,7 +29,7 @@ import org.apache.commons.collections4.collection.AbstractCollectionTest;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link Set} methods and contracts.
+ * Tests {@link Set}.
  * <p>
  * Since {@link Set} doesn't stipulate much new behavior that isn't already
  * found in {@link Collection}, this class basically just adds tests for
diff --git a/src/test/java/org/apache/commons/collections4/set/AbstractSortedSetTest.java b/src/test/java/org/apache/commons/collections4/set/AbstractSortedSetTest.java
index 2f66b69bc..095bc6a7d 100644
--- a/src/test/java/org/apache/commons/collections4/set/AbstractSortedSetTest.java
+++ b/src/test/java/org/apache/commons/collections4/set/AbstractSortedSetTest.java
@@ -25,7 +25,7 @@ import java.util.TreeSet;
 import org.apache.commons.collections4.BulkTest;
 
 /**
- * Abstract test class for {@link SortedSet} methods and contracts.
+ * Tests {@link SortedSet}.
  * <p>
  * To use, subclass and override the {@link #makeObject()}
  * method.  You may have to override other protected methods if your


(commons-collections) 02/02: Complete AbstractMapTest.testMapComputeIfPresent() implementation

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git

commit a685fae36f64ed9701f1a478bd1fa1822ddcdf2d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Oct 3 09:34:52 2024 -0400

    Complete AbstractMapTest.testMapComputeIfPresent() implementation
---
 .../commons/collections4/map/AbstractMapTest.java  | 67 ++++++++++++----------
 1 file changed, 37 insertions(+), 30 deletions(-)

diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java
index d3398ecba..f8aac17c8 100644
--- a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java
@@ -53,7 +53,7 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Test;
 
 /**
- * Abstract test class for {@link java.util.Map} methods and contracts.
+ * Tests {@link java.util.Map}.
  * <p>
  * The forces at work here are similar to those in {@link AbstractCollectionTest}. If your class implements the full Map interface, including optional
  * operations, simply extend this class, and implement the {@link #makeObject()} method.
@@ -1625,38 +1625,45 @@ public abstract class AbstractMapTest<M extends Map<K, V>, K, V> extends Abstrac
             // compute if present is a put.
             resetEmpty();
             getMap().computeIfPresent(keys[0], (k, v) -> values[0]);
-            resetFull();
-            int i = 0;
-            for (final Iterator<K> it = getMap().keySet().iterator(); it.hasNext() && i < newValues.length; i++) {
-                final K key = it.next();
-                final V newValue = newValues[i];
-                final boolean newValueAlready = getMap().containsValue(newValue);
-                final V prevValue = getMap().get(key);
-                final V oldValue = getMap().putIfAbsent(key, newValue);
-                final V value = getConfirmed().putIfAbsent(key, newValue);
-                verify();
-                assertEquals(value, oldValue, "Map.putIfAbsent should return previous value when changed");
-                assertEquals(prevValue, oldValue, "Map.putIfAbsent should return previous value when changed");
-                if (prevValue == null) {
-                    assertEquals(newValue, getMap().get(key), String.format("[%,d] key '%s', prevValue '%s', newValue '%s'", i, key, prevValue, newValue));
-                } else {
-                    assertEquals(oldValue, getMap().get(key), String.format("[%,d] key '%s', prevValue '%s', newValue '%s'", i, key, prevValue, newValue));
-                }
-                assertTrue(getMap().containsKey(key), "Map should still contain key after putIfAbsent when changed");
-                if (newValueAlready && newValue != null) {
-                    // TODO The test fixture already contain a null value, so we condition this assertion
-                    assertFalse(getMap().containsValue(newValue),
-                            String.format("[%,d] Map at '%s' shouldn't contain new value '%s' after putIfAbsent when changed", i, key, newValue));
-                }
-                // if duplicates are allowed, we're not guaranteed that the value
-                // no longer exists, so don't try checking that.
-                if (!isAllowDuplicateValues()) {
-                    assertFalse(getMap().containsValue(values[i]), "Map should not contain old value after putIfAbsent when changed");
+            if (isPutAddSupported()) {
+                resetFull();
+                int i = 0;
+                for (final Iterator<K> it = getMap().keySet().iterator(); it.hasNext() && i < newValues.length; i++) {
+                    final K key = it.next();
+                    final V newValue = newValues[i];
+                    final boolean newValueAlready = getMap().containsValue(newValue);
+                    final V prevValue = getMap().get(key);
+                    final V oldValue = getMap().computeIfPresent(key, (k, v) -> newValue);
+                    final V value = getConfirmed().computeIfPresent(key, (k, v) -> newValue);
+                    verify();
+                    assertEquals(value, oldValue, "Map.putIfAbsent should return previous value when changed");
+                    assertEquals(prevValue, oldValue, "Map.putIfAbsent should return previous value when changed");
+                    if (prevValue == null) {
+                        assertEquals(newValue, getMap().get(key), String.format("[%,d] key '%s', prevValue '%s', newValue '%s'", i, key, prevValue, newValue));
+                    } else {
+                        assertEquals(oldValue, getMap().get(key), String.format("[%,d] key '%s', prevValue '%s', newValue '%s'", i, key, prevValue, newValue));
+                    }
+                    assertTrue(getMap().containsKey(key), "Map should still contain key after putIfAbsent when changed");
+                    if (newValueAlready && newValue != null) {
+                        // TODO The test fixture already contain a null value, so we condition this assertion
+                        assertFalse(getMap().containsValue(newValue),
+                                String.format("[%,d] Map at '%s' shouldn't contain new value '%s' after putIfAbsent when changed", i, key, newValue));
+                    }
+                    // if duplicates are allowed, we're not guaranteed that the value
+                    // no longer exists, so don't try checking that.
+                    if (!isAllowDuplicateValues()) {
+                        assertFalse(getMap().containsValue(values[i]), "Map should not contain old value after putIfAbsent when changed");
+                    }
                 }
             }
         } else {
-            assertThrows(UnsupportedOperationException.class, () -> getMap().putIfAbsent(keys[0], values[0]),
-                    "Expected UnsupportedOperationException on put (add)");
+            if (getMap().containsKey(keys[0])) {
+                assertThrows(UnsupportedOperationException.class, () -> getMap().computeIfPresent(keys[0], (k, v) -> values[0]),
+                        "Expected UnsupportedOperationException on put (add)");
+            } else {
+                // doesn't throw
+                getMap().computeIfPresent(keys[0], (k, v) -> values[0]);
+            }
         }
     }