mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-21 23:48:18 -05:00
Tests still fail, but look prettier!
This commit is contained in:
parent
b7198b984c
commit
f2a4ceceff
@ -6,17 +6,18 @@ import junit.framework.TestCase;
|
|||||||
|
|
||||||
import org.bspeice.minimalbible.Injector;
|
import org.bspeice.minimalbible.Injector;
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadManager;
|
import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadManager;
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent;
|
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.InstalledManager;
|
import org.bspeice.minimalbible.activity.downloader.manager.InstalledManager;
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
import org.crosswire.jsword.book.Books;
|
import org.crosswire.jsword.book.Books;
|
||||||
|
import org.crosswire.jsword.book.BooksEvent;
|
||||||
|
import org.crosswire.jsword.book.BooksListener;
|
||||||
import org.crosswire.jsword.book.install.InstallManager;
|
import org.crosswire.jsword.book.install.InstallManager;
|
||||||
import org.crosswire.jsword.book.install.Installer;
|
import org.crosswire.jsword.book.install.Installer;
|
||||||
import org.crosswire.jsword.book.sword.SwordBook;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@ -27,7 +28,6 @@ import dagger.Module;
|
|||||||
import dagger.ObjectGraph;
|
import dagger.ObjectGraph;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.functions.Action0;
|
|
||||||
import rx.functions.Action1;
|
import rx.functions.Action1;
|
||||||
import rx.functions.Func1;
|
import rx.functions.Func1;
|
||||||
|
|
||||||
@ -83,32 +83,25 @@ public class InstalledManagerTest extends TestCase implements Injector {
|
|||||||
mObjectGraph.inject(this);
|
mObjectGraph.inject(this);
|
||||||
|
|
||||||
// Guarantee something is installed
|
// Guarantee something is installed
|
||||||
getInstalledBooks()
|
int count = getInstalledBooks().count().toBlocking().first();
|
||||||
.count()
|
|
||||||
.subscribe(new Action1<Integer>() {
|
|
||||||
@Override
|
|
||||||
public void call(Integer count) {
|
|
||||||
if (count <= 0) {
|
|
||||||
Log.i("InstalledManagerTest", "Nothing installed!");
|
|
||||||
final AtomicBoolean isInstalled = new AtomicBoolean(false);
|
|
||||||
final Book toInstall = rM.getAvailableModulesFlattened().toBlocking().first();
|
|
||||||
bDM.installBook(toInstall);
|
|
||||||
bDM.getDownloadEvents()
|
|
||||||
.subscribe(new Action1<DLProgressEvent>() {
|
|
||||||
@Override
|
|
||||||
public void call(DLProgressEvent dlProgressEvent) {
|
|
||||||
if (dlProgressEvent.getProgress() == DLProgressEvent.PROGRESS_COMPLETE &&
|
|
||||||
dlProgressEvent.getB().getName().equals(toInstall.getName())) {
|
|
||||||
|
|
||||||
isInstalled.set(true);
|
if (count <= 0) {
|
||||||
}
|
Log.i("InstalledManagerTest", "Nothing installed!");
|
||||||
}
|
final Book toInstall = rM.getAvailableModulesFlattened()
|
||||||
});
|
.toBlocking().first();
|
||||||
await().atMost(30, TimeUnit.SECONDS)
|
bDM.installBook(toInstall);
|
||||||
.untilTrue(isInstalled);
|
|
||||||
|
await().atMost(30, TimeUnit.SECONDS)
|
||||||
|
.until(new Callable<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean call() throws Exception {
|
||||||
|
return installedBooks.getBooks()
|
||||||
|
.contains(toInstall);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
Log.e("setUp", Boolean.toString(toInstall.getDriver().isDeletable(toInstall)));
|
||||||
|
Log.e("setUp", "Found the book!: " + toInstall.getInitials());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<Book> getInstalledBooks() {
|
public Observable<Book> getInstalledBooks() {
|
||||||
@ -119,12 +112,6 @@ public class InstalledManagerTest extends TestCase implements Injector {
|
|||||||
*/
|
*/
|
||||||
// TODO: Guarantee that we return newly-installed books
|
// TODO: Guarantee that we return newly-installed books
|
||||||
return Observable.from(installedBooks.getBooks())
|
return Observable.from(installedBooks.getBooks())
|
||||||
.filter(new Func1<Book, Boolean>() {
|
|
||||||
@Override
|
|
||||||
public Boolean call(Book book) {
|
|
||||||
return book.getDriver().isDeletable(book);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.filter(new Func1<Book, Boolean>() {
|
.filter(new Func1<Book, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public Boolean call(Book book) {
|
public Boolean call(Book book) {
|
||||||
@ -157,30 +144,24 @@ public class InstalledManagerTest extends TestCase implements Injector {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void testRemoveBook() throws Exception {
|
public void testRemoveBook() throws Exception {
|
||||||
final AtomicBoolean isRemoved = new AtomicBoolean(false);
|
final Book book = getInstalledBooks().toBlocking().first();
|
||||||
getInstalledBooks()
|
|
||||||
.first()
|
|
||||||
.subscribe(new Action1<Book>() {
|
|
||||||
@Override
|
|
||||||
public void call(Book book) {
|
|
||||||
iM.removeBook(book);
|
|
||||||
|
|
||||||
// The AbstractBook returns false all the time, make sure we have
|
final AtomicBoolean didRemove = new AtomicBoolean(false);
|
||||||
// an actual implementation
|
|
||||||
Log.w("testRemoveBook", book.getInitials());
|
installedBooks.addBooksListener(new BooksListener() {
|
||||||
isRemoved.set(!book.getDriver().isDeletable(book) &&
|
@Override
|
||||||
book instanceof SwordBook);
|
public void bookAdded(BooksEvent ev) {
|
||||||
}
|
|
||||||
}, new Action1<Throwable>() {
|
}
|
||||||
@Override
|
@Override
|
||||||
public void call(Throwable throwable) {
|
public void bookRemoved(BooksEvent ev) {
|
||||||
fail(throwable.getLocalizedMessage());
|
if (ev.getBook().equals(book)) {
|
||||||
}
|
didRemove.set(true);
|
||||||
}, new Action0() {
|
}
|
||||||
@Override
|
}
|
||||||
public void call() {
|
});
|
||||||
assertTrue(isRemoved.get());
|
|
||||||
}
|
iM.removeBook(book);
|
||||||
});
|
await().untilTrue(didRemove);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user