Clean and make more strict the InstalledManager tests

Unfortunately, they're currently always going to succeed. I'm having issues with the API not giving me a fresh list of what is installed.
This commit is contained in:
Bradlee Speice
2014-07-19 00:29:27 -04:00
parent d6d52cea04
commit 46e1285b61
3 changed files with 117 additions and 20 deletions

View File

@ -14,6 +14,8 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import rx.Observable;
/**
* Manager to keep track of which books have been installed
*/
@ -28,6 +30,7 @@ public class InstalledManager implements BooksListener {
@Inject
InstalledManager(Injector injector) {
injector.inject(this);
installedBooksList.addAll(installedBooks.getBooks());
installedBooks.addBooksListener(this);
}
@ -35,6 +38,12 @@ public class InstalledManager implements BooksListener {
return installedBooksList.contains(b);
}
public Observable<Book> getInstalledBooks() {
// This method is needed to provide a fresher copy of what's installed
// than Books.getInstalled() does.
return Observable.from(installedBooksList);
}
@Override
public void bookAdded(BooksEvent booksEvent) {
Log.d(TAG, "Book added: " + booksEvent.getBook().toString());
@ -54,16 +63,13 @@ public class InstalledManager implements BooksListener {
}
public void removeBook(Book b) {
// Not sure why we need to call this multiple times, but...
while (Books.installed().getBooks().contains(b)) {
try {
// This worked in the past, but isn't now...
// installedBooks.remove(b);
Book realBook = installedBooks.getBook(b.getInitials());
b.getDriver().delete(realBook);
} catch (BookException e) {
Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage());
}
try {
// This worked in the past, but isn't now...
// installedBooks.remove(b);
Book realBook = installedBooks.getBook(b.getInitials());
b.getDriver().delete(realBook);
} catch (BookException e) {
Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage());
}
}
}

View File

@ -52,7 +52,9 @@ public class RefreshManager {
/**
* Do the work of kicking off the AsyncTask to refresh books, and make sure we know
* when it's done.
* TODO: Should I have a better way of scheduling than Schedulers.io()?
* NOTE: This code assigns its own thread. This is because we are called privately, and
* don't want to expose this method. I don't like hiding the side effects like this, but
* in this case I'm making an exception.
*/
private Observable<Map<Installer, List<Book>>> refreshModules() {
if (availableModules == null) {