Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/single/SingleMapTest.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 org.junit.Test;
17
18 import io.reactivex.rxjava3.core.*;
19 import io.reactivex.rxjava3.functions.Function;
20 import io.reactivex.rxjava3.testsupport.TestHelper;
21
22 public class SingleMapTest extends RxJavaTest {
23
24 @Test
25 public void mapValue() {
26 Single.just(1).map(new Function<Integer, Integer>() {
27 @Override
28 public Integer apply(final Integer integer) throws Exception {
29 if (integer == 1) {
30 return 2;
31 }
32
33 return 1;
34 }
35 })
36 .test()
37 .assertResult(2);
38 }
39
40 @Test
41 public void mapValueNull() {
42 Single.just(1).map(new Function<Integer, SingleSource<Integer>>() {
43 @Override
44 public SingleSource<Integer> apply(final Integer integer) throws Exception {
45 return null;
46 }
47 })
48 .to(TestHelper.<SingleSource<Integer>>testConsumer())
49 .assertNoValues()
50 .assertError(NullPointerException.class)
51 .assertErrorMessage("The mapper function returned a null value.");
52 }
53
54 @Test
55 public void mapValueErrorThrown() {
56 Single.just(1).map(new Function<Integer, SingleSource<Integer>>() {
57 @Override
58 public SingleSource<Integer> apply(final Integer integer) throws Exception {
59 throw new RuntimeException("something went terribly wrong!");
60 }
61 })
62 .to(TestHelper.<SingleSource<Integer>>testConsumer())
63 .assertNoValues()
64 .assertError(RuntimeException.class)
65 .assertErrorMessage("something went terribly wrong!");
66 }
67
68 @Test
69 public void mapError() {
70 RuntimeException exception = new RuntimeException("test");
71
72 Single.error(exception).map(new Function<Object, Object>() {
73 @Override
74 public Object apply(final Object integer) throws Exception {
75 return new Object();
76 }
77 })
78 .test()
79 .assertError(exception);
80 }
81 }