mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-21 23:48:18 -05:00
Add the first full-scale test case
Also demonstrates some advanced Dagger usage
This commit is contained in:
parent
a9b06a7fde
commit
365cf0dccb
@ -51,16 +51,14 @@ android {
|
||||
dependencies {
|
||||
compile project(path: ':jsword-minimalbible', configuration: 'buildJSword')
|
||||
|
||||
compile 'com.squareup.dagger:dagger:1.2.1'
|
||||
provided 'com.squareup.dagger:dagger-compiler:1.2.1'
|
||||
|
||||
|
||||
provided 'de.devland.esperandro:esperandro:1.1.2'
|
||||
|
||||
|
||||
androidTestCompile 'com.jayway.awaitility:awaitility:1.6.0'
|
||||
androidTestProvided 'com.squareup.dagger:dagger-compiler:1.2.0'
|
||||
// androidTestProvided 'com.squareup.dagger:dagger-compiler:1.2.0'
|
||||
|
||||
compile 'com.squareup.dagger:dagger:1.2.1'
|
||||
compile 'com.jakewharton:butterknife:5.0.1'
|
||||
compile 'de.devland.esperandro:esperandro-api:1.1.2'
|
||||
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
|
||||
|
@ -0,0 +1,107 @@
|
||||
package org.bspeice.minimalbible.test.activity.downloader.manager;
|
||||
|
||||
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.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.Books;
|
||||
import org.crosswire.jsword.book.install.InstallManager;
|
||||
import org.crosswire.jsword.book.install.Installer;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.ObjectGraph;
|
||||
import dagger.Provides;
|
||||
import rx.functions.Action1;
|
||||
import rx.functions.Func1;
|
||||
|
||||
import static com.jayway.awaitility.Awaitility.*;
|
||||
|
||||
public class BookDownloadManagerTest extends TestCase implements Injector {
|
||||
|
||||
ObjectGraph mObjectGraph;
|
||||
|
||||
/**
|
||||
* Modules needed for this test case
|
||||
*/
|
||||
@Module(injects = {BookDownloadManager.class,
|
||||
RefreshManager.class,
|
||||
BookDownloadManagerTest.class})
|
||||
public static class BookDownloadManagerTestModules {
|
||||
Injector i;
|
||||
|
||||
BookDownloadManagerTestModules(Injector i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Injector provideInjector() {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
Books provideBooks() {
|
||||
return Books.installed();
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
Collection<Installer> provideInstallers() {
|
||||
return new InstallManager().getInstallers().values();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject BookDownloadManager bookDownloadManager;
|
||||
@Inject RefreshManager refreshManager;
|
||||
@Inject Books installedBooks;
|
||||
|
||||
@Override
|
||||
public void inject(Object o) {
|
||||
mObjectGraph.inject(o);
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
BookDownloadManagerTestModules modules = new BookDownloadManagerTestModules(this);
|
||||
mObjectGraph = ObjectGraph.create(modules);
|
||||
mObjectGraph.inject(this);
|
||||
}
|
||||
|
||||
public void testInstallBook() throws Exception {
|
||||
final Book toInstall = refreshManager.getAvailableModulesFlattened()
|
||||
.filter(new Func1<Book, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(Book book) {
|
||||
// First uninstalled book
|
||||
return !installedBooks.getBooks().contains(book);
|
||||
}
|
||||
})
|
||||
.toBlocking()
|
||||
.first();
|
||||
|
||||
bookDownloadManager.installBook(toInstall);
|
||||
|
||||
final AtomicBoolean signal = new AtomicBoolean(false);
|
||||
bookDownloadManager.getDownloadEvents()
|
||||
.subscribe(new Action1<DLProgressEvent>() {
|
||||
@Override
|
||||
public void call(DLProgressEvent dlProgressEvent) {
|
||||
if (dlProgressEvent.getB().getInitials().equals(toInstall.getInitials())
|
||||
&& dlProgressEvent.getProgress() == DLProgressEvent.PROGRESS_COMPLETE) {
|
||||
signal.set(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await().atMost(60, TimeUnit.SECONDS)
|
||||
.untilTrue(signal);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user