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();
}
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();
}
Aggregations