diff --git a/src/test/java/org/apache/commons/collections4/FluentIterableTest.java b/src/test/java/org/apache/commons/collections4/FluentIterableTest.java index 492044a0c..b2aada813 100644 --- a/src/test/java/org/apache/commons/collections4/FluentIterableTest.java +++ b/src/test/java/org/apache/commons/collections4/FluentIterableTest.java @@ -213,7 +213,7 @@ public class FluentIterableTest { @Test public void forEach() { final AtomicInteger sum = new AtomicInteger(0); - final Closure closure = input -> sum.addAndGet(input); + final Closure closure = sum::addAndGet; FluentIterable.of(iterableA).forEach(closure); int expectedSum = 0; diff --git a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java index 6696d980a..ba3f5addd 100644 --- a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java @@ -167,9 +167,7 @@ public class MapUtilsTest { @Test public void testInvertMapNull() { final Map nullMap = null; - final Exception exception = assertThrows(NullPointerException.class, () -> { - MapUtils.invertMap(nullMap); - }); + final Exception exception = assertThrows(NullPointerException.class, () -> MapUtils.invertMap(nullMap)); final String actualMessage = exception.getMessage(); assertTrue(actualMessage.contains("map")); } @@ -1015,30 +1013,22 @@ public class MapUtilsTest { @Test public void testUnmodifiableMap() { - final Exception exception = assertThrows(UnsupportedOperationException.class, () -> { - MapUtils.unmodifiableMap(new HashMap<>()).clear(); - }); + final Exception exception = assertThrows(UnsupportedOperationException.class, () -> MapUtils.unmodifiableMap(new HashMap<>()).clear()); } @Test public void testUnmodifiableSortedMap() { - final Exception exception = assertThrows(UnsupportedOperationException.class, () -> { - MapUtils.unmodifiableSortedMap(new TreeMap<>()).clear(); - }); + final Exception exception = assertThrows(UnsupportedOperationException.class, () -> MapUtils.unmodifiableSortedMap(new TreeMap<>()).clear()); } @Test public void testFixedSizeMap() { - final Exception exception = assertThrows(IllegalArgumentException.class, () -> { - MapUtils.fixedSizeMap(new HashMap<>()).put(new Object(), new Object()); - }); + final Exception exception = assertThrows(IllegalArgumentException.class, () -> MapUtils.fixedSizeMap(new HashMap<>()).put(new Object(), new Object())); } @Test public void testFixedSizeSortedMap() { - final Exception exception = assertThrows(IllegalArgumentException.class, () -> { - MapUtils.fixedSizeSortedMap(new TreeMap()).put(1L, 1L); - }); + final Exception exception = assertThrows(IllegalArgumentException.class, () -> MapUtils.fixedSizeSortedMap(new TreeMap()).put(1L, 1L)); } @Test diff --git a/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java b/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java index 0ace69d87..b5d37194e 100644 --- a/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java @@ -79,7 +79,7 @@ public class SplitMapUtilsTest { // check individual operations int sz = map.size(); - attemptPutOperation(() -> map.clear()); + attemptPutOperation(map::clear); assertEquals(sz, map.size()); @@ -116,11 +116,11 @@ public class SplitMapUtilsTest { public void testWritableMap() { final Map map = SplitMapUtils.writableMap(transformedMap); attemptGetOperation(() -> map.get(null)); - attemptGetOperation(() -> map.entrySet()); - attemptGetOperation(() -> map.keySet()); - attemptGetOperation(() -> map.values()); - attemptGetOperation(() -> map.size()); - attemptGetOperation(() -> map.isEmpty()); + attemptGetOperation(map::entrySet); + attemptGetOperation(map::keySet); + attemptGetOperation(map::values); + attemptGetOperation(map::size); + attemptGetOperation(map::isEmpty); attemptGetOperation(() -> map.containsKey(null)); attemptGetOperation(() -> map.containsValue(null)); attemptGetOperation(() -> map.remove(null)); 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 60d63700c..62c036e0f 100644 --- a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java @@ -963,7 +963,7 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { final int size = getCollection().size(); final int targetCount = Collections.frequency(elements, target); - final Predicate filter = e -> target.equals(e); + final Predicate filter = target::equals; assertTrue("Full collection removeIf should work", getCollection().removeIf(filter)); getConfirmed().removeIf(filter); diff --git a/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java b/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java index bb918f096..374b039d8 100644 --- a/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java @@ -700,12 +700,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { } } synchronized (map) { - for (final Iterator> iter = map.entrySet().iterator(); iter.hasNext();) { - final Map.Entry entry = iter.next(); - if (entry.getValue() == this) { - iter.remove(); - } - } + map.entrySet().removeIf(entry -> entry.getValue() == this); } } catch (final InterruptedException e) { fail("Unexpected InterruptedException"); @@ -866,11 +861,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { } } synchronized (map) { - for (final Iterator iter = map.values().iterator(); iter.hasNext();) { - if (iter.next() == this) { - iter.remove(); - } - } + map.values().removeIf(thread1 -> thread1 == this); } } catch (final InterruptedException e) { fail("Unexpected InterruptedException"); diff --git a/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java b/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java index 064516eb5..34121022d 100644 --- a/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java @@ -261,7 +261,7 @@ public class ReferenceMapTest extends AbstractIterableMapTest { public void testCustomPurge() { final List expiredValues = new ArrayList<>(); @SuppressWarnings("unchecked") - final Consumer consumer = (Consumer & Serializable) v -> expiredValues.add(v); + final Consumer consumer = (Consumer & Serializable) expiredValues::add; final Map map = new ReferenceMap(ReferenceStrength.WEAK, ReferenceStrength.HARD, false) { private static final long serialVersionUID = 1L;