| 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.single; |
| 15 |
|
| 16 |
import static org.junit.Assert.assertTrue; |
| 17 |
|
| 18 |
import java.util.List; |
| 19 |
import java.util.concurrent.TimeUnit; |
| 20 |
|
| 21 |
import org.junit.Test; |
| 22 |
|
| 23 |
import io.reactivex.rxjava3.core.*; |
| 24 |
import io.reactivex.rxjava3.exceptions.TestException; |
| 25 |
import io.reactivex.rxjava3.observers.TestObserver; |
| 26 |
import io.reactivex.rxjava3.plugins.RxJavaPlugins; |
| 27 |
import io.reactivex.rxjava3.schedulers.*; |
| 28 |
import io.reactivex.rxjava3.subjects.PublishSubject; |
| 29 |
import io.reactivex.rxjava3.testsupport.TestHelper; |
| 30 |
|
| 31 |
public class SingleSubscribeOnTest extends RxJavaTest { |
| 32 |
|
| 33 |
@Test |
| 34 |
public void normal() { |
| 35 |
List<Throwable> list = TestHelper.trackPluginErrors(); |
| 36 |
try { |
| 37 |
TestScheduler scheduler = new TestScheduler(); |
| 38 |
|
| 39 |
TestObserver<Integer> to = Single.just(1) |
| 40 |
.subscribeOn(scheduler) |
| 41 |
.test(); |
| 42 |
|
| 43 |
scheduler.advanceTimeBy(1, TimeUnit.SECONDS); |
| 44 |
|
| 45 |
to.assertResult(1); |
| 46 |
|
| 47 |
assertTrue(list.toString(), list.isEmpty()); |
| 48 |
} finally { |
| 49 |
RxJavaPlugins.reset(); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
@Test |
| 54 |
public void dispose() { |
| 55 |
TestHelper.checkDisposed(PublishSubject.create().singleOrError().subscribeOn(new TestScheduler())); |
| 56 |
} |
| 57 |
|
| 58 |
@Test |
| 59 |
public void error() { |
| 60 |
Single.error(new TestException()) |
| 61 |
.subscribeOn(Schedulers.single()) |
| 62 |
.test() |
| 63 |
.awaitDone(5, TimeUnit.SECONDS) |
| 64 |
.assertFailure(TestException.class); |
| 65 |
} |
| 66 |
} |