diff --git a/src/share/classes/java/util/stream/AbstractPipeline.java b/src/share/classes/java/util/stream/AbstractPipeline.java index d3ccdacbf086f840294bb9f086e3f4507f05e83d..61ed7c89ae210492373f82c4fff0c3cd631b97f4 100644 --- a/src/share/classes/java/util/stream/AbstractPipeline.java +++ b/src/share/classes/java/util/stream/AbstractPipeline.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -327,6 +327,7 @@ abstract class AbstractPipeline> @Override @SuppressWarnings("unchecked") public S onClose(Runnable closeHandler) { + Objects.requireNonNull(closeHandler); Runnable existingHandler = sourceStage.sourceCloseAction; sourceStage.sourceCloseAction = (existingHandler == null) diff --git a/src/share/classes/java/util/stream/BaseStream.java b/src/share/classes/java/util/stream/BaseStream.java index 35d46e087279803994e42629250f5b21b2a80b4e..61e74867a19c581934618eacdaa6b67dbb164ce8 100644 --- a/src/share/classes/java/util/stream/BaseStream.java +++ b/src/share/classes/java/util/stream/BaseStream.java @@ -53,7 +53,7 @@ import java.util.function.Predicate; * parallelism, which governs the behavior of all stream types. * * @param the type of the stream elements - * @param the type of of the stream implementing {@code BaseStream} + * @param the type of the stream implementing {@code BaseStream} * @since 1.8 * @see Stream * @see IntStream diff --git a/src/share/classes/java/util/stream/DoublePipeline.java b/src/share/classes/java/util/stream/DoublePipeline.java index 3b6335b7760d063c252011d07373f945c0253e70..3e9cddbd324ee389e7950f06b8b6fc11efb087fd 100644 --- a/src/share/classes/java/util/stream/DoublePipeline.java +++ b/src/share/classes/java/util/stream/DoublePipeline.java @@ -254,6 +254,7 @@ abstract class DoublePipeline @Override public final DoubleStream flatMap(DoubleFunction mapper) { + Objects.requireNonNull(mapper); return new StatelessOp(this, StreamShape.DOUBLE_VALUE, StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) { @Override @@ -469,6 +470,7 @@ abstract class DoublePipeline public final R collect(Supplier supplier, ObjDoubleConsumer accumulator, BiConsumer combiner) { + Objects.requireNonNull(combiner); BinaryOperator operator = (left, right) -> { combiner.accept(left, right); return left; diff --git a/src/share/classes/java/util/stream/DoubleStream.java b/src/share/classes/java/util/stream/DoubleStream.java index 4d5d23d49ea3258afa188576d4fb3111b494ac84..cfc12ffde282eee71299ffff241e1b3566c683ad 100644 --- a/src/share/classes/java/util/stream/DoubleStream.java +++ b/src/share/classes/java/util/stream/DoubleStream.java @@ -768,7 +768,7 @@ public interface DoubleStream extends BaseStream { * to the element at position {@code n - 1}. * * @param seed the initial element - * @param f a function to be applied to to the previous element to produce + * @param f a function to be applied to the previous element to produce * a new element * @return a new sequential {@code DoubleStream} */ diff --git a/src/share/classes/java/util/stream/IntPipeline.java b/src/share/classes/java/util/stream/IntPipeline.java index 5c3a8f125d5ab21364d5d7f5576aa1c9681055ee..313045f96c70d04b6154eef53371ea557e6cf852 100644 --- a/src/share/classes/java/util/stream/IntPipeline.java +++ b/src/share/classes/java/util/stream/IntPipeline.java @@ -290,6 +290,7 @@ abstract class IntPipeline @Override public final IntStream flatMap(IntFunction mapper) { + Objects.requireNonNull(mapper); return new StatelessOp(this, StreamShape.INT_VALUE, StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) { @Override @@ -465,6 +466,7 @@ abstract class IntPipeline public final R collect(Supplier supplier, ObjIntConsumer accumulator, BiConsumer combiner) { + Objects.requireNonNull(combiner); BinaryOperator operator = (left, right) -> { combiner.accept(left, right); return left; diff --git a/src/share/classes/java/util/stream/IntStream.java b/src/share/classes/java/util/stream/IntStream.java index 94c2924fc6d13473e9a9c4a62fe6dd75cd5d03de..0a67d5a19dd74ff29be1e9a7ab7774a5e6871266 100644 --- a/src/share/classes/java/util/stream/IntStream.java +++ b/src/share/classes/java/util/stream/IntStream.java @@ -734,7 +734,7 @@ public interface IntStream extends BaseStream { * element at position {@code n - 1}. * * @param seed the initial element - * @param f a function to be applied to to the previous element to produce + * @param f a function to be applied to the previous element to produce * a new element * @return A new sequential {@code IntStream} */ diff --git a/src/share/classes/java/util/stream/LongPipeline.java b/src/share/classes/java/util/stream/LongPipeline.java index 88e919e717ccb41e70dbd1fecda48273c87b6ede..fab01a21118af3718fb1302d71d247788fde2d65 100644 --- a/src/share/classes/java/util/stream/LongPipeline.java +++ b/src/share/classes/java/util/stream/LongPipeline.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -271,6 +271,7 @@ abstract class LongPipeline @Override public final LongStream flatMap(LongFunction mapper) { + Objects.requireNonNull(mapper); return new StatelessOp(this, StreamShape.LONG_VALUE, StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) { @Override @@ -447,6 +448,7 @@ abstract class LongPipeline public final R collect(Supplier supplier, ObjLongConsumer accumulator, BiConsumer combiner) { + Objects.requireNonNull(combiner); BinaryOperator operator = (left, right) -> { combiner.accept(left, right); return left; diff --git a/src/share/classes/java/util/stream/LongStream.java b/src/share/classes/java/util/stream/LongStream.java index a2d429e5a1ca9c74ba4fc2ce452be7ee61150ee2..78901b2b1c2b7f57acae6e99278f224e3a5d897d 100644 --- a/src/share/classes/java/util/stream/LongStream.java +++ b/src/share/classes/java/util/stream/LongStream.java @@ -727,7 +727,7 @@ public interface LongStream extends BaseStream { * element at position {@code n - 1}. * * @param seed the initial element - * @param f a function to be applied to to the previous element to produce + * @param f a function to be applied to the previous element to produce * a new element * @return a new sequential {@code LongStream} */ diff --git a/src/share/classes/java/util/stream/PipelineHelper.java b/src/share/classes/java/util/stream/PipelineHelper.java index f510131d6ec83cd4a2ba122db7ad1218b2e36243..090469def006f2daf76b75537dc674b343c8873b 100644 --- a/src/share/classes/java/util/stream/PipelineHelper.java +++ b/src/share/classes/java/util/stream/PipelineHelper.java @@ -74,7 +74,7 @@ abstract class PipelineHelper { /** * Returns the exact output size of the portion of the output resulting from * applying the pipeline stages described by this {@code PipelineHelper} to - * the the portion of the input described by the provided + * the portion of the input described by the provided * {@code Spliterator}, if known. If not known or known infinite, will * return {@code -1}. * diff --git a/src/share/classes/java/util/stream/SliceOps.java b/src/share/classes/java/util/stream/SliceOps.java index 34d55309d2d7e93a0ba2d601ce983ca830b48d1a..bfe053fca2580d4b0d492ef0091219acbbcfe1cb 100644 --- a/src/share/classes/java/util/stream/SliceOps.java +++ b/src/share/classes/java/util/stream/SliceOps.java @@ -693,7 +693,7 @@ final class SliceOps { * size. * * @param target the target size - * @return return the number of completed elements + * @return the number of completed elements */ private long completedSize(long target) { if (completed) diff --git a/src/share/classes/java/util/stream/Stream.java b/src/share/classes/java/util/stream/Stream.java index c35fc056825a13edf6d07a8a8d8d2f9103d3701c..bd915796272bc9ded505058da0e4ad8b8edd19bd 100644 --- a/src/share/classes/java/util/stream/Stream.java +++ b/src/share/classes/java/util/stream/Stream.java @@ -1013,7 +1013,7 @@ public interface Stream extends BaseStream> { * * @param the type of stream elements * @param seed the initial element - * @param f a function to be applied to to the previous element to produce + * @param f a function to be applied to the previous element to produce * a new element * @return a new sequential {@code Stream} */ diff --git a/src/share/classes/java/util/stream/StreamOpFlag.java b/src/share/classes/java/util/stream/StreamOpFlag.java index 8fecfed4df46720c0234fc48acfb46404533bfb3..e4ad988eaf1f162524a52d8a809d2f8c553e358e 100644 --- a/src/share/classes/java/util/stream/StreamOpFlag.java +++ b/src/share/classes/java/util/stream/StreamOpFlag.java @@ -115,7 +115,7 @@ import java.util.Spliterator; * characteristics that stream has; when describing a stream operation, one need * describe whether the operation preserves, injects, or clears that * characteristic. Accordingly, two bits are used for each flag, so as to allow - * representing not only the presence of of a characteristic, but how an + * representing not only the presence of a characteristic, but how an * operation modifies that characteristic. There are two common forms in which * flag bits are combined into an {@code int} bit set. Stream flags * are a unioned bit set constructed by ORing the enum characteristic values of diff --git a/test/java/util/stream/bootlib/java/util/stream/ThowableHelper.java b/test/java/util/stream/bootlib/java/util/stream/ThowableHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..fc7807f6df0f1cbc7b89114e3d29b4bafdba55ab --- /dev/null +++ b/test/java/util/stream/bootlib/java/util/stream/ThowableHelper.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.stream; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +public final class ThowableHelper { + + public static void checkException(Class ce, Runnable r) { + Exception caught = null; + try { + r.run(); + } catch (Exception e) { + caught = e; + } + + assertNotNull(caught); + assertTrue(ce.isInstance(caught)); + } + + public static void checkNPE(Runnable r) { + checkException(NullPointerException.class, r); + } + + public static void checkISE(Runnable r) { + checkException(IllegalStateException.class, r); + } +} diff --git a/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CollectAndSummaryStatisticsTest.java b/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CollectAndSummaryStatisticsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..a869cdf41f3af27d02ee08c072ea70e9f12eb027 --- /dev/null +++ b/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CollectAndSummaryStatisticsTest.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @summary primtive stream collection with summary statistics + * @bug 8044047 + */ + +package org.openjdk.tests.java.util.stream; + +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.DoubleSummaryStatistics; +import java.util.IntSummaryStatistics; +import java.util.List; +import java.util.LongSummaryStatistics; +import java.util.stream.Collectors; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; +import java.util.stream.LongStream; +import java.util.stream.OpTestCase; + +import static java.util.stream.LambdaTestHelpers.countTo; +import static java.util.stream.ThowableHelper.checkNPE; + +@Test +public class CollectAndSummaryStatisticsTest extends OpTestCase { + + public void testIntCollectNull() { + checkNPE(() -> IntStream.of(1).collect(null, + IntSummaryStatistics::accept, + IntSummaryStatistics::combine)); + checkNPE(() -> IntStream.of(1).collect(IntSummaryStatistics::new, + null, + IntSummaryStatistics::combine)); + checkNPE(() -> IntStream.of(1).collect(IntSummaryStatistics::new, + IntSummaryStatistics::accept, + null)); + } + + public void testLongCollectNull() { + checkNPE(() -> LongStream.of(1).collect(null, + LongSummaryStatistics::accept, + LongSummaryStatistics::combine)); + checkNPE(() -> LongStream.of(1).collect(LongSummaryStatistics::new, + null, + LongSummaryStatistics::combine)); + checkNPE(() -> LongStream.of(1).collect(LongSummaryStatistics::new, + LongSummaryStatistics::accept, + null)); + } + + public void testDoubleCollectNull() { + checkNPE(() -> DoubleStream.of(1).collect(null, + DoubleSummaryStatistics::accept, + DoubleSummaryStatistics::combine)); + checkNPE(() -> DoubleStream.of(1).collect(DoubleSummaryStatistics::new, + null, + DoubleSummaryStatistics::combine)); + checkNPE(() -> DoubleStream.of(1).collect(DoubleSummaryStatistics::new, + DoubleSummaryStatistics::accept, + null)); + } + + public void testIntStatistics() { + List instances = new ArrayList<>(); + instances.add(countTo(1000).stream().collect(Collectors.summarizingInt(i -> i))); + instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics()); + instances.add(countTo(1000).stream().mapToInt(i -> i).collect(IntSummaryStatistics::new, + IntSummaryStatistics::accept, + IntSummaryStatistics::combine)); + instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingInt(i -> i))); + instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics()); + instances.add(countTo(1000).parallelStream().mapToInt(i -> i).collect(IntSummaryStatistics::new, + IntSummaryStatistics::accept, + IntSummaryStatistics::combine)); + + for (IntSummaryStatistics stats : instances) { + assertEquals(stats.getCount(), 1000); + assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum()); + assertEquals(stats.getAverage(), (double) stats.getSum() / stats.getCount()); + assertEquals(stats.getMax(), 1000); + assertEquals(stats.getMin(), 1); + } + } + + + public void testLongStatistics() { + List instances = new ArrayList<>(); + instances.add(countTo(1000).stream().collect(Collectors.summarizingLong(i -> i))); + instances.add(countTo(1000).stream().mapToLong(i -> i).summaryStatistics()); + instances.add(countTo(1000).stream().mapToLong(i -> i).collect(LongSummaryStatistics::new, + LongSummaryStatistics::accept, + LongSummaryStatistics::combine)); + instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingLong(i -> i))); + instances.add(countTo(1000).parallelStream().mapToLong(i -> i).summaryStatistics()); + instances.add(countTo(1000).parallelStream().mapToLong(i -> i).collect(LongSummaryStatistics::new, + LongSummaryStatistics::accept, + LongSummaryStatistics::combine)); + + for (LongSummaryStatistics stats : instances) { + assertEquals(stats.getCount(), 1000); + assertEquals(stats.getSum(), (long) countTo(1000).stream().mapToInt(i -> i).sum()); + assertEquals(stats.getAverage(), (double) stats.getSum() / stats.getCount()); + assertEquals(stats.getMax(), 1000L); + assertEquals(stats.getMin(), 1L); + } + } + + public void testDoubleStatistics() { + List instances = new ArrayList<>(); + instances.add(countTo(1000).stream().collect(Collectors.summarizingDouble(i -> i))); + instances.add(countTo(1000).stream().mapToDouble(i -> i).summaryStatistics()); + instances.add(countTo(1000).stream().mapToDouble(i -> i).collect(DoubleSummaryStatistics::new, + DoubleSummaryStatistics::accept, + DoubleSummaryStatistics::combine)); + instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingDouble(i -> i))); + instances.add(countTo(1000).parallelStream().mapToDouble(i -> i).summaryStatistics()); + instances.add(countTo(1000).parallelStream().mapToDouble(i -> i).collect(DoubleSummaryStatistics::new, + DoubleSummaryStatistics::accept, + DoubleSummaryStatistics::combine)); + + for (DoubleSummaryStatistics stats : instances) { + assertEquals(stats.getCount(), 1000); + assertEquals(stats.getSum(), (double) countTo(1000).stream().mapToInt(i -> i).sum()); + assertEquals(stats.getAverage(), stats.getSum() / stats.getCount()); + assertEquals(stats.getMax(), 1000.0); + assertEquals(stats.getMin(), 1.0); + } + } +} diff --git a/test/java/util/stream/test/org/openjdk/tests/java/util/stream/ExplodeOpTest.java b/test/java/util/stream/test/org/openjdk/tests/java/util/stream/FlatMapOpTest.java similarity index 90% rename from test/java/util/stream/test/org/openjdk/tests/java/util/stream/ExplodeOpTest.java rename to test/java/util/stream/test/org/openjdk/tests/java/util/stream/FlatMapOpTest.java index cbd9534aa6fce0030aa0ec119e237d44bf0f7fb0..787b6b8fe27f7b3aaabe77fb39d1d1590a4236d2 100644 --- a/test/java/util/stream/test/org/openjdk/tests/java/util/stream/ExplodeOpTest.java +++ b/test/java/util/stream/test/org/openjdk/tests/java/util/stream/FlatMapOpTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -20,6 +20,13 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ + +/* + * @test + * @summary flat-map operations + * @bug 8044047 + */ + package org.openjdk.tests.java.util.stream; import org.testng.annotations.Test; @@ -31,14 +38,17 @@ import java.util.function.Function; import java.util.stream.*; import static java.util.stream.LambdaTestHelpers.*; +import static java.util.stream.ThowableHelper.checkNPE; -/** - * ExplodeOpTest - * - * @author Brian Goetz - */ @Test -public class ExplodeOpTest extends OpTestCase { +public class FlatMapOpTest extends OpTestCase { + + public void testNullMapper() { + checkNPE(() -> Stream.of(1).flatMap(null)); + checkNPE(() -> IntStream.of(1).flatMap(null)); + checkNPE(() -> LongStream.of(1).flatMap(null)); + checkNPE(() -> DoubleStream.of(1).flatMap(null)); + } static final Function> integerRangeMapper = e -> IntStream.range(0, e).boxed(); diff --git a/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamBuilderTest.java b/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamBuilderTest.java index d8d46fd6368f06778a5a6ca6ae13b62488fe6e57..352f3cc7099878bd11834d75e300ee98ae5464fb 100644 --- a/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamBuilderTest.java +++ b/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamBuilderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -38,6 +38,7 @@ import java.util.stream.Stream; import java.util.stream.TestData; import static java.util.stream.Collectors.toList; +import static java.util.stream.ThowableHelper.checkISE; @Test public class StreamBuilderTest extends OpTestCase { @@ -52,23 +53,6 @@ public class StreamBuilderTest extends OpTestCase { return sizes.stream().map(i -> new Object[] { i }).toArray(Object[][]::new); } - private void checkException(Class ce, Runnable r) { - Exception caught = null; - try { - r.run(); - } catch (Exception e) { - caught = e; - } - - assertNotNull(caught); - assertTrue(ce.isInstance(caught)); - } - - private void checkISE(Runnable r) { - checkException(IllegalStateException.class, r); - } - - // @Test public void testSingleton() { diff --git a/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamCloseTest.java b/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamCloseTest.java index 51ffd4b9010d5d04eeb66541bda827a108ee2e5d..6fd24a9816abae3df4f5eabf410f53291e60b9d7 100644 --- a/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamCloseTest.java +++ b/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamCloseTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -20,6 +20,13 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ + +/* + * @test + * @summary close handlers and closing streams + * @bug 8044047 + */ + package org.openjdk.tests.java.util.stream; import java.util.Arrays; @@ -29,14 +36,14 @@ import java.util.stream.Stream; import org.testng.annotations.Test; import static java.util.stream.LambdaTestHelpers.countTo; +import static java.util.stream.ThowableHelper.checkNPE; -/** - * StreamCloseTest - * - * @author Brian Goetz - */ @Test(groups = { "serialization-hostile" }) public class StreamCloseTest extends OpTestCase { + public void testNullCloseHandler() { + checkNPE(() -> Stream.of(1).onClose(null)); + } + public void testEmptyCloseHandler() { try (Stream ints = countTo(100).stream()) { ints.forEach(i -> {}); diff --git a/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SummaryStatisticsTest.java b/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SummaryStatisticsTest.java deleted file mode 100644 index 3850b83880c90c0891074b9f4719dcc2ead71fe4..0000000000000000000000000000000000000000 --- a/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SummaryStatisticsTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package org.openjdk.tests.java.util.stream; - -import java.util.ArrayList; -import java.util.DoubleSummaryStatistics; -import java.util.IntSummaryStatistics; -import java.util.List; -import java.util.LongSummaryStatistics; -import java.util.stream.Collectors; -import java.util.stream.OpTestCase; - -import org.testng.annotations.Test; - -import static java.util.stream.LambdaTestHelpers.countTo; - -/** - * TestSummaryStatistics - * - * @author Brian Goetz - */ -@Test -public class SummaryStatisticsTest extends OpTestCase { - public void testIntStatistics() { - List instances = new ArrayList<>(); - instances.add(countTo(1000).stream().collect(Collectors.summarizingInt(i -> i))); - instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics()); - instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingInt(i -> i))); - instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics()); - - for (IntSummaryStatistics stats : instances) { - assertEquals(stats.getCount(), 1000); - assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum()); - assertEquals(stats.getMax(), 1000); - assertEquals(stats.getMin(), 1); - } - } - - public void testLongStatistics() { - List instances = new ArrayList<>(); - instances.add(countTo(1000).stream().collect(Collectors.summarizingLong(i -> i))); - instances.add(countTo(1000).stream().mapToLong(i -> i).summaryStatistics()); - instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingLong(i -> i))); - instances.add(countTo(1000).parallelStream().mapToLong(i -> i).summaryStatistics()); - - for (LongSummaryStatistics stats : instances) { - assertEquals(stats.getCount(), 1000); - assertEquals(stats.getSum(), (long) countTo(1000).stream().mapToInt(i -> i).sum()); - assertEquals(stats.getMax(), 1000L); - assertEquals(stats.getMin(), 1L); - } - } - - public void testDoubleStatistics() { - List instances = new ArrayList<>(); - instances.add(countTo(1000).stream().collect(Collectors.summarizingDouble(i -> i))); - instances.add(countTo(1000).stream().mapToDouble(i -> i).summaryStatistics()); - instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingDouble(i -> i))); - instances.add(countTo(1000).parallelStream().mapToDouble(i -> i).summaryStatistics()); - - for (DoubleSummaryStatistics stats : instances) { - assertEquals(stats.getCount(), 1000); - assertEquals(stats.getSum(), (double) countTo(1000).stream().mapToInt(i -> i).sum()); - assertEquals(stats.getMax(), 1000.0); - assertEquals(stats.getMin(), 1.0); - } - } -}