| 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.observers.TestObserver; |
| 23 |
import io.reactivex.rxjava3.subjects.*; |
| 24 |
import io.reactivex.rxjava3.testsupport.TestHelper; |
| 25 |
|
| 26 |
public class CompletableAndThenObservableTest extends RxJavaTest { |
| 27 |
|
| 28 |
@Test |
| 29 |
public void cancelMain() { |
| 30 |
CompletableSubject cs = CompletableSubject.create(); |
| 31 |
PublishSubject<Integer> ps = PublishSubject.create(); |
| 32 |
|
| 33 |
TestObserver<Integer> to = cs.andThen(ps) |
| 34 |
.test(); |
| 35 |
|
| 36 |
assertTrue(cs.hasObservers()); |
| 37 |
assertFalse(ps.hasObservers()); |
| 38 |
|
| 39 |
to.dispose(); |
| 40 |
|
| 41 |
assertFalse(cs.hasObservers()); |
| 42 |
assertFalse(ps.hasObservers()); |
| 43 |
} |
| 44 |
|
| 45 |
@Test |
| 46 |
public void cancelOther() { |
| 47 |
CompletableSubject cs = CompletableSubject.create(); |
| 48 |
PublishSubject<Integer> ps = PublishSubject.create(); |
| 49 |
|
| 50 |
TestObserver<Integer> to = cs.andThen(ps) |
| 51 |
.test(); |
| 52 |
|
| 53 |
assertTrue(cs.hasObservers()); |
| 54 |
assertFalse(ps.hasObservers()); |
| 55 |
|
| 56 |
cs.onComplete(); |
| 57 |
|
| 58 |
assertFalse(cs.hasObservers()); |
| 59 |
assertTrue(ps.hasObservers()); |
| 60 |
|
| 61 |
to.dispose(); |
| 62 |
|
| 63 |
assertFalse(cs.hasObservers()); |
| 64 |
assertFalse(ps.hasObservers()); |
| 65 |
} |
| 66 |
|
| 67 |
@Test |
| 68 |
public void errorMain() { |
| 69 |
CompletableSubject cs = CompletableSubject.create(); |
| 70 |
PublishSubject<Integer> ps = PublishSubject.create(); |
| 71 |
|
| 72 |
TestObserver<Integer> to = cs.andThen(ps) |
| 73 |
.test(); |
| 74 |
|
| 75 |
assertTrue(cs.hasObservers()); |
| 76 |
assertFalse(ps.hasObservers()); |
| 77 |
|
| 78 |
cs.onError(new TestException()); |
| 79 |
|
| 80 |
assertFalse(cs.hasObservers()); |
| 81 |
assertFalse(ps.hasObservers()); |
| 82 |
|
| 83 |
to.assertFailure(TestException.class); |
| 84 |
} |
| 85 |
|
| 86 |
@Test |
| 87 |
public void errorOther() { |
| 88 |
CompletableSubject cs = CompletableSubject.create(); |
| 89 |
PublishSubject<Integer> ps = PublishSubject.create(); |
| 90 |
|
| 91 |
TestObserver<Integer> to = cs.andThen(ps) |
| 92 |
.test(); |
| 93 |
|
| 94 |
assertTrue(cs.hasObservers()); |
| 95 |
assertFalse(ps.hasObservers()); |
| 96 |
|
| 97 |
cs.onComplete(); |
| 98 |
|
| 99 |
assertFalse(cs.hasObservers()); |
| 100 |
assertTrue(ps.hasObservers()); |
| 101 |
|
| 102 |
ps.onError(new TestException()); |
| 103 |
|
| 104 |
assertFalse(cs.hasObservers()); |
| 105 |
assertFalse(ps.hasObservers()); |
| 106 |
|
| 107 |
to.assertFailure(TestException.class); |
| 108 |
} |
| 109 |
|
| 110 |
@Test |
| 111 |
public void isDisposed() { |
| 112 |
TestHelper.checkDisposed(Completable.never().andThen(Observable.never())); |
| 113 |
} |
| 114 |
|
| 115 |
} |