Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/single/SingleOnErrorXTest.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.single;
15
16 import java.util.List;
17
18 import org.junit.Test;
19
20 import io.reactivex.rxjava3.core.*;
21 import io.reactivex.rxjava3.exceptions.*;
22 import io.reactivex.rxjava3.functions.Function;
23 import io.reactivex.rxjava3.testsupport.*;
24
25 public class SingleOnErrorXTest extends RxJavaTest {
26
27 @Test
28 public void returnSuccess() {
29 Single.just(1)
30 .onErrorReturnItem(2)
31 .test()
32 .assertResult(1);
33 }
34
35 @Test
36 public void resumeThrows() {
37 TestObserverEx<Integer> to = Single.<Integer>error(new TestException("Outer"))
38 .onErrorReturn(new Function<Throwable, Integer>() {
39 @Override
40 public Integer apply(Throwable e) throws Exception {
41 throw new TestException("Inner");
42 }
43 })
44 .to(TestHelper.<Integer>testConsumer())
45 .assertFailure(CompositeException.class);
46
47 List<Throwable> errors = TestHelper.compositeList(to.errors().get(0));
48
49 TestHelper.assertError(errors, 0, TestException.class, "Outer");
50 TestHelper.assertError(errors, 1, TestException.class, "Inner");
51 }
52
53 @Test
54 public void resumeErrors() {
55 Single.error(new TestException("Main"))
56 .onErrorResumeWith(Single.error(new TestException("Resume")))
57 .to(TestHelper.<Object>testConsumer())
58 .assertFailureAndMessage(TestException.class, "Resume");
59 }
60
61 @Test
62 public void resumeDispose() {
63 TestHelper.checkDisposed(Single.error(new TestException("Main"))
64 .onErrorResumeWith(Single.just(1)));
65 }
66
67 @Test
68 public void resumeDoubleOnSubscribe() {
69 TestHelper.checkDoubleOnSubscribeSingle(new Function<Single<Object>, SingleSource<Object>>() {
70 @Override
71 public SingleSource<Object> apply(Single<Object> s) throws Exception {
72 return s.onErrorResumeWith(Single.just(1));
73 }
74 });
75 }
76
77 @Test
78 public void resumeSuccess() {
79 Single.just(1)
80 .onErrorResumeWith(Single.just(2))
81 .test()
82 .assertResult(1);
83 }
84 }