Repository navigation
Expand file tree
/
Copy pathFlowableDematerializeTest.java
More file actions
134 lines (98 loc) · 4.53 KB
/
Copy pathFlowableDematerializeTest.java
File metadata and controls
134 lines (98 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* Copyright 2016 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/
package io.reactivex.internal.operators.flowable;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
import org.junit.Test;
import org.reactivestreams.Subscriber;
import io.reactivex.*;
import io.reactivex.exceptions.TestException;
import io.reactivex.subscribers.TestSubscriber;
public class FlowableDematerializeTest {
@Test
public void testDematerialize1() {
Flowable<Notification<Integer>> notifications = Flowable.just(1, 2).materialize();
Flowable<Integer> dematerialize = notifications.dematerialize();
Subscriber<Integer> observer = TestHelper.mockSubscriber();
dematerialize.subscribe(observer);
verify(observer, times(1)).onNext(1);
verify(observer, times(1)).onNext(2);
verify(observer, times(1)).onComplete();
verify(observer, never()).onError(any(Throwable.class));
}
@Test
public void testDematerialize2() {
Throwable exception = new Throwable("test");
Flowable<Integer> observable = Flowable.error(exception);
Flowable<Integer> dematerialize = observable.materialize().dematerialize();
Subscriber<Integer> observer = TestHelper.mockSubscriber();
dematerialize.subscribe(observer);
verify(observer, times(1)).onError(exception);
verify(observer, times(0)).onComplete();
verify(observer, times(0)).onNext(any(Integer.class));
}
@Test
public void testDematerialize3() {
Exception exception = new Exception("test");
Flowable<Integer> observable = Flowable.error(exception);
Flowable<Integer> dematerialize = observable.materialize().dematerialize();
Subscriber<Integer> observer = TestHelper.mockSubscriber();
dematerialize.subscribe(observer);
verify(observer, times(1)).onError(exception);
verify(observer, times(0)).onComplete();
verify(observer, times(0)).onNext(any(Integer.class));
}
@Test
public void testErrorPassThru() {
Exception exception = new Exception("test");
Flowable<Integer> observable = Flowable.error(exception);
Flowable<Integer> dematerialize = observable.dematerialize();
Subscriber<Integer> observer = TestHelper.mockSubscriber();
dematerialize.subscribe(observer);
verify(observer, times(1)).onError(exception);
verify(observer, times(0)).onComplete();
verify(observer, times(0)).onNext(any(Integer.class));
}
@Test
public void testCompletePassThru() {
Flowable<Integer> observable = Flowable.empty();
Flowable<Integer> dematerialize = observable.dematerialize();
Subscriber<Integer> observer = TestHelper.mockSubscriber();
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(observer);
dematerialize.subscribe(ts);
System.out.println(ts.errors());
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
verify(observer, times(0)).onNext(any(Integer.class));
}
@Test
public void testHonorsContractWhenCompleted() {
Flowable<Integer> source = Flowable.just(1);
Flowable<Integer> result = source.materialize().dematerialize();
Subscriber<Integer> o = TestHelper.mockSubscriber();
result.subscribe(o);
verify(o).onNext(1);
verify(o).onComplete();
verify(o, never()).onError(any(Throwable.class));
}
@Test
public void testHonorsContractWhenThrows() {
Flowable<Integer> source = Flowable.error(new TestException());
Flowable<Integer> result = source.materialize().dematerialize();
Subscriber<Integer> o = TestHelper.mockSubscriber();
result.subscribe(o);
verify(o, never()).onNext(any(Integer.class));
verify(o, never()).onComplete();
verify(o).onError(any(TestException.class));
}
}