mirror of
https://github.com/MinimalBible/MinimalBible-Legacy
synced 2024-11-16 04:58:26 -05:00
Get the unit tests passing again
Note: I need to write more. Lots more.
This commit is contained in:
parent
04fe4d13b4
commit
e945ef51a7
@ -118,11 +118,7 @@ public class BookListFragment extends BaseFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Listen for the books!
|
// Listen for the books!
|
||||||
refreshManager.getAvailableModules()
|
refreshManager.getAvailableModulesFlattened()
|
||||||
// First flatten the Map to its lists
|
|
||||||
.flatMap((books) -> Observable.from(books.values()))
|
|
||||||
// Then flatten the lists
|
|
||||||
.flatMap(Observable::from)
|
|
||||||
.filter((book) -> book.getBookCategory() ==
|
.filter((book) -> book.getBookCategory() ==
|
||||||
BookCategory.fromString(getArguments().getString(ARG_BOOK_CATEGORY)))
|
BookCategory.fromString(getArguments().getString(ARG_BOOK_CATEGORY)))
|
||||||
// Repack all the books
|
// Repack all the books
|
||||||
|
@ -56,6 +56,7 @@ public class BookDownloadManager implements WorkListener, BooksListener {
|
|||||||
BookDownloadThread dlThread = dlThreadProvider.get();
|
BookDownloadThread dlThread = dlThreadProvider.get();
|
||||||
dlThread.downloadBook(b);
|
dlThread.downloadBook(b);
|
||||||
addJob(BookDownloadThread.getJobId(b), b);
|
addJob(BookDownloadThread.getJobId(b), b);
|
||||||
|
downloadEvents.onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_BEGINNING, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addJob(String jobId, Book b) {
|
public void addJob(String jobId, Book b) {
|
||||||
|
@ -63,6 +63,9 @@ public class InstalledManager implements BooksListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeBook(Book b) {
|
public void removeBook(Book b) {
|
||||||
|
if (installedBooks == null) {
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// This worked in the past, but isn't now...
|
// This worked in the past, but isn't now...
|
||||||
// installedBooks.remove(b);
|
// installedBooks.remove(b);
|
||||||
|
@ -61,6 +61,14 @@ public class RefreshManager {
|
|||||||
return availableModules;
|
return availableModules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Observable<Book> getAvailableModulesFlattened() {
|
||||||
|
return availableModules
|
||||||
|
// First flatten the Map to its lists
|
||||||
|
.flatMap((books) -> Observable.from(books.values()))
|
||||||
|
// Then flatten the lists
|
||||||
|
.flatMap(Observable::from);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cached book list
|
* Get the cached book list
|
||||||
* @return The cached book list, or null
|
* @return The cached book list, or null
|
||||||
@ -90,7 +98,7 @@ public class RefreshManager {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
.take(1)
|
.first()
|
||||||
.map(element -> element.entrySet().iterator().next().getKey());
|
.map(element -> element.entrySet().iterator().next().getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,24 +1,35 @@
|
|||||||
package org.bspeice.minimalbible.test;
|
package org.bspeice.minimalbible.test;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.bspeice.minimalbible.MinimalBible;
|
import org.bspeice.minimalbible.MinimalBible;
|
||||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
import org.bspeice.minimalbible.MinimalBibleModules;
|
||||||
|
import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadManager;
|
||||||
|
import org.bspeice.minimalbible.activities.downloader.manager.DLProgressEvent;
|
||||||
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
|
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
|
||||||
import org.bspeice.minimalbible.activities.downloader.manager.InstalledManager;
|
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.Book;
|
||||||
import org.crosswire.jsword.book.BookException;
|
import org.crosswire.jsword.book.BookException;
|
||||||
import org.crosswire.jsword.book.Books;
|
import org.crosswire.jsword.book.Books;
|
||||||
|
import org.crosswire.jsword.book.install.InstallException;
|
||||||
import org.crosswire.jsword.book.install.Installer;
|
import org.crosswire.jsword.book.install.Installer;
|
||||||
import org.crosswire.jsword.passage.NoSuchKeyException;
|
import org.crosswire.jsword.passage.NoSuchKeyException;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.ObjectGraph;
|
import dagger.ObjectGraph;
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
import static com.jayway.awaitility.Awaitility.await;
|
import static com.jayway.awaitility.Awaitility.await;
|
||||||
|
|
||||||
@ -33,6 +44,8 @@ public class DownloadActivityTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
@Inject DownloadManager dm;
|
@Inject DownloadManager dm;
|
||||||
@Inject InstalledManager im;
|
@Inject InstalledManager im;
|
||||||
|
@Inject RefreshManager rm;
|
||||||
|
@Inject BookDownloadManager bdm;
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MinimalBible application = MinimalBible.getApplication();
|
MinimalBible application = MinimalBible.getApplication();
|
||||||
@ -45,42 +58,6 @@ public class DownloadActivityTest extends InstrumentationTestCase {
|
|||||||
assertEquals(true, true);
|
assertEquals(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* When we start a download, make sure a progress event of 0 is triggered.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
public void testInitialProgressEventOnDownload() throws InterruptedException {
|
|
||||||
final CountDownLatch signal = new CountDownLatch(1);
|
|
||||||
|
|
||||||
// Need to make sure we've refreshed the refreshmanager first
|
|
||||||
Installer i = (Installer) dm.getInstallers().values().toArray()[0];
|
|
||||||
final Book testBook = i.getBooks().get(0);
|
|
||||||
await().atMost(30, TimeUnit.SECONDS).until(new Callable<Boolean>() {
|
|
||||||
@Override
|
|
||||||
public Boolean call() throws Exception {
|
|
||||||
return rm.installerFromBook(testBook) != null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// And wait for the actual download
|
|
||||||
dm.getDownloadBus().register(new Object() {
|
|
||||||
public void onEvent(DLProgressEvent event) {
|
|
||||||
if (event.getProgress() == 0) {
|
|
||||||
signal.countDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
BookDownloadThread thread = bookDownloadThreadProvider.get();
|
|
||||||
thread.downloadBook(testBook);
|
|
||||||
|
|
||||||
signal.await(10, TimeUnit.SECONDS);
|
|
||||||
if (signal.getCount() != 0) {
|
|
||||||
fail("Event did not trigger!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that we can successfully download and remove a book
|
* Test that we can successfully download and remove a book
|
||||||
*/
|
*/
|
||||||
@ -88,7 +65,9 @@ public class DownloadActivityTest extends InstrumentationTestCase {
|
|||||||
// Install a book
|
// Install a book
|
||||||
Installer i = (Installer) dm.getInstallers().values().toArray()[0];
|
Installer i = (Installer) dm.getInstallers().values().toArray()[0];
|
||||||
final Book testBook = i.getBooks().get(0);
|
final Book testBook = i.getBooks().get(0);
|
||||||
await().atMost(30, TimeUnit.SECONDS).until(() -> Books.installed().getBooks().contains(testBook));
|
bdm.installBook(testBook);
|
||||||
|
await().atMost(30, TimeUnit.SECONDS)
|
||||||
|
.until(() -> Books.installed().getBooks().contains(testBook));
|
||||||
|
|
||||||
// Validate that we can actually do something with the book
|
// Validate that we can actually do something with the book
|
||||||
// TODO: Validate that the book exists on the filesystem too
|
// TODO: Validate that the book exists on the filesystem too
|
||||||
@ -103,7 +82,8 @@ public class DownloadActivityTest extends InstrumentationTestCase {
|
|||||||
// Remove the book and make sure it's gone
|
// Remove the book and make sure it's gone
|
||||||
// TODO: Validate that the book is off the filesystem
|
// TODO: Validate that the book is off the filesystem
|
||||||
im.removeBook(testBook);
|
im.removeBook(testBook);
|
||||||
assertFalse(Books.installed().getBooks().contains(testBook));
|
await().atMost(10, TimeUnit.SECONDS)
|
||||||
|
.until(() -> !Books.installed().getBooks().contains(testBook));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user