diff options
author | cpovirk <cpovirk@google.com> | 2023-11-27 11:24:46 -0800 |
---|---|---|
committer | Google Java Core Libraries <jake-team+copybara@google.com> | 2023-11-27 11:28:32 -0800 |
commit | c4477c0a0e3c22a78c7757739b6a9cdd63a00500 (patch) | |
tree | 7f82e3d0de4e506e7b787781a50e16d290b69550 | |
parent | e6f062cf1ba73fa8cf61c74f6269a4a96a12ebbe (diff) | |
download | guava-c4477c0a0e3c22a78c7757739b6a9cdd63a00500.tar.gz |
Reenable some tests externally.
The GWT bug that caused trouble for them was fixed long ago.
PiperOrigin-RevId: 585709530
-rw-r--r-- | guava-tests/test/com/google/common/collect/StreamsTest.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/guava-tests/test/com/google/common/collect/StreamsTest.java b/guava-tests/test/com/google/common/collect/StreamsTest.java index 94c24003e..2da73a974 100644 --- a/guava-tests/test/com/google/common/collect/StreamsTest.java +++ b/guava-tests/test/com/google/common/collect/StreamsTest.java @@ -14,6 +14,7 @@ package com.google.common.collect; +import static com.google.common.collect.Streams.findLast; import static com.google.common.collect.Streams.stream; import com.google.common.annotations.GwtCompatible; @@ -22,16 +23,19 @@ import com.google.common.collect.testing.SpliteratorTester; import com.google.common.primitives.Doubles; import com.google.common.truth.IterableSubject; import com.google.common.truth.Truth; +import com.google.common.truth.Truth8; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.OptionalDouble; import java.util.OptionalInt; import java.util.OptionalLong; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; +import java.util.stream.Collectors; import java.util.stream.DoubleStream; import java.util.stream.IntStream; import java.util.stream.LongStream; @@ -75,6 +79,62 @@ public class StreamsTest extends TestCase { assertThat(stream(java.util.Optional.of("a"))).containsExactly("a"); } + public void testFindLast_refStream() { + Truth8.assertThat(findLast(Stream.of())).isEmpty(); + Truth8.assertThat(findLast(Stream.of("a", "b", "c", "d"))).hasValue("d"); + + // test with a large, not-subsized Spliterator + List<Integer> list = + IntStream.rangeClosed(0, 10000).boxed().collect(Collectors.toCollection(LinkedList::new)); + Truth8.assertThat(findLast(list.stream())).hasValue(10000); + + // no way to find out the stream is empty without walking its spliterator + Truth8.assertThat(findLast(list.stream().filter(i -> i < 0))).isEmpty(); + } + + public void testFindLast_intStream() { + Truth.assertThat(findLast(IntStream.of())).isEqualTo(OptionalInt.empty()); + Truth.assertThat(findLast(IntStream.of(1, 2, 3, 4, 5))).isEqualTo(OptionalInt.of(5)); + + // test with a large, not-subsized Spliterator + List<Integer> list = + IntStream.rangeClosed(0, 10000).boxed().collect(Collectors.toCollection(LinkedList::new)); + Truth.assertThat(findLast(list.stream().mapToInt(i -> i))).isEqualTo(OptionalInt.of(10000)); + + // no way to find out the stream is empty without walking its spliterator + Truth.assertThat(findLast(list.stream().mapToInt(i -> i).filter(i -> i < 0))) + .isEqualTo(OptionalInt.empty()); + } + + public void testFindLast_longStream() { + Truth.assertThat(findLast(LongStream.of())).isEqualTo(OptionalLong.empty()); + Truth.assertThat(findLast(LongStream.of(1, 2, 3, 4, 5))).isEqualTo(OptionalLong.of(5)); + + // test with a large, not-subsized Spliterator + List<Long> list = + LongStream.rangeClosed(0, 10000).boxed().collect(Collectors.toCollection(LinkedList::new)); + Truth.assertThat(findLast(list.stream().mapToLong(i -> i))).isEqualTo(OptionalLong.of(10000)); + + // no way to find out the stream is empty without walking its spliterator + Truth.assertThat(findLast(list.stream().mapToLong(i -> i).filter(i -> i < 0))) + .isEqualTo(OptionalLong.empty()); + } + + public void testFindLast_doubleStream() { + Truth.assertThat(findLast(DoubleStream.of())).isEqualTo(OptionalDouble.empty()); + Truth.assertThat(findLast(DoubleStream.of(1, 2, 3, 4, 5))).isEqualTo(OptionalDouble.of(5)); + + // test with a large, not-subsized Spliterator + List<Long> list = + LongStream.rangeClosed(0, 10000).boxed().collect(Collectors.toCollection(LinkedList::new)); + Truth.assertThat(findLast(list.stream().mapToDouble(i -> i))) + .isEqualTo(OptionalDouble.of(10000)); + + // no way to find out the stream is empty without walking its spliterator + Truth.assertThat(findLast(list.stream().mapToDouble(i -> i).filter(i -> i < 0))) + .isEqualTo(OptionalDouble.empty()); + } + public void testConcat_refStream() { assertThat(Streams.concat(Stream.of("a"), Stream.of("b"), Stream.empty(), Stream.of("c", "d"))) .containsExactly("a", "b", "c", "d") |