| 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.mixed; |
| 15 |
|
| 16 |
import static org.junit.Assert.*; |
| 17 |
|
| 18 |
import org.junit.Test; |
| 19 |
|
| 20 |
import io.reactivex.rxjava3.core.*; |
| 21 |
import io.reactivex.rxjava3.exceptions.TestException; |
| 22 |
import io.reactivex.rxjava3.functions.Function; |
| 23 |
import io.reactivex.rxjava3.internal.functions.Functions; |
| 24 |
import io.reactivex.rxjava3.observers.TestObserver; |
| 25 |
import io.reactivex.rxjava3.subjects.*; |
| 26 |
import io.reactivex.rxjava3.testsupport.TestHelper; |
| 27 |
|
| 28 |
public class MaybeFlatMapObservableTest extends RxJavaTest { |
| 29 |
|
| 30 |
@Test |
| 31 |
public void cancelMain() { |
| 32 |
MaybeSubject<Integer> ms = MaybeSubject.create(); |
| 33 |
PublishSubject<Integer> ps = PublishSubject.create(); |
| 34 |
|
| 35 |
TestObserver<Integer> to = ms.flatMapObservable(Functions.justFunction(ps)) |
| 36 |
.test(); |
| 37 |
|
| 38 |
assertTrue(ms.hasObservers()); |
| 39 |
assertFalse(ps.hasObservers()); |
| 40 |
|
| 41 |
to.dispose(); |
| 42 |
|
| 43 |
assertFalse(ms.hasObservers()); |
| 44 |
assertFalse(ps.hasObservers()); |
| 45 |
} |
| 46 |
|
| 47 |
@Test |
| 48 |
public void cancelOther() { |
| 49 |
MaybeSubject<Integer> ms = MaybeSubject.create(); |
| 50 |
PublishSubject<Integer> ps = PublishSubject.create(); |
| 51 |
|
| 52 |
TestObserver<Integer> to = ms.flatMapObservable(Functions.justFunction(ps)) |
| 53 |
.test(); |
| 54 |
|
| 55 |
assertTrue(ms.hasObservers()); |
| 56 |
assertFalse(ps.hasObservers()); |
| 57 |
|
| 58 |
ms.onSuccess(1); |
| 59 |
|
| 60 |
assertFalse(ms.hasObservers()); |
| 61 |
assertTrue(ps.hasObservers()); |
| 62 |
|
| 63 |
to.dispose(); |
| 64 |
|
| 65 |
assertFalse(ms.hasObservers()); |
| 66 |
assertFalse(ps.hasObservers()); |
| 67 |
} |
| 68 |
|
| 69 |
@Test |
| 70 |
public void mapperCrash() { |
| 71 |
Maybe.just(1).flatMapObservable(new Function<Integer, ObservableSource<? extends Object>>() { |
| 72 |
@Override |
| 73 |
public ObservableSource<? extends Object> apply(Integer v) throws Exception { |
| 74 |
throw new TestException(); |
| 75 |
} |
| 76 |
}) |
| 77 |
.test() |
| 78 |
.assertFailure(TestException.class); |
| 79 |
} |
| 80 |
|
| 81 |
@Test |
| 82 |
public void isDisposed() { |
| 83 |
TestHelper.checkDisposed(Maybe.never().flatMapObservable(Functions.justFunction(Observable.never()))); |
| 84 |
} |
| 85 |
} |