From 5a2eee49d5a1e00306750339c27ee9a1e3173d40 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Wed, 4 Jun 2014 21:53:53 -0400 Subject: [PATCH] Add code to test installing and removing books The test was successful on the first try. I don't know if I should be scared about that. --- .../test/DownloadActivityTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java b/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java index 3f01068..1052da8 100644 --- a/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java +++ b/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java @@ -7,9 +7,13 @@ import org.bspeice.minimalbible.MinimalBibleModules; import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadThread; import org.bspeice.minimalbible.activities.downloader.manager.DLProgressEvent; import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager; +import org.bspeice.minimalbible.activities.downloader.manager.InstalledManager; import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager; import org.crosswire.jsword.book.Book; +import org.crosswire.jsword.book.BookException; +import org.crosswire.jsword.book.Books; import org.crosswire.jsword.book.install.Installer; +import org.crosswire.jsword.passage.NoSuchKeyException; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; @@ -33,6 +37,7 @@ public class DownloadActivityTest extends InstrumentationTestCase { public static class DownloadActivityTestModule {} @Inject DownloadManager dm; + @Inject InstalledManager im; @Inject Provider bookDownloadThreadProvider; @Inject RefreshManager rm; @@ -80,4 +85,34 @@ public class DownloadActivityTest extends InstrumentationTestCase { } } + /** + * Test that we can successfully download and remove a book + */ + public void testInstallAndRemoveBook() { + // Install a book + Installer i = (Installer) dm.getInstallers().values().toArray()[0]; + final Book testBook = i.getBooks().get(0); + await().atMost(30, TimeUnit.SECONDS).until(new Callable() { + @Override + public Boolean call() throws Exception { + return Books.installed().getBooks().contains(testBook); + } + }); + + // Validate that we can actually do something with the book + // TODO: Validate that the book exists on the filesystem too + try { + assertNotNull(testBook.getRawText(testBook.getKey("Gen 1:1"))); + } catch (BookException e) { + fail(e.getMessage()); + } catch (NoSuchKeyException e) { + fail(e.getMessage()); + } + + // Remove the book and make sure it's gone + // TODO: Validate that the book is off the filesystem + im.removeBook(testBook); + assertFalse(Books.installed().getBooks().contains(testBook)); + } + }