use of org.wikipedia.testlib.TestLatch in project apps-android-wikipedia by wikimedia.
the class SaneAsyncTaskTest method testAppropriateThreadException.
@Test
public void testAppropriateThreadException() {
final TestLatch latch = new TestLatch();
runOnMainSync(() -> new SaneAsyncTask<Void>() {
@Override
public void onBeforeExecute() {
assertUiThread();
}
@Override
public void onFinish(Void result) {
fail("onFinish called even when there is an exception");
}
@Override
public void onCatch(Throwable caught) {
assertUiThread();
latch.countDown();
}
@Override
public Void performTask() throws Throwable {
assertNotUiThread();
throw new Exception();
}
}.execute());
latch.await();
}
use of org.wikipedia.testlib.TestLatch in project apps-android-wikipedia by wikimedia.
the class SaneAsyncTaskTest method testFinishHandling.
@Test
public void testFinishHandling() {
final TestLatch latch = new TestLatch();
final Integer returned = 42;
runOnMainSync(() -> new SaneAsyncTask<Integer>() {
@Override
public void onFinish(Integer result) {
assertThat(returned, is(result));
latch.countDown();
}
@Override
public void onCatch(Throwable caught) {
fail("Exception called despite success");
}
@Override
public Integer performTask() throws Throwable {
return returned;
}
}.execute());
latch.await();
}
use of org.wikipedia.testlib.TestLatch in project apps-android-wikipedia by wikimedia.
the class MwMobileViewPageLeadTest method testThumbUrls.
@Test
@SuppressWarnings("checkstyle:magicnumber")
public void testThumbUrls() throws Throwable {
enqueueFromFile("page_lead_mw.json");
final TestLatch latch = new TestLatch();
subject.lead(CacheControl.FORCE_NETWORK, null, "foo", 640).enqueue(new Callback<PageLead>() {
@Override
public void onResponse(@NonNull Call<PageLead> call, @NonNull Response<PageLead> response) {
assertThat(response.body().getLeadImageUrl(640).contains("640px"), is(true));
assertThat(response.body().getThumbUrl().contains(preferredThumbSizeString()), is(true));
assertThat(response.body().getDescription(), is("Mexican boxer"));
latch.countDown();
}
@Override
public void onFailure(@NonNull Call<PageLead> call, @NonNull Throwable t) {
fail();
latch.countDown();
}
});
latch.await();
}
use of org.wikipedia.testlib.TestLatch in project apps-android-wikipedia by wikimedia.
the class RbPageLeadTest method testThumbUrls.
@Test
@SuppressWarnings("checkstyle:magicnumber")
public void testThumbUrls() throws Throwable {
enqueueFromFile("page_lead_rb.json");
final TestLatch latch = new TestLatch();
subject.lead(CacheControl.FORCE_NETWORK, null, "foo", 640).enqueue(new Callback<PageLead>() {
@Override
public void onResponse(@NonNull Call<PageLead> call, @NonNull Response<PageLead> response) {
assertThat(response.body().getLeadImageUrl(640).contains("640px"), is(true));
assertThat(response.body().getThumbUrl().contains(preferredThumbSizeString()), is(true));
assertThat(response.body().getDescription(), is("Mexican boxer"));
latch.countDown();
}
@Override
public void onFailure(@NonNull Call<PageLead> call, @NonNull Throwable t) {
fail();
latch.countDown();
}
});
latch.await();
}
use of org.wikipedia.testlib.TestLatch in project apps-android-wikipedia by wikimedia.
the class BatchUtilTest method testMwApiBatches.
@Test
@SuppressWarnings("checkstyle:magicnumber")
public void testMwApiBatches() throws Throwable {
final TestLatch latch = new TestLatch();
BatchUtil.makeBatches(titles, new BatchUtil.Handler<Integer>() {
private List<Integer> sizes = new ArrayList<>();
private int count;
@Override
public void handleBatch(@NonNull List<PageTitle> batchTitles, int total, BatchUtil.Callback<Integer> cb) {
sizes.add(batchTitles.size());
count += batchTitles.size();
if (count == TOTAL) {
assertThat(sizes.get(0), is(50));
assertThat(sizes.get(1), is(50));
assertThat(sizes.get(2), is(20));
latch.countDown();
}
}
}, null);
latch.await();
}
Aggregations