From 08a1aaa68453f212543d6f01a30dac9c14287fec Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Thu, 17 Jul 2014 18:12:56 -0400 Subject: [PATCH] First InstalledManager test case --- .../manager/InstalledManagerTest.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/InstalledManagerTest.java diff --git a/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/InstalledManagerTest.java b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/InstalledManagerTest.java new file mode 100644 index 0000000..9c22aa4 --- /dev/null +++ b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/InstalledManagerTest.java @@ -0,0 +1,95 @@ +package org.bspeice.minimalbible.test.activity.downloader.manager; + +import junit.framework.TestCase; + +import org.bspeice.minimalbible.Injector; +import org.bspeice.minimalbible.activity.downloader.manager.InstalledManager; +import org.crosswire.jsword.book.Book; +import org.crosswire.jsword.book.Books; + +import java.util.List; +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.Observable; +import rx.functions.Action1; +import rx.functions.Func1; + +public class InstalledManagerTest extends TestCase implements Injector { + ObjectGraph mObjectGraph; + + @Module(injects = {InstalledManager.class, + InstalledManagerTest.class}) + static class IMTestModules { + Injector i; + public IMTestModules(Injector i) { + this.i = i; + } + + @Provides @Singleton + Injector provideInjector() { + return this.i; + } + + @Provides @Singleton + Books provideInstalledBooks() { + return Books.installed(); + } + + @Provides + List provideInstalledBooksList(Books b) { + return b.getBooks(); + } + } + + @Inject Books installedBooks; + @Inject InstalledManager iM; + + @Override + public void inject(Object o) { + mObjectGraph.inject(o); + } + + public void setUp() throws Exception { + super.setUp(); + mObjectGraph = ObjectGraph.create(new IMTestModules(this)); + mObjectGraph.inject(this); + + //TODO: Guarantee that a book is installed. + } + + Observable getInstalledBooks() { + return Observable.from(installedBooks.getBooks()) + .filter(new Func1() { + @Override + public Boolean call(Book book) { + // Double check that the book is actually installed + return book.getDriver().isDeletable(book); + } + }); + } + + public void testIsInstalled() throws Exception { + final AtomicBoolean foundMismatch = new AtomicBoolean(false); + getInstalledBooks() + .subscribe(new Action1() { + @Override + public void call(Book book) { + if (!iM.isInstalled(book)) { + foundMismatch.set(true); + } + } + }); + assertFalse(foundMismatch.get()); + } + + /* + public void testRemoveBook() throws Exception { + } + */ +} \ No newline at end of file