Search in sources :

Example 6 with TestLatch

use of org.wikipedia.testlib.TestLatch in project apps-android-wikipedia by wikimedia.

the class SaneAsyncTaskTest method testExceptionHandling.

@Test
public void testExceptionHandling() {
    final TestLatch latch = new TestLatch();
    final Throwable thrown = new Exception();
    runOnMainSync(() -> new SaneAsyncTask<Void>() {

        @Override
        public void onFinish(Void result) {
            fail("onFinish called despite exception");
        }

        @Override
        public void onCatch(Throwable caught) {
            assertThat(caught, is(thrown));
            latch.countDown();
        }

        @Override
        public Void performTask() throws Throwable {
            throw thrown;
        }
    }.execute());
    latch.await();
}
Also used : TestLatch(org.wikipedia.testlib.TestLatch) Test(org.junit.Test)

Example 7 with TestLatch

use of org.wikipedia.testlib.TestLatch in project apps-android-wikipedia by wikimedia.

the class SaneAsyncTaskTest method testAppropriateThreadFinish.

@Test
public void testAppropriateThreadFinish() {
    final TestLatch latch = new TestLatch();
    runOnMainSync(() -> new SaneAsyncTask<Void>() {

        @Override
        public void onBeforeExecute() {
            assertUiThread();
        }

        @Override
        public void onFinish(Void result) {
            assertUiThread();
            latch.countDown();
        }

        @Override
        public Void performTask() throws Throwable {
            assertNotUiThread();
            return null;
        }
    }.execute());
    latch.await();
}
Also used : TestLatch(org.wikipedia.testlib.TestLatch) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 TestLatch (org.wikipedia.testlib.TestLatch)7 BasePageLeadTest (org.wikipedia.dataclient.page.BasePageLeadTest)2 PageLead (org.wikipedia.dataclient.page.PageLead)2 ArrayList (java.util.ArrayList)1 MwMobileViewPageLead (org.wikipedia.dataclient.mwapi.page.MwMobileViewPageLead)1 PageTitle (org.wikipedia.page.PageTitle)1