Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/completable/CompletableOnErrorXTest.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.junit.Assert.assertEquals;
17
18 import java.io.IOException;
19
20 import org.junit.Test;
21
22 import io.reactivex.rxjava3.core.*;
23 import io.reactivex.rxjava3.exceptions.TestException;
24 import io.reactivex.rxjava3.functions.Function;
25 import io.reactivex.rxjava3.internal.functions.Functions;
26 import io.reactivex.rxjava3.subjects.CompletableSubject;
27 import io.reactivex.rxjava3.testsupport.TestHelper;
28
29 public class CompletableOnErrorXTest extends RxJavaTest {
30
31 @Test
32 public void normalReturn() {
33 Completable.complete()
34 .onErrorComplete()
35 .test()
36 .assertResult();
37 }
38
39 @Test
40 public void normalResumeNext() {
41 final int[] call = { 0 };
42 Completable.complete()
43 .onErrorResumeNext(new Function<Throwable, CompletableSource>() {
44 @Override
45 public CompletableSource apply(Throwable e) throws Exception {
46 call[0]++;
47 return Completable.complete();
48 }
49 })
50 .test()
51 .assertResult();
52
53 assertEquals(0, call[0]);
54 }
55
56 @Test
57 public void onErrorReturnConst() {
58 Completable.error(new TestException())
59 .onErrorReturnItem(1)
60 .test()
61 .assertResult(1);
62 }
63
64 @Test
65 public void onErrorReturn() {
66 Completable.error(new TestException())
67 .onErrorReturn(Functions.justFunction(1))
68 .test()
69 .assertResult(1);
70 }
71
72 @Test
73 public void onErrorReturnFunctionThrows() {
74 TestHelper.assertCompositeExceptions(Completable.error(new TestException())
75 .onErrorReturn(new Function<Throwable, Object>() {
76 @Override
77 public Object apply(Throwable v) throws Exception {
78 throw new IOException();
79 }
80 })
81 .to(TestHelper.testConsumer()), TestException.class, IOException.class);
82 }
83
84 @Test
85 public void onErrorReturnEmpty() {
86 Completable.complete()
87 .onErrorReturnItem(2)
88 .test()
89 .assertResult();
90 }
91
92 @Test
93 public void onErrorReturnDispose() {
94 TestHelper.checkDisposed(CompletableSubject.create().onErrorReturnItem(1));
95 }
96
97 @Test
98 public void onErrorReturnDoubleOnSubscribe() {
99 TestHelper.checkDoubleOnSubscribeCompletableToMaybe(new Function<Completable, MaybeSource<Object>>() {
100 @Override
101 public MaybeSource<Object> apply(Completable v) throws Exception {
102 return v.onErrorReturnItem(1);
103 }
104 });
105 }
106 }