mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-21 23:48:18 -05:00
Add a test for the download job ID
This commit is contained in:
parent
b40106cedb
commit
ca22be41cc
@ -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<Book> installableBooks() {
|
||||
return refreshManager.getAvailableModulesFlattened()
|
||||
.filter(new Func1<Book, Boolean>() {
|
||||
@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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user