diff --git a/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/BookDownloadManagerTest.java b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/BookDownloadManagerTest.java index 3b5202c..47ea423 100644 --- a/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/BookDownloadManagerTest.java +++ b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/BookDownloadManagerTest.java @@ -1,11 +1,16 @@ package org.bspeice.minimalbible.test.activity.downloader.manager; +import android.util.Log; + import junit.framework.TestCase; import org.bspeice.minimalbible.Injector; import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadManager; import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent; import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager; +import org.crosswire.common.progress.JobManager; +import org.crosswire.common.progress.WorkEvent; +import org.crosswire.common.progress.WorkListener; import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.Books; import org.crosswire.jsword.book.install.InstallManager; @@ -21,6 +26,7 @@ import javax.inject.Singleton; import dagger.Module; import dagger.ObjectGraph; import dagger.Provides; +import rx.Observable; import rx.functions.Action1; import rx.functions.Func1; @@ -75,17 +81,18 @@ public class BookDownloadManagerTest extends TestCase implements Injector { mObjectGraph.inject(this); } - public void testInstallBook() throws Exception { - final Book toInstall = refreshManager.getAvailableModulesFlattened() + Observable installableBooks() { + return refreshManager.getAvailableModulesFlattened() .filter(new Func1() { @Override public Boolean call(Book book) { - // First uninstalled book return !installedBooks.getBooks().contains(book); } - }) - .toBlocking() - .first(); + }); + } + + public void testInstallBook() throws Exception { + final Book toInstall = installableBooks().toBlocking().first(); bookDownloadManager.installBook(toInstall); @@ -104,4 +111,28 @@ public class BookDownloadManagerTest extends TestCase implements Injector { await().atMost(60, TimeUnit.SECONDS) .untilTrue(signal); } + + public void testJobIdMatch() { + final Book toInstall = installableBooks().toBlocking().first(); + final String jobName = BookDownloadManager.getJobId(toInstall); + final AtomicBoolean jobNameMatch = new AtomicBoolean(false); + + JobManager.addWorkListener(new WorkListener() { + @Override + public void workProgressed(WorkEvent ev) { + Log.d("testJobIdMatch", ev.getJob().getJobID() + " " + jobName); + if (ev.getJob().getJobID().equals(jobName)) { + jobNameMatch.set(true); + } + } + + @Override + public void workStateChanged(WorkEvent ev) { + } + }); + + bookDownloadManager.installBook(toInstall); + await().atMost(1, TimeUnit.SECONDS) + .untilTrue(jobNameMatch); + } } \ No newline at end of file