Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/SubscribeWithTest.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;
15
16 import static org.junit.Assert.assertEquals;
17
18 import org.junit.Test;
19
20 import io.reactivex.rxjava3.core.*;
21 import io.reactivex.rxjava3.disposables.Disposable;
22 import io.reactivex.rxjava3.observers.TestObserver;
23 import io.reactivex.rxjava3.subscribers.TestSubscriber;
24
25 public class SubscribeWithTest extends RxJavaTest {
26
27 @Test
28 public void withFlowable() {
29 Flowable.range(1, 10)
30 .subscribeWith(new TestSubscriber<>())
31 .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
32 }
33
34 @Test
35 public void withObservable() {
36 Observable.range(1, 10)
37 .subscribeWith(new TestObserver<>())
38 .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
39 }
40
41 class ObserverImpl implements SingleObserver<Object>, CompletableObserver {
42 Object value;
43
44 @Override
45 public void onSubscribe(Disposable d) {
46
47 }
48
49 @Override
50 public void onComplete() {
51 this.value = 100;
52 }
53
54 @Override
55 public void onSuccess(Object value) {
56 this.value = value;
57 }
58
59 @Override
60 public void onError(Throwable e) {
61 this.value = e;
62 }
63 }
64
65 @Test
66 public void withSingle() {
67 assertEquals(1, Single.just(1).subscribeWith(new ObserverImpl()).value);
68 }
69
70 @Test
71 public void withCompletable() {
72 assertEquals(100, Completable.complete().subscribeWith(new ObserverImpl()).value);
73 }
74
75 }