| 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.single; |
| 15 |
|
| 16 |
import static org.junit.Assert.*; |
| 17 |
|
| 18 |
import java.util.*; |
| 19 |
import java.util.concurrent.*; |
| 20 |
import java.util.concurrent.atomic.*; |
| 21 |
|
| 22 |
import org.junit.*; |
| 23 |
|
| 24 |
import io.reactivex.rxjava3.core.*; |
| 25 |
import io.reactivex.rxjava3.core.Observable; |
| 26 |
import io.reactivex.rxjava3.disposables.*; |
| 27 |
import io.reactivex.rxjava3.exceptions.TestException; |
| 28 |
import io.reactivex.rxjava3.functions.*; |
| 29 |
import io.reactivex.rxjava3.internal.operators.single.SingleInternalHelper; |
| 30 |
import io.reactivex.rxjava3.schedulers.Schedulers; |
| 31 |
import io.reactivex.rxjava3.subscribers.TestSubscriber; |
| 32 |
import io.reactivex.rxjava3.testsupport.*; |
| 33 |
|
| 34 |
public class SingleTest extends RxJavaTest { |
| 35 |
|
| 36 |
@Test |
| 37 |
public void helloWorld() { |
| 38 |
TestSubscriber<String> ts = new TestSubscriber<>(); |
| 39 |
Single.just("Hello World!").toFlowable().subscribe(ts); |
| 40 |
ts.assertValueSequence(Arrays.asList("Hello World!")); |
| 41 |
} |
| 42 |
|
| 43 |
@Test |
| 44 |
public void helloWorld2() { |
| 45 |
final AtomicReference<String> v = new AtomicReference<>(); |
| 46 |
Single.just("Hello World!").subscribe(new SingleObserver<String>() { |
| 47 |
|
| 48 |
@Override |
| 49 |
public void onSubscribe(Disposable d) { |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
public void onSuccess(String value) { |
| 55 |
v.set(value); |
| 56 |
} |
| 57 |
|
| 58 |
@Override |
| 59 |
public void onError(Throwable error) { |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
}); |
| 64 |
assertEquals("Hello World!", v.get()); |
| 65 |
} |
| 66 |
|
| 67 |
@Test |
| 68 |
public void map() { |
| 69 |
TestSubscriber<String> ts = new TestSubscriber<>(); |
| 70 |
Single.just("A") |
| 71 |
.map(new Function<String, String>() { |
| 72 |
@Override |
| 73 |
public String apply(String s) { |
| 74 |
return s + "B"; |
| 75 |
} |
| 76 |
}) |
| 77 |
.toFlowable().subscribe(ts); |
| 78 |
ts.assertValueSequence(Arrays.asList("AB")); |
| 79 |
} |
| 80 |
|
| 81 |
@Test |
| 82 |
public void zip() { |
| 83 |
TestSubscriber<String> ts = new TestSubscriber<>(); |
| 84 |
Single<String> a = Single.just("A"); |
| 85 |
Single<String> b = Single.just("B"); |
| 86 |
|
| 87 |
Single.zip(a, b, new BiFunction<String, String, String>() { |
| 88 |
@Override |
| 89 |
public String apply(String a1, String b1) { |
| 90 |
return a1 + b1; |
| 91 |
} |
| 92 |
}) |
| 93 |
.toFlowable().subscribe(ts); |
| 94 |
ts.assertValueSequence(Arrays.asList("AB")); |
| 95 |
} |
| 96 |
|
| 97 |
@Test |
| 98 |
public void zipWith() { |
| 99 |
TestSubscriber<String> ts = new TestSubscriber<>(); |
| 100 |
|
| 101 |
Single.just("A").zipWith(Single.just("B"), new BiFunction<String, String, String>() { |
| 102 |
@Override |
| 103 |
public String apply(String a1, String b1) { |
| 104 |
return a1 + b1; |
| 105 |
} |
| 106 |
}) |
| 107 |
.toFlowable().subscribe(ts); |
| 108 |
ts.assertValueSequence(Arrays.asList("AB")); |
| 109 |
} |
| 110 |
|
| 111 |
@Test |
| 112 |
public void merge() { |
| 113 |
TestSubscriber<String> ts = new TestSubscriber<>(); |
| 114 |
Single<String> a = Single.just("A"); |
| 115 |
Single<String> b = Single.just("B"); |
| 116 |
|
| 117 |
Single.merge(a, b).subscribe(ts); |
| 118 |
ts.assertValueSequence(Arrays.asList("A", "B")); |
| 119 |
} |
| 120 |
|
| 121 |
@Test |
| 122 |
public void mergeWith() { |
| 123 |
TestSubscriber<String> ts = new TestSubscriber<>(); |
| 124 |
|
| 125 |
Single.just("A").mergeWith(Single.just("B")).subscribe(ts); |
| 126 |
ts.assertValueSequence(Arrays.asList("A", "B")); |
| 127 |
} |
| 128 |
|
| 129 |
@Test |
| 130 |
public void createSuccess() { |
| 131 |
TestSubscriber<Object> ts = new TestSubscriber<>(); |
| 132 |
|
| 133 |
Single.unsafeCreate(new SingleSource<Object>() { |
| 134 |
@Override |
| 135 |
public void subscribe(SingleObserver<? super Object> observer) { |
| 136 |
observer.onSubscribe(Disposable.empty()); |
| 137 |
observer.onSuccess("Hello"); |
| 138 |
} |
| 139 |
}).toFlowable().subscribe(ts); |
| 140 |
|
| 141 |
ts.assertValueSequence(Arrays.asList("Hello")); |
| 142 |
} |
| 143 |
|
| 144 |
@Test |
| 145 |
public void createError() { |
| 146 |
TestSubscriberEx<Object> ts = new TestSubscriberEx<>(); |
| 147 |
Single.unsafeCreate(new SingleSource<Object>() { |
| 148 |
@Override |
| 149 |
public void subscribe(SingleObserver<? super Object> observer) { |
| 150 |
observer.onSubscribe(Disposable.empty()); |
| 151 |
observer.onError(new RuntimeException("fail")); |
| 152 |
} |
| 153 |
}).toFlowable().subscribe(ts); |
| 154 |
|
| 155 |
ts.assertError(RuntimeException.class); |
| 156 |
ts.assertErrorMessage("fail"); |
| 157 |
} |
| 158 |
|
| 159 |
@Test |
| 160 |
public void async() { |
| 161 |
TestSubscriber<String> ts = new TestSubscriber<>(); |
| 162 |
Single.just("Hello") |
| 163 |
.subscribeOn(Schedulers.io()) |
| 164 |
.map(new Function<String, String>() { |
| 165 |
@Override |
| 166 |
public String apply(String v) { |
| 167 |
System.out.println("SubscribeOn Thread: " + Thread.currentThread()); |
| 168 |
return v; |
| 169 |
} |
| 170 |
}) |
| 171 |
.observeOn(Schedulers.computation()) |
| 172 |
.map(new Function<String, String>() { |
| 173 |
@Override |
| 174 |
public String apply(String v) { |
| 175 |
System.out.println("ObserveOn Thread: " + Thread.currentThread()); |
| 176 |
return v; |
| 177 |
} |
| 178 |
}) |
| 179 |
.toFlowable().subscribe(ts); |
| 180 |
ts.awaitDone(5, TimeUnit.SECONDS); |
| 181 |
ts.assertValueSequence(Arrays.asList("Hello")); |
| 182 |
} |
| 183 |
|
| 184 |
@Test |
| 185 |
public void flatMap() throws InterruptedException { |
| 186 |
TestSubscriberEx<String> ts = new TestSubscriberEx<>(); |
| 187 |
Single.just("Hello").flatMap(new Function<String, Single<String>>() { |
| 188 |
@Override |
| 189 |
public Single<String> apply(String s) { |
| 190 |
return Single.just(s + " World!").subscribeOn(Schedulers.computation()); |
| 191 |
} |
| 192 |
} |
| 193 |
).toFlowable().subscribe(ts); |
| 194 |
if (!ts.await(5, TimeUnit.SECONDS)) { |
| 195 |
ts.cancel(); |
| 196 |
Assert.fail("TestSubscriber timed out."); |
| 197 |
} |
| 198 |
ts.assertValueSequence(Arrays.asList("Hello World!")); |
| 199 |
} |
| 200 |
|
| 201 |
@Test |
| 202 |
public void timeout() { |
| 203 |
TestSubscriber<String> ts = new TestSubscriber<>(); |
| 204 |
Single<String> s1 = Single.<String>unsafeCreate(new SingleSource<String>() { |
| 205 |
@Override |
| 206 |
public void subscribe(SingleObserver<? super String> observer) { |
| 207 |
observer.onSubscribe(Disposable.empty()); |
| 208 |
try { |
| 209 |
Thread.sleep(5000); |
| 210 |
} catch (InterruptedException e) { |
| 211 |
// ignore as we expect this for the test |
| 212 |
} |
| 213 |
observer.onSuccess("success"); |
| 214 |
} |
| 215 |
}).subscribeOn(Schedulers.io()); |
| 216 |
|
| 217 |
s1.timeout(100, TimeUnit.MILLISECONDS).toFlowable().subscribe(ts); |
| 218 |
|
| 219 |
ts.awaitDone(5, TimeUnit.SECONDS); |
| 220 |
ts.assertError(TimeoutException.class); |
| 221 |
} |
| 222 |
|
| 223 |
@Test |
| 224 |
public void timeoutWithFallback() { |
| 225 |
TestSubscriber<String> ts = new TestSubscriber<>(); |
| 226 |
Single<String> s1 = Single.<String>unsafeCreate(new SingleSource<String>() { |
| 227 |
@Override |
| 228 |
public void subscribe(SingleObserver<? super String> observer) { |
| 229 |
observer.onSubscribe(Disposable.empty()); |
| 230 |
try { |
| 231 |
Thread.sleep(5000); |
| 232 |
} catch (InterruptedException e) { |
| 233 |
// ignore as we expect this for the test |
| 234 |
} |
| 235 |
observer.onSuccess("success"); |
| 236 |
} |
| 237 |
}).subscribeOn(Schedulers.io()); |
| 238 |
|
| 239 |
s1.timeout(100, TimeUnit.MILLISECONDS, Single.just("hello")).toFlowable().subscribe(ts); |
| 240 |
|
| 241 |
ts.awaitDone(5, TimeUnit.SECONDS); |
| 242 |
ts.assertNoErrors(); |
| 243 |
ts.assertValue("hello"); |
| 244 |
} |
| 245 |
|
| 246 |
@Test |
| 247 |
public void unsubscribe() throws InterruptedException { |
| 248 |
TestSubscriber<String> ts = new TestSubscriber<>(); |
| 249 |
final AtomicBoolean unsubscribed = new AtomicBoolean(); |
| 250 |
final AtomicBoolean interrupted = new AtomicBoolean(); |
| 251 |
final CountDownLatch latch = new CountDownLatch(2); |
| 252 |
|
| 253 |
Single<String> s1 = Single.<String>unsafeCreate(new SingleSource<String>() { |
| 254 |
@Override |
| 255 |
public void subscribe(final SingleObserver<? super String> observer) { |
| 256 |
SerialDisposable sd = new SerialDisposable(); |
| 257 |
observer.onSubscribe(sd); |
| 258 |
final Thread t = new Thread(new Runnable() { |
| 259 |
|
| 260 |
@Override |
| 261 |
public void run() { |
| 262 |
try { |
| 263 |
Thread.sleep(5000); |
| 264 |
observer.onSuccess("success"); |
| 265 |
} catch (InterruptedException e) { |
| 266 |
interrupted.set(true); |
| 267 |
latch.countDown(); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
}); |
| 272 |
sd.replace(Disposable.fromRunnable(new Runnable() { |
| 273 |
@Override |
| 274 |
public void run() { |
| 275 |
unsubscribed.set(true); |
| 276 |
t.interrupt(); |
| 277 |
latch.countDown(); |
| 278 |
} |
| 279 |
})); |
| 280 |
t.start(); |
| 281 |
} |
| 282 |
}); |
| 283 |
|
| 284 |
s1.toFlowable().subscribe(ts); |
| 285 |
|
| 286 |
Thread.sleep(100); |
| 287 |
|
| 288 |
ts.cancel(); |
| 289 |
|
| 290 |
if (latch.await(1000, TimeUnit.MILLISECONDS)) { |
| 291 |
assertTrue(unsubscribed.get()); |
| 292 |
assertTrue(interrupted.get()); |
| 293 |
} else { |
| 294 |
fail("timed out waiting for latch"); |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
/** |
| 299 |
* Assert that unsubscribe propagates when passing in a SingleObserver and not a Subscriber. |
| 300 |
* @throws InterruptedException if the test is interrupted |
| 301 |
*/ |
| 302 |
@Test |
| 303 |
public void unsubscribe2() throws InterruptedException { |
| 304 |
final SerialDisposable sd = new SerialDisposable(); |
| 305 |
SingleObserver<String> ts = new SingleObserver<String>() { |
| 306 |
|
| 307 |
@Override |
| 308 |
public void onSubscribe(Disposable d) { |
| 309 |
sd.replace(d); |
| 310 |
} |
| 311 |
|
| 312 |
@Override |
| 313 |
public void onSuccess(String value) { |
| 314 |
// not interested in value |
| 315 |
} |
| 316 |
|
| 317 |
@Override |
| 318 |
public void onError(Throwable error) { |
| 319 |
// not interested in value |
| 320 |
} |
| 321 |
|
| 322 |
}; |
| 323 |
final AtomicBoolean unsubscribed = new AtomicBoolean(); |
| 324 |
final AtomicBoolean interrupted = new AtomicBoolean(); |
| 325 |
final CountDownLatch latch = new CountDownLatch(2); |
| 326 |
|
| 327 |
Single<String> s1 = Single.unsafeCreate(new SingleSource<String>() { |
| 328 |
@Override |
| 329 |
public void subscribe(final SingleObserver<? super String> observer) { |
| 330 |
SerialDisposable sd = new SerialDisposable(); |
| 331 |
observer.onSubscribe(sd); |
| 332 |
final Thread t = new Thread(new Runnable() { |
| 333 |
|
| 334 |
@Override |
| 335 |
public void run() { |
| 336 |
try { |
| 337 |
Thread.sleep(5000); |
| 338 |
observer.onSuccess("success"); |
| 339 |
} catch (InterruptedException e) { |
| 340 |
interrupted.set(true); |
| 341 |
latch.countDown(); |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
}); |
| 346 |
sd.replace(Disposable.fromRunnable(new Runnable() { |
| 347 |
@Override |
| 348 |
public void run() { |
| 349 |
unsubscribed.set(true); |
| 350 |
t.interrupt(); |
| 351 |
latch.countDown(); |
| 352 |
} |
| 353 |
})); |
| 354 |
t.start(); |
| 355 |
|
| 356 |
} |
| 357 |
}); |
| 358 |
|
| 359 |
s1.subscribe(ts); |
| 360 |
|
| 361 |
Thread.sleep(100); |
| 362 |
|
| 363 |
sd.dispose(); |
| 364 |
|
| 365 |
if (latch.await(1000, TimeUnit.MILLISECONDS)) { |
| 366 |
assertTrue(unsubscribed.get()); |
| 367 |
assertTrue(interrupted.get()); |
| 368 |
} else { |
| 369 |
fail("timed out waiting for latch"); |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
/** |
| 374 |
* Assert that unsubscribe propagates when passing in a SingleObserver and not a Subscriber. |
| 375 |
* @throws InterruptedException if the test is interrupted |
| 376 |
*/ |
| 377 |
@Test |
| 378 |
public void unsubscribeViaReturnedSubscription() throws InterruptedException { |
| 379 |
final AtomicBoolean unsubscribed = new AtomicBoolean(); |
| 380 |
final AtomicBoolean interrupted = new AtomicBoolean(); |
| 381 |
final CountDownLatch latch = new CountDownLatch(2); |
| 382 |
|
| 383 |
Single<String> s1 = Single.unsafeCreate(new SingleSource<String>() { |
| 384 |
@Override |
| 385 |
public void subscribe(final SingleObserver<? super String> observer) { |
| 386 |
SerialDisposable sd = new SerialDisposable(); |
| 387 |
observer.onSubscribe(sd); |
| 388 |
final Thread t = new Thread(new Runnable() { |
| 389 |
|
| 390 |
@Override |
| 391 |
public void run() { |
| 392 |
try { |
| 393 |
Thread.sleep(5000); |
| 394 |
observer.onSuccess("success"); |
| 395 |
} catch (InterruptedException e) { |
| 396 |
interrupted.set(true); |
| 397 |
latch.countDown(); |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
}); |
| 402 |
sd.replace(Disposable.fromRunnable(new Runnable() { |
| 403 |
@Override |
| 404 |
public void run() { |
| 405 |
unsubscribed.set(true); |
| 406 |
t.interrupt(); |
| 407 |
latch.countDown(); |
| 408 |
} |
| 409 |
})); |
| 410 |
t.start(); |
| 411 |
|
| 412 |
} |
| 413 |
}); |
| 414 |
|
| 415 |
Disposable subscription = s1.subscribe(); |
| 416 |
|
| 417 |
Thread.sleep(100); |
| 418 |
|
| 419 |
subscription.dispose(); |
| 420 |
|
| 421 |
if (latch.await(1000, TimeUnit.MILLISECONDS)) { |
| 422 |
assertTrue(unsubscribed.get()); |
| 423 |
assertTrue(interrupted.get()); |
| 424 |
} else { |
| 425 |
fail("timed out waiting for latch"); |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
@Test |
| 430 |
public void backpressureAsObservable() { |
| 431 |
Single<String> s = Single.unsafeCreate(new SingleSource<String>() { |
| 432 |
@Override |
| 433 |
public void subscribe(SingleObserver<? super String> t) { |
| 434 |
t.onSubscribe(Disposable.empty()); |
| 435 |
t.onSuccess("hello"); |
| 436 |
} |
| 437 |
}); |
| 438 |
|
| 439 |
TestSubscriber<String> ts = new TestSubscriber<>(0L); |
| 440 |
|
| 441 |
s.toFlowable().subscribe(ts); |
| 442 |
|
| 443 |
ts.assertNoValues(); |
| 444 |
|
| 445 |
ts.request(1); |
| 446 |
|
| 447 |
ts.assertValue("hello"); |
| 448 |
} |
| 449 |
|
| 450 |
@Test |
| 451 |
public void toObservable() { |
| 452 |
Flowable<String> a = Single.just("a").toFlowable(); |
| 453 |
TestSubscriber<String> ts = new TestSubscriber<>(); |
| 454 |
a.subscribe(ts); |
| 455 |
ts.assertValue("a"); |
| 456 |
ts.assertNoErrors(); |
| 457 |
ts.assertComplete(); |
| 458 |
} |
| 459 |
|
| 460 |
@Test(expected = NullPointerException.class) |
| 461 |
public void doOnEventNullEvent() { |
| 462 |
Single.just(1).doOnEvent(null); |
| 463 |
} |
| 464 |
|
| 465 |
@Test |
| 466 |
public void doOnEventComplete() { |
| 467 |
final AtomicInteger atomicInteger = new AtomicInteger(0); |
| 468 |
|
| 469 |
Single.just(1).doOnEvent(new BiConsumer<Integer, Throwable>() { |
| 470 |
@Override |
| 471 |
public void accept(final Integer integer, final Throwable throwable) throws Exception { |
| 472 |
if (integer != null) { |
| 473 |
atomicInteger.incrementAndGet(); |
| 474 |
} |
| 475 |
} |
| 476 |
}).subscribe(); |
| 477 |
|
| 478 |
assertEquals(1, atomicInteger.get()); |
| 479 |
} |
| 480 |
|
| 481 |
@Test |
| 482 |
public void doOnEventError() { |
| 483 |
final AtomicInteger atomicInteger = new AtomicInteger(0); |
| 484 |
|
| 485 |
Single.error(new RuntimeException()).doOnEvent(new BiConsumer<Object, Throwable>() { |
| 486 |
@Override |
| 487 |
public void accept(final Object o, final Throwable throwable) throws Exception { |
| 488 |
if (throwable != null) { |
| 489 |
atomicInteger.incrementAndGet(); |
| 490 |
} |
| 491 |
} |
| 492 |
}).subscribe(); |
| 493 |
|
| 494 |
assertEquals(1, atomicInteger.get()); |
| 495 |
} |
| 496 |
|
| 497 |
@Test |
| 498 |
public void toFuture() throws Exception { |
| 499 |
assertEquals(1, Single.just(1).toFuture().get().intValue()); |
| 500 |
} |
| 501 |
|
| 502 |
@Test |
| 503 |
public void toFutureThrows() throws Exception { |
| 504 |
try { |
| 505 |
Single.error(new TestException()).toFuture().get(); |
| 506 |
} catch (ExecutionException ex) { |
| 507 |
assertTrue(ex.toString(), ex.getCause() instanceof TestException); |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
@Test(expected = UnsupportedOperationException.class) |
| 512 |
public void toFlowableIterableRemove() { |
| 513 |
Iterable<? extends Flowable<Integer>> f = SingleInternalHelper.iterableToFlowable(Arrays.asList(Single.just(1))); |
| 514 |
|
| 515 |
Iterator<? extends Flowable<Integer>> iterator = f.iterator(); |
| 516 |
iterator.next(); |
| 517 |
iterator.remove(); |
| 518 |
} |
| 519 |
|
| 520 |
@Test |
| 521 |
public void zipIterableObject() { |
| 522 |
final List<Single<Integer>> singles = Arrays.asList(Single.just(1), Single.just(4)); |
| 523 |
Single.zip(singles, new Function<Object[], Object>() { |
| 524 |
@Override |
| 525 |
public Object apply(final Object[] o) throws Exception { |
| 526 |
int sum = 0; |
| 527 |
for (Object i : o) { |
| 528 |
sum += (Integer) i; |
| 529 |
} |
| 530 |
return sum; |
| 531 |
} |
| 532 |
}).test().assertResult(5); |
| 533 |
} |
| 534 |
|
| 535 |
@Test |
| 536 |
public void to() { |
| 537 |
Single.just(1).to(new SingleConverter<Integer, Flowable<Integer>>() { |
| 538 |
@Override |
| 539 |
public Flowable<Integer> apply(Single<Integer> v) { |
| 540 |
return v.toFlowable(); |
| 541 |
} |
| 542 |
}) |
| 543 |
.test() |
| 544 |
.assertResult(1); |
| 545 |
} |
| 546 |
|
| 547 |
@Test(expected = NullPointerException.class) |
| 548 |
public void fromObservableNull() { |
| 549 |
Single.fromObservable(null); |
| 550 |
} |
| 551 |
|
| 552 |
@Test |
| 553 |
public void fromObservableEmpty() { |
| 554 |
Single.fromObservable(Observable.empty()) |
| 555 |
.test() |
| 556 |
.assertFailure(NoSuchElementException.class); |
| 557 |
} |
| 558 |
|
| 559 |
@Test |
| 560 |
public void fromObservableMoreThan1Elements() { |
| 561 |
Single.fromObservable(Observable.just(1, 2)) |
| 562 |
.to(TestHelper.<Integer>testConsumer()) |
| 563 |
.assertFailure(IllegalArgumentException.class) |
| 564 |
.assertErrorMessage("Sequence contains more than one element!"); |
| 565 |
} |
| 566 |
|
| 567 |
@Test |
| 568 |
public void fromObservableOneElement() { |
| 569 |
Single.fromObservable(Observable.just(1)) |
| 570 |
.test() |
| 571 |
.assertResult(1); |
| 572 |
} |
| 573 |
|
| 574 |
@Test |
| 575 |
public void fromObservableError() { |
| 576 |
Single.fromObservable(Observable.error(new RuntimeException("some error"))) |
| 577 |
.to(TestHelper.testConsumer()) |
| 578 |
.assertFailure(RuntimeException.class) |
| 579 |
.assertErrorMessage("some error"); |
| 580 |
} |
| 581 |
|
| 582 |
@Test(expected = NullPointerException.class) |
| 583 |
public void implementationThrows() { |
| 584 |
new Single<Integer>() { |
| 585 |
@Override |
| 586 |
protected void subscribeActual(SingleObserver<? super Integer> observer) { |
| 587 |
throw new NullPointerException(); |
| 588 |
} |
| 589 |
}.test(); |
| 590 |
} |
| 591 |
} |
| 592 |
|