From ed219bc8a44c21bd2ecbdadd60213754aa79a5e2 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Fri, 30 May 2014 23:23:16 -0400 Subject: [PATCH] Unit test fixes, works locally. We'll see if it finally runs on Travis... --- MinimalBible/build.gradle | 6 +-- .../test/DownloadActivityTest.java | 37 ++++++++++++------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/MinimalBible/build.gradle b/MinimalBible/build.gradle index 21496af..a6b2d98 100644 --- a/MinimalBible/build.gradle +++ b/MinimalBible/build.gradle @@ -18,9 +18,6 @@ dependencies { compile project(path: ':jsword-minimalbible', configuration: 'buildJSword') compile project(':appcompat_v7') - apt "org.androidannotations:androidannotations:3.0+" - compile "org.androidannotations:androidannotations-api:3.0+" - apt 'com.squareup.dagger:dagger-compiler:1.2.0' compile 'com.squareup.dagger:dagger:1.2.0' @@ -30,7 +27,7 @@ dependencies { compile 'de.devland.esperandro:esperandro-api:1.1.2' apt 'de.devland.esperandro:esperandro:1.1.2' - compile 'com.f2prateek.dart:dart:1.1.0' + // compile 'com.f2prateek.dart:dart:1.1.0' compile 'com.readystatesoftware.systembartint:systembartint:1.0.3' compile 'de.greenrobot:eventbus:2.2.0' @@ -40,6 +37,7 @@ dependencies { // And our unit testing needs some specific stuff (and specific stuff included again) androidTestCompile 'junit:junit:4.11+' + androidTestCompile 'com.jayway.awaitility:awaitility:1.6.0' androidTestProvided 'com.squareup.dagger:dagger-compiler:1.2.0' } diff --git a/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java b/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java index d0307bd..8dcf0a3 100644 --- a/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java +++ b/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java @@ -1,26 +1,27 @@ package org.bspeice.minimalbible.test; import android.test.InstrumentationTestCase; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; import org.bspeice.minimalbible.MinimalBible; import org.bspeice.minimalbible.MinimalBibleModules; -import org.bspeice.minimalbible.R; -import org.bspeice.minimalbible.activities.downloader.BookItemHolder; +import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadThread; import org.bspeice.minimalbible.activities.downloader.manager.DLProgressEvent; import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager; +import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager; import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.install.Installer; +import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import javax.inject.Inject; +import javax.inject.Provider; import dagger.Module; +import static com.jayway.awaitility.Awaitility.*; + /** * Tests for the Download activity */ @@ -30,8 +31,9 @@ public class DownloadActivityTest extends InstrumentationTestCase { injects = DownloadActivityTest.class) public static class DownloadActivityTestModule {} - @Inject - DownloadManager dm; + @Inject DownloadManager dm; + @Inject Provider bookDownloadThreadProvider; + @Inject RefreshManager rm; public void setUp() { MinimalBible.getApplication().getObjGraph() @@ -47,21 +49,28 @@ public class DownloadActivityTest extends InstrumentationTestCase { */ public void testInitialProgressEventOnDownload() throws InterruptedException { final CountDownLatch signal = new CountDownLatch(1); - Installer i = (Installer) dm.getInstallers().values().toArray()[0]; - Book testBook = i.getBooks().get(0); - View dummyView = LayoutInflater.from(MinimalBible.getApplication()) - .inflate(R.layout.list_download_items, null); - BookItemHolder holder = new BookItemHolder(dummyView, testBook); + // Need to make sure we've refreshed the refreshmanager first + Installer i = (Installer) dm.getInstallers().values().toArray()[0]; + final Book testBook = i.getBooks().get(0); + await().until(new Callable() { + @Override + public Boolean call() throws Exception { + return rm.installerFromBook(testBook) != null; + } + }); + + // And wait for the actual download dm.getDownloadBus().register(new Object() { public void onEvent(DLProgressEvent event) { - Log.d("testInitial", Integer.toString(event.getProgress())); if (event.getProgress() == 0) { signal.countDown(); } } }); - holder.onDownloadItem(dummyView); + + BookDownloadThread thread = bookDownloadThreadProvider.get(); + thread.downloadBook(testBook); signal.await(10, TimeUnit.SECONDS); if (signal.getCount() != 0) {