| 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.flowable; |
| 15 |
|
| 16 |
import static org.mockito.ArgumentMatchers.any; |
| 17 |
import static org.mockito.Mockito.*; |
| 18 |
|
| 19 |
import org.junit.*; |
| 20 |
import org.reactivestreams.Subscriber; |
| 21 |
|
| 22 |
import io.reactivex.rxjava3.core.*; |
| 23 |
import io.reactivex.rxjava3.functions.Function; |
| 24 |
import io.reactivex.rxjava3.processors.PublishProcessor; |
| 25 |
import io.reactivex.rxjava3.testsupport.TestHelper; |
| 26 |
|
| 27 |
public class FlowableSkipUntilTest extends RxJavaTest { |
| 28 |
Subscriber<Object> subscriber; |
| 29 |
|
| 30 |
@Before |
| 31 |
public void before() { |
| 32 |
subscriber = TestHelper.mockSubscriber(); |
| 33 |
} |
| 34 |
|
| 35 |
@Test |
| 36 |
public void normal1() { |
| 37 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 38 |
PublishProcessor<Integer> other = PublishProcessor.create(); |
| 39 |
|
| 40 |
Flowable<Integer> m = source.skipUntil(other); |
| 41 |
m.subscribe(subscriber); |
| 42 |
|
| 43 |
source.onNext(0); |
| 44 |
source.onNext(1); |
| 45 |
|
| 46 |
other.onNext(100); |
| 47 |
|
| 48 |
source.onNext(2); |
| 49 |
source.onNext(3); |
| 50 |
source.onNext(4); |
| 51 |
source.onComplete(); |
| 52 |
|
| 53 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 54 |
verify(subscriber, times(1)).onNext(2); |
| 55 |
verify(subscriber, times(1)).onNext(3); |
| 56 |
verify(subscriber, times(1)).onNext(4); |
| 57 |
verify(subscriber, times(1)).onComplete(); |
| 58 |
} |
| 59 |
|
| 60 |
@Test |
| 61 |
public void otherNeverFires() { |
| 62 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 63 |
|
| 64 |
Flowable<Integer> m = source.skipUntil(Flowable.never()); |
| 65 |
|
| 66 |
m.subscribe(subscriber); |
| 67 |
|
| 68 |
source.onNext(0); |
| 69 |
source.onNext(1); |
| 70 |
source.onNext(2); |
| 71 |
source.onNext(3); |
| 72 |
source.onNext(4); |
| 73 |
source.onComplete(); |
| 74 |
|
| 75 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 76 |
verify(subscriber, never()).onNext(any()); |
| 77 |
verify(subscriber, times(1)).onComplete(); |
| 78 |
} |
| 79 |
|
| 80 |
@Test |
| 81 |
public void otherEmpty() { |
| 82 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 83 |
|
| 84 |
Flowable<Integer> m = source.skipUntil(Flowable.empty()); |
| 85 |
|
| 86 |
m.subscribe(subscriber); |
| 87 |
|
| 88 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 89 |
verify(subscriber, never()).onNext(any()); |
| 90 |
verify(subscriber, never()).onComplete(); |
| 91 |
} |
| 92 |
|
| 93 |
@Test |
| 94 |
public void otherFiresAndCompletes() { |
| 95 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 96 |
PublishProcessor<Integer> other = PublishProcessor.create(); |
| 97 |
|
| 98 |
Flowable<Integer> m = source.skipUntil(other); |
| 99 |
m.subscribe(subscriber); |
| 100 |
|
| 101 |
source.onNext(0); |
| 102 |
source.onNext(1); |
| 103 |
|
| 104 |
other.onNext(100); |
| 105 |
other.onComplete(); |
| 106 |
|
| 107 |
source.onNext(2); |
| 108 |
source.onNext(3); |
| 109 |
source.onNext(4); |
| 110 |
source.onComplete(); |
| 111 |
|
| 112 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 113 |
verify(subscriber, times(1)).onNext(2); |
| 114 |
verify(subscriber, times(1)).onNext(3); |
| 115 |
verify(subscriber, times(1)).onNext(4); |
| 116 |
verify(subscriber, times(1)).onComplete(); |
| 117 |
} |
| 118 |
|
| 119 |
@Test |
| 120 |
public void sourceThrows() { |
| 121 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 122 |
PublishProcessor<Integer> other = PublishProcessor.create(); |
| 123 |
|
| 124 |
Flowable<Integer> m = source.skipUntil(other); |
| 125 |
m.subscribe(subscriber); |
| 126 |
|
| 127 |
source.onNext(0); |
| 128 |
source.onNext(1); |
| 129 |
|
| 130 |
other.onNext(100); |
| 131 |
other.onComplete(); |
| 132 |
|
| 133 |
source.onNext(2); |
| 134 |
source.onError(new RuntimeException("Forced failure")); |
| 135 |
|
| 136 |
verify(subscriber, times(1)).onNext(2); |
| 137 |
verify(subscriber, times(1)).onError(any(Throwable.class)); |
| 138 |
verify(subscriber, never()).onComplete(); |
| 139 |
} |
| 140 |
|
| 141 |
@Test |
| 142 |
public void otherThrowsImmediately() { |
| 143 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 144 |
PublishProcessor<Integer> other = PublishProcessor.create(); |
| 145 |
|
| 146 |
Flowable<Integer> m = source.skipUntil(other); |
| 147 |
m.subscribe(subscriber); |
| 148 |
|
| 149 |
source.onNext(0); |
| 150 |
source.onNext(1); |
| 151 |
|
| 152 |
other.onError(new RuntimeException("Forced failure")); |
| 153 |
|
| 154 |
verify(subscriber, never()).onNext(any()); |
| 155 |
verify(subscriber, times(1)).onError(any(Throwable.class)); |
| 156 |
verify(subscriber, never()).onComplete(); |
| 157 |
} |
| 158 |
|
| 159 |
@Test |
| 160 |
public void dispose() { |
| 161 |
TestHelper.checkDisposed(PublishProcessor.create().skipUntil(PublishProcessor.create())); |
| 162 |
} |
| 163 |
|
| 164 |
@Test |
| 165 |
public void doubleOnSubscribe() { |
| 166 |
TestHelper.checkDoubleOnSubscribeFlowable(new Function<Flowable<Object>, Flowable<Object>>() { |
| 167 |
@Override |
| 168 |
public Flowable<Object> apply(Flowable<Object> f) throws Exception { |
| 169 |
return f.skipUntil(Flowable.never()); |
| 170 |
} |
| 171 |
}); |
| 172 |
|
| 173 |
TestHelper.checkDoubleOnSubscribeFlowable(new Function<Flowable<Object>, Flowable<Object>>() { |
| 174 |
@Override |
| 175 |
public Flowable<Object> apply(Flowable<Object> f) throws Exception { |
| 176 |
return Flowable.never().skipUntil(f); |
| 177 |
} |
| 178 |
}); |
| 179 |
} |
| 180 |
} |