@Test public void subscribeOn() { String main = Thread.currentThread().getName(); String other = Perhaps.fromCallable(new Callable<String>() { @Override public String call() throws Exception { return Thread.currentThread().getName(); } }) .subscribeOn(Schedulers.single()) .blockingGet(); assertNotNull(other); assertNotEquals(main, other); }
@Test public void observeOn() { String main = Thread.currentThread().getName(); String other = Perhaps.just(1) .observeOn(Schedulers.single()) .map(new Function<Integer, String>() { @Override public String apply(Integer v) throws Exception { return Thread.currentThread().getName(); } }) .blockingGet(5, TimeUnit.SECONDS); assertNotNull(other); assertNotEquals(main, other); }
@Test public void subscribeOnError() { String main = Thread.currentThread().getName(); final String[] other = { null }; Perhaps.error(new IOException()) .subscribeOn(Schedulers.single()) .mapError(new Function<Throwable, Throwable>() { @Override public Throwable apply(Throwable e) throws Exception { other[0] = Thread.currentThread().getName(); return e; } }) .onErrorReturnItem(0) .blockingGet(5, TimeUnit.SECONDS); assertNotNull(other); assertNotEquals(main, other); }
@Test public void observeOnError() { String main = Thread.currentThread().getName(); final String[] other = { null }; Perhaps.error(new IOException()) .observeOn(Schedulers.single()) .mapError(new Function<Throwable, Throwable>() { @Override public Throwable apply(Throwable e) throws Exception { other[0] = Thread.currentThread().getName(); return e; } }) .onErrorReturnItem(0) .blockingGet(5, TimeUnit.SECONDS); assertNotNull(other); assertNotEquals(main, other); }
@Test public void observeOnHidden() { String main = Thread.currentThread().getName(); String other = Perhaps.just(1).hide() .observeOn(Schedulers.single()) .map(new Function<Integer, String>() { @Override public String apply(Integer v) throws Exception { return Thread.currentThread().getName(); } }) .blockingGet(5, TimeUnit.SECONDS); assertNotNull(other); assertNotEquals(main, other); }