|
| 1 | +/** |
| 2 | + * Copyright 2016 Netflix, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package rx.internal.operators; |
| 18 | + |
| 19 | +import static org.junit.Assert.*; |
| 20 | +import org.junit.Test; |
| 21 | + |
| 22 | +import rx.Completable; |
| 23 | +import rx.functions.Func1; |
| 24 | +import rx.observers.AssertableSubscriber; |
| 25 | +import rx.subjects.PublishSubject; |
| 26 | + |
| 27 | +public class CompletableOnErrorXTest { |
| 28 | + |
| 29 | + @Test |
| 30 | + public void nextUnsubscribe() { |
| 31 | + PublishSubject<Integer> ps = PublishSubject.create(); |
| 32 | + |
| 33 | + AssertableSubscriber<Void> as = ps.toCompletable() |
| 34 | + .onErrorResumeNext(new Func1<Throwable, Completable>() { |
| 35 | + @Override |
| 36 | + public Completable call(Throwable e) { |
| 37 | + return Completable.complete(); |
| 38 | + } |
| 39 | + }) |
| 40 | + .test(); |
| 41 | + |
| 42 | + assertTrue(ps.hasObservers()); |
| 43 | + |
| 44 | + as.unsubscribe(); |
| 45 | + |
| 46 | + assertFalse("Still subscribed!", ps.hasObservers()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void completeUnsubscribe() { |
| 51 | + PublishSubject<Integer> ps = PublishSubject.create(); |
| 52 | + |
| 53 | + AssertableSubscriber<Void> as = ps.toCompletable() |
| 54 | + .onErrorComplete() |
| 55 | + .test(); |
| 56 | + |
| 57 | + assertTrue(ps.hasObservers()); |
| 58 | + |
| 59 | + as.unsubscribe(); |
| 60 | + |
| 61 | + assertFalse("Still subscribed!", ps.hasObservers()); |
| 62 | + } |
| 63 | +} |
0 commit comments