| 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.observable; |
| 15 |
|
| 16 |
import static org.junit.Assert.*; |
| 17 |
|
| 18 |
import java.util.concurrent.*; |
| 19 |
|
| 20 |
import org.junit.Test; |
| 21 |
|
| 22 |
import io.reactivex.rxjava3.core.*; |
| 23 |
import io.reactivex.rxjava3.functions.Function; |
| 24 |
import io.reactivex.rxjava3.operators.QueueFuseable; |
| 25 |
import io.reactivex.rxjava3.operators.ScalarSupplier; |
| 26 |
import io.reactivex.rxjava3.schedulers.Schedulers; |
| 27 |
import io.reactivex.rxjava3.testsupport.*; |
| 28 |
|
| 29 |
public class ObservableFromTest extends RxJavaTest { |
| 30 |
|
| 31 |
@Test |
| 32 |
public void fromFutureTimeout() throws Exception { |
| 33 |
Observable.fromFuture(Observable.never() |
| 34 |
.toFuture(), 100, TimeUnit.MILLISECONDS) |
| 35 |
.subscribeOn(Schedulers.io()) |
| 36 |
.test() |
| 37 |
.awaitDone(5, TimeUnit.SECONDS) |
| 38 |
.assertFailure(TimeoutException.class); |
| 39 |
} |
| 40 |
|
| 41 |
@Test |
| 42 |
public void fromPublisher() { |
| 43 |
Observable.fromPublisher(Flowable.just(1)) |
| 44 |
.test() |
| 45 |
.assertResult(1); |
| 46 |
} |
| 47 |
|
| 48 |
@Test |
| 49 |
public void just10() { |
| 50 |
Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) |
| 51 |
.test() |
| 52 |
.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); |
| 53 |
} |
| 54 |
|
| 55 |
@Test |
| 56 |
public void fromArrayEmpty() { |
| 57 |
assertSame(Observable.empty(), Observable.fromArray()); |
| 58 |
} |
| 59 |
|
| 60 |
@Test |
| 61 |
public void fromArraySingle() { |
| 62 |
assertTrue(Observable.fromArray(1) instanceof ScalarSupplier); |
| 63 |
} |
| 64 |
|
| 65 |
@Test |
| 66 |
public void fromPublisherDispose() { |
| 67 |
TestHelper.checkDisposed(Flowable.just(1).toObservable()); |
| 68 |
} |
| 69 |
|
| 70 |
@Test |
| 71 |
public void fromPublisherDoubleOnSubscribe() { |
| 72 |
TestHelper.checkDoubleOnSubscribeFlowableToObservable(new Function<Flowable<Object>, ObservableSource<Object>>() { |
| 73 |
@Override |
| 74 |
public ObservableSource<Object> apply(Flowable<Object> f) throws Exception { |
| 75 |
return f.toObservable(); |
| 76 |
} |
| 77 |
}); |
| 78 |
} |
| 79 |
|
| 80 |
@Test |
| 81 |
public void fusionRejected() { |
| 82 |
TestObserverEx<Integer> to = new TestObserverEx<>(QueueFuseable.ASYNC); |
| 83 |
|
| 84 |
Observable.fromArray(1, 2, 3) |
| 85 |
.subscribe(to); |
| 86 |
|
| 87 |
to.assertFusionMode(QueueFuseable.NONE) |
| 88 |
.assertResult(1, 2, 3); |
| 89 |
} |
| 90 |
} |