@@ -0,0 +1,2089 @@
+package com.thefuntasty.infinity.test.adapter.thread;%0A%0Aimport android.os.Build;%0Aimport android.support.v4.widget.SwipeRefreshLayout;%0A%0Aimport com.thefuntasty.infinity.InfinityEventListener;%0Aimport com.thefuntasty.infinity.InfinityException;%0Aimport com.thefuntasty.infinity.test.App;%0Aimport com.thefuntasty.infinity.test.BuildConfig;%0Aimport com.thefuntasty.infinity.test.User;%0Aimport com.thefuntasty.infinity.test.adapter.BaseAdapterTest;%0A%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.ArgumentCaptor;%0Aimport org.mockito.Captor;%0Aimport org.mockito.Mock;%0Aimport org.robolectric.RobolectricTestRunner;%0Aimport org.robolectric.annotation.Config;%0A%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.concurrent.CountDownLatch;%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport rx.Observable;%0Aimport rx.schedulers.Schedulers;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0Aimport static org.mockito.Matchers.eq;%0Aimport static org.mockito.Mockito.verify;%0A%0A@RunWith(RobolectricTestRunner.class)%0A@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.M, application = App.class)%0Apublic class DataFromNonUIThreadTest extends BaseAdapterTest %7B%0A%0A%09private CountDownLatch lock = new CountDownLatch(1);%0A%09@Mock InfinityEventListener mockEventListener;%0A%09@Captor ArgumentCaptor%3CThrowable%3E captor;%0A%0A%09@Test%0A%09public void dataFromBadThread() throws Exception %7B%0A%09%09lock.await(1, TimeUnit.SECONDS);%0A%0A%09%09verify(mockEventListener).onFirstUnavailable(captor.capture(), eq(false));%0A%09%09assertThat(captor.getValue()).hasMessage(%22Callback methods onData() & onError() must be called from UI Thread%22);%0A%09%09assertThat(captor.getValue()).isExactlyInstanceOf(InfinityException.class);%0A%09%7D%0A%0A%09@Override%0A%09public Observable%3CList%3CUser%3E%3E getDataObservable(int limit, int offset) %7B%0A%09%09return Observable.just(Collections.%3CUser%3EemptyList())%0A%09%09%09%09.doOnUnsubscribe(() -%3E lock.countDown())%0A%09%09%09%09.subscribeOn(Schedulers.io())%0A%09%09%09%09.observeOn(Schedulers.io());%0A%09%7D%0A%0A%09@Override public InfinityEventListener getEventListener(SwipeRefreshLayout refresh) %7B%0A%09%09return mockEventListener;%0A%09%7D%0A%7D%0A

add test to check case when accessing adapter from wrong thread