Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/completable/CompletableResumeNextTest.java

raw
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.completable;
15
16 import static org.mockito.Mockito.*;
17 import org.junit.Test;
18
19 import io.reactivex.rxjava3.core.*;
20 import io.reactivex.rxjava3.exceptions.TestException;
21 import io.reactivex.rxjava3.functions.*;
22 import io.reactivex.rxjava3.internal.functions.Functions;
23 import io.reactivex.rxjava3.testsupport.TestHelper;
24
25 public class CompletableResumeNextTest extends RxJavaTest {
26
27 @Test
28 public void resumeNextError() {
29 Completable.error(new TestException())
30 .onErrorResumeNext(Functions.justFunction(Completable.error(new TestException("second"))))
31 .to(TestHelper.<Object>testConsumer())
32 .assertFailureAndMessage(TestException.class, "second");
33 }
34
35 @Test
36 public void disposeInMain() {
37 TestHelper.checkDisposedCompletable(new Function<Completable, CompletableSource>() {
38 @Override
39 public CompletableSource apply(Completable c) throws Exception {
40 return c.onErrorResumeNext(Functions.justFunction(Completable.complete()));
41 }
42 });
43 }
44
45 @Test
46 public void disposeInResume() {
47 TestHelper.checkDisposedCompletable(new Function<Completable, CompletableSource>() {
48 @Override
49 public CompletableSource apply(Completable c) throws Exception {
50 return Completable.error(new TestException()).onErrorResumeNext(Functions.justFunction(c));
51 }
52 });
53 }
54
55 @Test
56 public void disposed() {
57 TestHelper.checkDisposed(
58 Completable.error(new TestException())
59 .onErrorResumeNext(Functions.justFunction(Completable.never()))
60 );
61 }
62
63 @Test
64 public void resumeWithNoError() throws Throwable {
65 Action action = mock(Action.class);
66
67 Completable.complete()
68 .onErrorResumeWith(Completable.fromAction(action))
69 .test()
70 .assertResult();
71
72 verify(action, never()).run();
73 }
74
75 @Test
76 public void resumeWithError() throws Throwable {
77 Action action = mock(Action.class);
78
79 Completable.error(new TestException())
80 .onErrorResumeWith(Completable.fromAction(action))
81 .test()
82 .assertResult();
83
84 verify(action).run();
85 }
86 }