package com.epy0n0ff.ci;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;
import rx.Observable;
import rx.Subscriber;
import rx.observers.TestSubscriber;
import rx.schedulers.Schedulers;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

/**
 * Async task test
 * Created by epy0n0ff on 2015/09/25.
 */
@RunWith(RobolectricGradleTestRunner.class) @Config(
    sdk = 21,
    constants = BuildConfig.class) public class RxTest {
  @Test public void asyncTest() {
    Observable<Object> testObservable = Observable.create(new Observable.OnSubscribe<Object>() {
      @Override public void call(final Subscriber<? super Object> subscriber) {
        try {
          Thread.sleep(3000);
          subscriber.onNext(new Object());
          subscriber.onCompleted();
        } catch (InterruptedException e) {
          subscriber.onError(e);
        }
      }
    }).observeOn(Schedulers.newThread());

    TestSubscriber<Object> testSubscriber = new TestSubscriber<>();
    testObservable.subscribe(testSubscriber);

    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertNoErrors();
    testSubscriber.assertCompleted();

    assertThat("check onNextEvents size", testSubscriber.getOnNextEvents().size(), is(1));
  }
}

@@ -19,16 +19,41 @@
 ff.ci;%0A%0A
+import org.junit.Before;%0A
 import o
@@ -67,16 +67,16 @@
 t.Test;%0A
-
 import o
@@ -216,16 +216,37 @@
 rvable;%0A
+import rx.Scheduler;%0A
 import r
@@ -251,32 +251,127 @@
  rx.Subscriber;%0A
+import rx.android.plugins.RxAndroidPlugins;%0Aimport rx.android.plugins.RxAndroidSchedulersHook;%0A
 import rx.observ
@@ -701,16 +701,258 @@
 xTest %7B%0A
+  @Before public void setUp() %7B%0A    RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() %7B%0A      @Override public Scheduler getMainThreadScheduler() %7B%0A        return Schedulers.newThread();%0A      %7D%0A    %7D);%0A  %7D%0A%0A
   @Test 
@@ -1375,48 +1375,14 @@
   %7D%0A
+
     %7D)
-.observeOn(Schedulers.newThread())
 ;%0A%0A 

Change observeOn(...) to registerSchedulersHook.