| 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.subscribers; |
| 15 |
|
| 16 |
import static org.junit.Assert.*; |
| 17 |
|
| 18 |
import org.junit.Test; |
| 19 |
|
| 20 |
import io.reactivex.rxjava3.annotations.*; |
| 21 |
import io.reactivex.rxjava3.core.RxJavaTest; |
| 22 |
import io.reactivex.rxjava3.internal.subscriptions.*; |
| 23 |
import io.reactivex.rxjava3.subscribers.TestSubscriber; |
| 24 |
import io.reactivex.rxjava3.testsupport.TestHelper; |
| 25 |
|
| 26 |
public class BasicFuseableSubscriberTest extends RxJavaTest { |
| 27 |
|
| 28 |
@Test |
| 29 |
public void offerThrows() { |
| 30 |
BasicFuseableSubscriber<Integer, Integer> fcs = new BasicFuseableSubscriber<Integer, Integer>(new TestSubscriber<>(0L)) { |
| 31 |
|
| 32 |
@Override |
| 33 |
public void onNext(Integer t) { |
| 34 |
} |
| 35 |
|
| 36 |
@Override |
| 37 |
public int requestFusion(int mode) { |
| 38 |
return 0; |
| 39 |
} |
| 40 |
|
| 41 |
@Nullable |
| 42 |
@Override |
| 43 |
public Integer poll() throws Exception { |
| 44 |
return null; |
| 45 |
} |
| 46 |
}; |
| 47 |
|
| 48 |
fcs.onSubscribe(new ScalarSubscription<>(fcs, 1)); |
| 49 |
|
| 50 |
TestHelper.assertNoOffer(fcs); |
| 51 |
|
| 52 |
assertFalse(fcs.isEmpty()); |
| 53 |
fcs.clear(); |
| 54 |
assertTrue(fcs.isEmpty()); |
| 55 |
} |
| 56 |
|
| 57 |
@Test |
| 58 |
public void implementationStopsOnSubscribe() { |
| 59 |
TestSubscriber<Integer> ts = new TestSubscriber<>(); |
| 60 |
BasicFuseableSubscriber<Integer, Integer> bfs = new BasicFuseableSubscriber<Integer, Integer>(ts) { |
| 61 |
|
| 62 |
@Override |
| 63 |
protected boolean beforeDownstream() { |
| 64 |
return false; |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public void onNext(@NonNull Integer t) { |
| 69 |
ts.onNext(t); |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
public int requestFusion(int mode) { |
| 74 |
// TODO Auto-generated method stub |
| 75 |
return 0; |
| 76 |
} |
| 77 |
|
| 78 |
@Override |
| 79 |
public @Nullable Integer poll() throws Throwable { |
| 80 |
return null; |
| 81 |
} |
| 82 |
}; |
| 83 |
|
| 84 |
bfs.onSubscribe(new BooleanSubscription()); |
| 85 |
|
| 86 |
assertFalse(ts.hasSubscription()); |
| 87 |
} |
| 88 |
} |