From 386c1e2f37f77aedbfb624800bab51319bf3a9fd Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 13 Jun 2020 10:55:46 -0400 Subject: [PATCH] Simplify lambdas. --- .../org/apache/commons/lang3/StreamsTest.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/apache/commons/lang3/StreamsTest.java b/src/test/java/org/apache/commons/lang3/StreamsTest.java index 3e17ed1bd..a0b79f60c 100644 --- a/src/test/java/org/apache/commons/lang3/StreamsTest.java +++ b/src/test/java/org/apache/commons/lang3/StreamsTest.java @@ -46,7 +46,7 @@ class StreamsTest { @Test void testSimpleStreamMap() { final List input = Arrays.asList("1", "2", "3", "4", "5", "6"); - final List output = Functions.stream(input).map(s -> Integer.valueOf(s)).collect(Collectors.toList()); + final List output = Functions.stream(input).map(Integer::valueOf).collect(Collectors.toList()); assertEquals(6, output.size()); for (int i = 0; i < 6; i++) { assertEquals(i+1, output.get(i).intValue()); @@ -56,7 +56,7 @@ class StreamsTest { @Test void testSimpleStreamMapFailing() { final List input = Arrays.asList("1", "2", "3", "4 ", "5", "6"); - final Executable testMethod = () -> Functions.stream(input).map(s -> Integer.valueOf(s)).collect(Collectors.toList()); + final Executable testMethod = () -> Functions.stream(input).map(Integer::valueOf).collect(Collectors.toList()); final NumberFormatException thrown = assertThrows(NumberFormatException.class, testMethod); assertEquals("For input string: \"4 \"", thrown.getMessage()); } @@ -130,10 +130,8 @@ class StreamsTest { void testSimpleStreamFilter() { final List input = Arrays.asList("1", "2", "3", "4", "5", "6"); final List output = Functions.stream(input) - .map(s -> Integer.valueOf(s)) - .filter(i -> { - return i.intValue() %2 == 0; - }) + .map(Integer::valueOf) + .filter(i -> (i.intValue() %2 == 0)) .collect(Collectors.toList()); assertEvenNumbers(output); } @@ -160,7 +158,7 @@ class StreamsTest { Stream simpleStreamFilterFailing() { final List input = Arrays.asList("1", "2", "3", "4", "5", "6"); final List output = Functions.stream(input) - .map(s -> Integer.valueOf(s)) + .map(Integer::valueOf) .filter(asIntPredicate(null)) .collect(Collectors.toList()); assertEvenNumbers(output); @@ -170,7 +168,7 @@ class StreamsTest { dynamicTest("IllegalArgumentException", () -> { final IllegalArgumentException iae = new IllegalArgumentException("Invalid argument: " + 5); final Executable testMethod = () -> Functions.stream(input) - .map(s -> Integer.valueOf(s)) + .map(Integer::valueOf) .filter(asIntPredicate(iae)) .collect(Collectors.toList()); final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, testMethod); @@ -180,7 +178,7 @@ class StreamsTest { dynamicTest("OutOfMemoryError", () -> { final OutOfMemoryError oome = new OutOfMemoryError(); final Executable testMethod = () -> Functions.stream(input) - .map(s -> Integer.valueOf(s)) + .map(Integer::valueOf) .filter(asIntPredicate(oome)) .collect(Collectors.toList()); final OutOfMemoryError thrown = assertThrows(OutOfMemoryError.class, testMethod); @@ -190,7 +188,7 @@ class StreamsTest { dynamicTest("SAXException", () -> { final SAXException se = new SAXException(); final Executable testMethod = () -> Functions.stream(input) - .map(s -> Integer.valueOf(s)) + .map(Integer::valueOf) .filter(asIntPredicate(se)) .collect(Collectors.toList()); final UndeclaredThrowableException thrown = assertThrows(UndeclaredThrowableException.class, testMethod);