Simplify lambdas.
This commit is contained in:
parent
2f7a3a8118
commit
386c1e2f37
|
@ -46,7 +46,7 @@ class StreamsTest {
|
|||
@Test
|
||||
void testSimpleStreamMap() {
|
||||
final List<String> input = Arrays.asList("1", "2", "3", "4", "5", "6");
|
||||
final List<Integer> output = Functions.stream(input).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
|
||||
final List<Integer> 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<String> 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<String> input = Arrays.asList("1", "2", "3", "4", "5", "6");
|
||||
final List<Integer> 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<DynamicTest> simpleStreamFilterFailing() {
|
||||
final List<String> input = Arrays.asList("1", "2", "3", "4", "5", "6");
|
||||
final List<Integer> 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);
|
||||
|
|
Loading…
Reference in New Issue