changeset 8444:e86f51639227

Temporarily sever dependence of tests on Functions static methods; misc test tweaks
author briangoetz
date Tue, 30 Apr 2013 22:59:39 -0400
parents 7c4898c8b974
children e6c5b31dd1ae
files test-ng/bootlib/java/util/stream/LambdaTestHelpers.java test-ng/tests/org/openjdk/tests/java/util/regex/PatternTest.java test-ng/tests/org/openjdk/tests/java/util/stream/ForEachOpTest.java test-ng/tests/org/openjdk/tests/java/util/stream/GroupByOpTest.java test-ng/tests/org/openjdk/tests/java/util/stream/InfiniteStreamWithLimitOpTest.java test-ng/tests/org/openjdk/tests/java/util/stream/MapOpTest.java test-ng/tests/org/openjdk/tests/java/util/stream/SequentialOpTest.java test-ng/tests/org/openjdk/tests/java/util/stream/StreamBuilderTest.java test-ng/tests/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java test-ng/tests/org/openjdk/tests/java/util/stream/TabulatorsTest.java
diffstat 10 files changed, 37 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/test-ng/bootlib/java/util/stream/LambdaTestHelpers.java	Tue Apr 30 12:53:41 2013 -0700
+++ b/test-ng/bootlib/java/util/stream/LambdaTestHelpers.java	Tue Apr 30 22:59:39 2013 -0400
@@ -132,6 +132,15 @@
         return t -> predicate.test(t) ? forTrue : forFalse;
     }
 
+    public static <T> Function<T, T> identity() {
+        return t -> t;
+    }
+
+    public static<V, T, R> Function<V, R> compose(Function<? super T, ? extends R> after, Function<? super V, ? extends T> before) {
+        Objects.requireNonNull(before);
+        return (V v) -> after.apply(before.apply(v));
+    }
+
     public static List<Integer> empty() {
         ArrayList<Integer> list = new ArrayList<>();
         list.add(null);
--- a/test-ng/tests/org/openjdk/tests/java/util/regex/PatternTest.java	Tue Apr 30 12:53:41 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/regex/PatternTest.java	Tue Apr 30 22:59:39 2013 -0400
@@ -8,6 +8,7 @@
 import java.util.function.Function;
 import java.util.function.Supplier;
 import java.util.regex.Pattern;
+import java.util.stream.LambdaTestHelpers;
 import java.util.stream.OpTestCase;
 import java.util.stream.Stream;
 import java.util.stream.TestData;
@@ -97,6 +98,6 @@
     public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
 	Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
 	withData(TestData.Factory.ofSupplier(description, ss))
-		 .stream(Function.identity()).expectedResult(expected).exercise();
+		 .stream(LambdaTestHelpers.identity()).expectedResult(expected).exercise();
     }
 }
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/ForEachOpTest.java	Tue Apr 30 12:53:41 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/ForEachOpTest.java	Tue Apr 30 22:59:39 2013 -0400
@@ -79,7 +79,7 @@
 
         // Test multiple stages
         withData(data).
-                terminal(s -> s.map(Function.identity()), terminalFunc).
+                terminal(s -> s.map(LambdaTestHelpers.identity()), terminalFunc).
                 expectedResult(input).
                 exercise();
     }
@@ -100,7 +100,7 @@
 
         // Test multiple stages
         withData(data).
-                terminal(s -> s.map(Function.identity()), terminalFunc).
+                terminal(s -> s.map(LambdaTestHelpers.identity()), terminalFunc).
                 parallelEqualityAsserter(LambdaTestHelpers::assertContentsUnordered).
                 exercise();
     }
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/GroupByOpTest.java	Tue Apr 30 12:53:41 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/GroupByOpTest.java	Tue Apr 30 22:59:39 2013 -0400
@@ -115,8 +115,8 @@
             new MapperData<>(mId, uniqueSize),
             new MapperData<>(mZero, Math.min(1, data.size())),
             new MapperData<>(mDoubler, uniqueSize),
-            new MapperData<>(mId.compose(mDoubler), uniqueSize),
-            new MapperData<>(mDoubler.compose(mDoubler), uniqueSize),
+            new MapperData<>(LambdaTestHelpers.compose(mId, mDoubler), uniqueSize),
+            new MapperData<>(LambdaTestHelpers.compose(mDoubler, mDoubler), uniqueSize),
 
             new MapperData<>(LambdaTestHelpers.forPredicate(pFalse, true, false), Math.min(1, uniqueSize)),
             new MapperData<>(LambdaTestHelpers.forPredicate(pTrue, true, false), Math.min(1, uniqueSize)),
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/InfiniteStreamWithLimitOpTest.java	Tue Apr 30 12:53:41 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/InfiniteStreamWithLimitOpTest.java	Tue Apr 30 22:59:39 2013 -0400
@@ -31,7 +31,6 @@
 import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
-import java.util.stream.Streams;
 
 import static java.util.stream.LambdaTestHelpers.assertContents;
 
@@ -59,8 +58,11 @@
     }
 
     public void testInfiniteWithLimitToShortCircuitTerminal() {
-        Stream.generate(() -> (Integer) 1).limit(4).toArray();
-        Stream.generate(() -> (Integer) 1).limit(4).filter(i -> true).toArray();
-        Stream.generate(() -> (Integer) 1).limit(4).collect(Collectors.toList());
+        Object[] array = Stream.generate(() -> 1).limit(4).toArray();
+        assertEquals(4, array.length);
+        array = Stream.generate(() -> 1).limit(4).filter(i -> true).toArray();
+        assertEquals(4, array.length);
+        List<Integer> result = Stream.generate(() -> 1).limit(4).collect(Collectors.toList());
+        assertEquals(result, Arrays.asList(1, 1, 1, 1));
     }
 }
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/MapOpTest.java	Tue Apr 30 12:53:41 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/MapOpTest.java	Tue Apr 30 22:59:39 2013 -0400
@@ -56,8 +56,8 @@
         assertCountSum(countTo(10).stream().map(mDoubler), 10, 110);
         assertCountSum(countTo(10).stream().map(mDoubler).map(mDoubler), 10, 220);
 
-        exerciseOps(countTo(0), s -> s.map(Function.identity()), countTo(0));
-        exerciseOps(countTo(1000), s -> s.map(Function.identity()), countTo(1000));
+        exerciseOps(countTo(0), s -> s.map(LambdaTestHelpers.identity()), countTo(0));
+        exerciseOps(countTo(1000), s -> s.map(LambdaTestHelpers.identity()), countTo(1000));
         // @@@ Force cast to integer so output is Stream<Integer> rather an IntStream
         //     this just ensures that no warnings are logged about boxing
         //     when the result is compared with the output
@@ -86,8 +86,8 @@
         exerciseOpsInt(data, s -> s.map(mId), s -> s.map(e -> e), s -> s.map(e -> e), s -> s.map(e -> e));
         exerciseOpsInt(data, s -> s.map(mZero), s -> s.map(e -> 0), s -> s.map(e -> 0), s -> s.map(e -> 0));
         exerciseOpsInt(data, s -> s.map(mDoubler), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e));
-        exerciseOpsInt(data, s -> s.map(mId.compose(mDoubler)), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e));
-        exerciseOpsInt(data, s -> s.map(mDoubler.compose(mDoubler)), s -> s.map(e -> 4*e), s -> s.map(e -> 4*e), s -> s.map(e -> 4*e));
+        exerciseOpsInt(data, s -> s.map(LambdaTestHelpers.compose(mId, mDoubler)), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e));
+        exerciseOpsInt(data, s -> s.map(LambdaTestHelpers.compose(mDoubler, mDoubler)), s -> s.map(e -> 4*e), s -> s.map(e -> 4*e), s -> s.map(e -> 4*e));
         exerciseOps(data, s -> s.mapToInt(i -> i));
         exerciseOps(data, s -> s.mapToLong(i -> i));
         exerciseOps(data, s -> s.mapToDouble(i -> i));
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/SequentialOpTest.java	Tue Apr 30 12:53:41 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/SequentialOpTest.java	Tue Apr 30 22:59:39 2013 -0400
@@ -52,7 +52,7 @@
     @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class,
           groups = { "serialization-hostile" })
     public void testLazy(String name, TestData.OfRef<Integer> data) {
-        Function<Integer, Integer> id = Function.identity();
+        Function<Integer, Integer> id = LambdaTestHelpers.identity();
         AtomicInteger counter = new AtomicInteger();
         Supplier<Stream<Integer>>[] suppliers = new Supplier[] { () -> data.stream(), () -> data.parallelStream() };
         UnaryOperator<Stream<Integer>>[] configs
@@ -93,7 +93,7 @@
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
     public void testMixedSeqPar(String name, TestData.OfRef<Integer> data) {
-        Function<Integer, Integer> id = Function.identity();
+        Function<Integer, Integer> id = LambdaTestHelpers.identity();
         UnaryOperator<Stream<Integer>>[] changers
                 = new UnaryOperator[] {
                 (UnaryOperator<Stream<Integer>>) s -> s,
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/StreamBuilderTest.java	Tue Apr 30 12:53:41 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/StreamBuilderTest.java	Tue Apr 30 22:59:39 2013 -0400
@@ -33,6 +33,7 @@
 import java.util.function.Function;
 import java.util.stream.DoubleStream;
 import java.util.stream.IntStream;
+import java.util.stream.LambdaTestHelpers;
 import java.util.stream.LongStream;
 import java.util.stream.OpTestCase;
 import java.util.stream.Stream;
@@ -83,7 +84,7 @@
                 exercise();
 
         withData(data).
-                stream(s -> s.map(Function.identity())).
+                stream(s -> s.map(LambdaTestHelpers.identity())).
                 expectedResult(Collections.singletonList(1)).
                 exercise();
     }
@@ -127,7 +128,7 @@
                 exercise();
 
         withData(data).
-                stream(s -> s.map(Function.identity())).
+                stream(s -> s.map(LambdaTestHelpers.identity())).
                 expectedResult(IntStream.range(0, size).boxed().collect(toList())).
                 exercise();
     }
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java	Tue Apr 30 12:53:41 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java	Tue Apr 30 22:59:39 2013 -0400
@@ -38,6 +38,7 @@
 import java.util.stream.DoubleStreamTestDataProvider;
 import java.util.stream.IntStream;
 import java.util.stream.IntStreamTestDataProvider;
+import java.util.stream.LambdaTestHelpers;
 import java.util.stream.LongStream;
 import java.util.stream.LongStreamTestDataProvider;
 import java.util.stream.OpTestCase;
@@ -254,7 +255,7 @@
         List<UnaryOperator<Stream<Integer>>> intermediateOps = Arrays.asList(
                 s -> s.parallel(),
                 // The following ensures the wrapping spliterator is tested
-                s -> s.map(Function.identity()).parallel()
+                s -> s.map(LambdaTestHelpers.identity()).parallel()
         );
 
         for (Consumer<Stream<Integer>> terminalOp : terminalOps) {
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/TabulatorsTest.java	Tue Apr 30 12:53:41 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/TabulatorsTest.java	Tue Apr 30 22:59:39 2013 -0400
@@ -326,23 +326,23 @@
         exerciseMapTabulation(data,
                               groupingBy(classifier, reducing(0, Integer::sum)),
                               new GroupedMapAssertion<>(classifier, HashMap.class,
-                                                        new ReduceAssertion<>(0, Function.identity(), Integer::sum)));
+                                                        new ReduceAssertion<>(0, LambdaTestHelpers.identity(), Integer::sum)));
         // with concurrent
         exerciseMapTabulation(data,
                               groupingByConcurrent(classifier, reducing(0, Integer::sum)),
                               new GroupedMapAssertion<>(classifier, ConcurrentHashMap.class,
-                                                        new ReduceAssertion<>(0, Function.identity(), Integer::sum)));
+                                                        new ReduceAssertion<>(0, LambdaTestHelpers.identity(), Integer::sum)));
 
         // With explicit constructors
         exerciseMapTabulation(data,
                               groupingBy(classifier, TreeMap::new, reducing(0, Integer::sum)),
                               new GroupedMapAssertion<>(classifier, TreeMap.class,
-                                                        new ReduceAssertion<>(0, Function.identity(), Integer::sum)));
+                                                        new ReduceAssertion<>(0, LambdaTestHelpers.identity(), Integer::sum)));
         // with concurrent
         exerciseMapTabulation(data,
                               groupingByConcurrent(classifier, ConcurrentSkipListMap::new, reducing(0, Integer::sum)),
                               new GroupedMapAssertion<>(classifier, ConcurrentSkipListMap.class,
-                                                        new ReduceAssertion<>(0, Function.identity(), Integer::sum)));
+                                                        new ReduceAssertion<>(0, LambdaTestHelpers.identity(), Integer::sum)));
 
         // Single-level map-reduce
         exerciseMapTabulation(data,
@@ -395,6 +395,6 @@
         exerciseMapTabulation(data,
                               partitioningBy(classifier, reducing(0, Integer::sum)),
                               new PartitionAssertion<>(classifier,
-                                                       new ReduceAssertion<>(0, Function.identity(), Integer::sum)));
+                                                       new ReduceAssertion<>(0, LambdaTestHelpers.identity(), Integer::sum)));
     }
 }