| 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.rxjava3.internal.operators.maybe; |
| 15 |
|
| 16 |
import java.util.List; |
| 17 |
|
| 18 |
import org.junit.Test; |
| 19 |
|
| 20 |
import io.reactivex.rxjava3.core.*; |
| 21 |
import io.reactivex.rxjava3.exceptions.*; |
| 22 |
import io.reactivex.rxjava3.functions.Function; |
| 23 |
import io.reactivex.rxjava3.internal.functions.Functions; |
| 24 |
import io.reactivex.rxjava3.testsupport.*; |
| 25 |
|
| 26 |
public class MaybeFlatMapNotificationTest extends RxJavaTest { |
| 27 |
|
| 28 |
@Test |
| 29 |
public void dispose() { |
| 30 |
TestHelper.checkDisposed(Maybe.just(1) |
| 31 |
.flatMap(Functions.justFunction(Maybe.just(1)), |
| 32 |
Functions.justFunction(Maybe.just(1)), Functions.justSupplier(Maybe.just(1)))); |
| 33 |
} |
| 34 |
|
| 35 |
@Test |
| 36 |
public void doubleOnSubscribe() { |
| 37 |
TestHelper.checkDoubleOnSubscribeMaybe(new Function<Maybe<Integer>, MaybeSource<Integer>>() { |
| 38 |
@Override |
| 39 |
public MaybeSource<Integer> apply(Maybe<Integer> m) throws Exception { |
| 40 |
return m |
| 41 |
.flatMap(Functions.justFunction(Maybe.just(1)), |
| 42 |
Functions.justFunction(Maybe.just(1)), Functions.justSupplier(Maybe.just(1))); |
| 43 |
} |
| 44 |
}); |
| 45 |
} |
| 46 |
|
| 47 |
@Test |
| 48 |
public void onSuccessNull() { |
| 49 |
Maybe.just(1) |
| 50 |
.flatMap(Functions.justFunction((Maybe<Integer>)null), |
| 51 |
Functions.justFunction(Maybe.just(1)), |
| 52 |
Functions.justSupplier(Maybe.just(1))) |
| 53 |
.test() |
| 54 |
.assertFailure(NullPointerException.class); |
| 55 |
} |
| 56 |
|
| 57 |
@Test |
| 58 |
public void onErrorNull() { |
| 59 |
TestObserverEx<Integer> to = Maybe.<Integer>error(new TestException()) |
| 60 |
.flatMap(Functions.justFunction(Maybe.just(1)), |
| 61 |
Functions.justFunction((Maybe<Integer>)null), |
| 62 |
Functions.justSupplier(Maybe.just(1))) |
| 63 |
.to(TestHelper.<Integer>testConsumer()) |
| 64 |
.assertFailure(CompositeException.class); |
| 65 |
|
| 66 |
List<Throwable> ce = TestHelper.compositeList(to.errors().get(0)); |
| 67 |
|
| 68 |
TestHelper.assertError(ce, 0, TestException.class); |
| 69 |
TestHelper.assertError(ce, 1, NullPointerException.class); |
| 70 |
} |
| 71 |
|
| 72 |
@Test |
| 73 |
public void onCompleteNull() { |
| 74 |
Maybe.<Integer>empty() |
| 75 |
.flatMap(Functions.justFunction(Maybe.just(1)), |
| 76 |
Functions.justFunction(Maybe.just(1)), |
| 77 |
Functions.justSupplier((Maybe<Integer>)null)) |
| 78 |
.test() |
| 79 |
.assertFailure(NullPointerException.class); |
| 80 |
} |
| 81 |
|
| 82 |
@Test |
| 83 |
public void onSuccessEmpty() { |
| 84 |
Maybe.just(1) |
| 85 |
.flatMap(Functions.justFunction(Maybe.<Integer>empty()), |
| 86 |
Functions.justFunction(Maybe.just(1)), |
| 87 |
Functions.justSupplier(Maybe.just(1))) |
| 88 |
.test() |
| 89 |
.assertResult(); |
| 90 |
} |
| 91 |
|
| 92 |
@Test |
| 93 |
public void onSuccessError() { |
| 94 |
Maybe.just(1) |
| 95 |
.flatMap(Functions.justFunction(Maybe.<Integer>error(new TestException())), |
| 96 |
Functions.justFunction((Maybe<Integer>)null), |
| 97 |
Functions.justSupplier(Maybe.just(1))) |
| 98 |
.test() |
| 99 |
.assertFailure(TestException.class); |
| 100 |
} |
| 101 |
} |