Add a test for the download job ID

This commit is contained in:
Bradlee Speice 2014-07-17 17:42:31 -04:00
parent b40106cedb
commit ca22be41cc

View File

@ -1,11 +1,16 @@
package org.bspeice.minimalbible.test.activity.downloader.manager; package org.bspeice.minimalbible.test.activity.downloader.manager;
import android.util.Log;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.bspeice.minimalbible.Injector; import org.bspeice.minimalbible.Injector;
import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadManager; import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadManager;
import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent; import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent;
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager; 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.Book;
import org.crosswire.jsword.book.Books; import org.crosswire.jsword.book.Books;
import org.crosswire.jsword.book.install.InstallManager; import org.crosswire.jsword.book.install.InstallManager;
@ -21,6 +26,7 @@ import javax.inject.Singleton;
import dagger.Module; import dagger.Module;
import dagger.ObjectGraph; import dagger.ObjectGraph;
import dagger.Provides; import dagger.Provides;
import rx.Observable;
import rx.functions.Action1; import rx.functions.Action1;
import rx.functions.Func1; import rx.functions.Func1;
@ -75,17 +81,18 @@ public class BookDownloadManagerTest extends TestCase implements Injector {
mObjectGraph.inject(this); mObjectGraph.inject(this);
} }
public void testInstallBook() throws Exception { Observable<Book> installableBooks() {
final Book toInstall = refreshManager.getAvailableModulesFlattened() return refreshManager.getAvailableModulesFlattened()
.filter(new Func1<Book, Boolean>() { .filter(new Func1<Book, Boolean>() {
@Override @Override
public Boolean call(Book book) { public Boolean call(Book book) {
// First uninstalled book
return !installedBooks.getBooks().contains(book); return !installedBooks.getBooks().contains(book);
} }
}) });
.toBlocking() }
.first();
public void testInstallBook() throws Exception {
final Book toInstall = installableBooks().toBlocking().first();
bookDownloadManager.installBook(toInstall); bookDownloadManager.installBook(toInstall);
@ -104,4 +111,28 @@ public class BookDownloadManagerTest extends TestCase implements Injector {
await().atMost(60, TimeUnit.SECONDS) await().atMost(60, TimeUnit.SECONDS)
.untilTrue(signal); .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);
}
} }