|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-present, RxJava Contributors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 | + * compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 | + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 | + * the License for the specific language governing permissions and limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +package io.reactivex.rxjava4.internal.operators.streamable; |
| 15 | + |
| 16 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 17 | + |
| 18 | +import java.util.*; |
| 19 | +import java.util.concurrent.TimeUnit; |
| 20 | + |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +import io.reactivex.rxjava4.core.Streamable; |
| 24 | +import io.reactivex.rxjava4.exceptions.TestException; |
| 25 | + |
| 26 | +public class StreamableCollectIntoTest extends StreamableBaseTest { |
| 27 | + |
| 28 | + @Test |
| 29 | + public void multipleItems() throws Throwable { |
| 30 | + Streamable.range(1, 5) |
| 31 | + .collectInto(new ArrayList<Integer>(), (list, item) -> list.add(item)) |
| 32 | + .test() |
| 33 | + .awaitDone(5, TimeUnit.SECONDS) |
| 34 | + .assertResult(new ArrayList<>(List.of(1, 2, 3, 4, 5))); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void empty() throws Throwable { |
| 39 | + Streamable.<Integer>empty() |
| 40 | + .collectInto(new ArrayList<Integer>(), (list, item) -> list.add(item)) |
| 41 | + .test() |
| 42 | + .awaitDone(5, TimeUnit.SECONDS) |
| 43 | + .assertResult(new ArrayList<Integer>()); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void error() throws Throwable { |
| 48 | + Streamable.<Integer>error(new TestException("error")) |
| 49 | + .collectInto(new ArrayList<Integer>(), (list, item) -> list.add(item)) |
| 50 | + .test() |
| 51 | + .awaitDone(5, TimeUnit.SECONDS) |
| 52 | + .assertFailure(TestException.class); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void nullArguments() { |
| 57 | + assertThrows(NullPointerException.class, () -> Streamable.<Integer>empty().collectInto((ArrayList<Integer>) null, (list, item) -> list.add(item))); |
| 58 | + assertThrows(NullPointerException.class, () -> Streamable.empty().collectInto(new ArrayList<Integer>(), null)); |
| 59 | + } |
| 60 | +} |
0 commit comments