mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-21 23:48:18 -05:00
Can't fix tests, fix application instead
See documentation for more information on why I can't fix the tests to actually guarantee anything.
This commit is contained in:
parent
f2a4ceceff
commit
d685beaae6
@ -17,8 +17,6 @@ import org.crosswire.jsword.book.install.Installer;
|
|||||||
|
|
||||||
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.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -31,8 +29,13 @@ import rx.Observable;
|
|||||||
import rx.functions.Action1;
|
import rx.functions.Action1;
|
||||||
import rx.functions.Func1;
|
import rx.functions.Func1;
|
||||||
|
|
||||||
import static com.jayway.awaitility.Awaitility.await;
|
/**
|
||||||
|
* Test the InstalledManager
|
||||||
|
* Currently due to limitations with JSword (which I'm currently investigating) you can't delete
|
||||||
|
* books without restarting the application. That is, if you install it, there must be a restart
|
||||||
|
* in between it being deleted. Unfortunately, that means that this TestCase really can't guarantee
|
||||||
|
* much, since I can't install a book at runtime to be removed.
|
||||||
|
*/
|
||||||
public class InstalledManagerTest extends TestCase implements Injector {
|
public class InstalledManagerTest extends TestCase implements Injector {
|
||||||
ObjectGraph mObjectGraph;
|
ObjectGraph mObjectGraph;
|
||||||
|
|
||||||
@ -68,8 +71,6 @@ public class InstalledManagerTest extends TestCase implements Injector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject InstalledManager iM;
|
@Inject InstalledManager iM;
|
||||||
@Inject BookDownloadManager bDM;
|
|
||||||
@Inject RefreshManager rM;
|
|
||||||
@Inject Books installedBooks;
|
@Inject Books installedBooks;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -82,41 +83,26 @@ public class InstalledManagerTest extends TestCase implements Injector {
|
|||||||
mObjectGraph = ObjectGraph.create(new IMTestModules(this));
|
mObjectGraph = ObjectGraph.create(new IMTestModules(this));
|
||||||
mObjectGraph.inject(this);
|
mObjectGraph.inject(this);
|
||||||
|
|
||||||
// Guarantee something is installed
|
// Unfortunately, unless something is already installed, we can't actually remove anything
|
||||||
int count = getInstalledBooks().count().toBlocking().first();
|
int count = getInstalledBooks().count().toBlocking().first();
|
||||||
|
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
Log.i("InstalledManagerTest", "Nothing installed!");
|
Log.w("InstalledManagerTest", "No books available, test can not guarantee anything.");
|
||||||
final Book toInstall = rM.getAvailableModulesFlattened()
|
|
||||||
.toBlocking().first();
|
|
||||||
bDM.installBook(toInstall);
|
|
||||||
|
|
||||||
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() {
|
||||||
/* The golden copy for testing of what's installed.
|
/* The golden copy for testing of what's installed.
|
||||||
NOTE: Currently, I have yet to find a guaranteed way to know if a book
|
NOTE: Currently, I have yet to find a guaranteed way to immediately delete
|
||||||
is installed or not. So while the test cases are semantically correct,
|
a book that is freshly installed. While the tests are semantically correct, unfortunately,
|
||||||
nothing is actually proven until I can guarantee this list is correct.
|
this test case specifically doesn't guarantee much of anything.
|
||||||
*/
|
*/
|
||||||
// TODO: Guarantee that we return newly-installed books
|
|
||||||
return Observable.from(installedBooks.getBooks())
|
return Observable.from(installedBooks.getBooks())
|
||||||
.filter(new Func1<Book, Boolean>() {
|
.filter(new Func1<Book, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public Boolean call(Book book) {
|
public Boolean call(Book book) {
|
||||||
// Not sure why, but this book can't be deleted...
|
// Not sure why, but this book can't be deleted...
|
||||||
return !book.getInitials().equals("ot1nt2");
|
return book.getDriver().isDeletable(book);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -162,6 +148,8 @@ public class InstalledManagerTest extends TestCase implements Injector {
|
|||||||
});
|
});
|
||||||
|
|
||||||
iM.removeBook(book);
|
iM.removeBook(book);
|
||||||
await().untilTrue(didRemove);
|
if (!didRemove.get()) {
|
||||||
|
Log.w("testRemoveBook", "Could not remove book, not necessarily fatal.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,11 @@
|
|||||||
package org.bspeice.minimalbible.activity.downloader;
|
package org.bspeice.minimalbible.activity.downloader;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.todddavies.components.progressbar.ProgressWheel;
|
import com.todddavies.components.progressbar.ProgressWheel;
|
||||||
|
|
||||||
@ -15,6 +17,7 @@ import org.bspeice.minimalbible.activity.downloader.manager.InstalledManager;
|
|||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.InjectView;
|
import butterknife.InjectView;
|
||||||
@ -45,6 +48,8 @@ public class BookItemHolder {
|
|||||||
BookDownloadManager bookDownloadManager;
|
BookDownloadManager bookDownloadManager;
|
||||||
@Inject
|
@Inject
|
||||||
InstalledManager installedManager;
|
InstalledManager installedManager;
|
||||||
|
@Inject @Named("DownloadActivityContext")
|
||||||
|
Context ctx;
|
||||||
|
|
||||||
private final Book b;
|
private final Book b;
|
||||||
private Subscription subscription;
|
private Subscription subscription;
|
||||||
@ -90,8 +95,13 @@ public class BookItemHolder {
|
|||||||
public void onDownloadItem(View v) {
|
public void onDownloadItem(View v) {
|
||||||
if (installedManager.isInstalled(b)) {
|
if (installedManager.isInstalled(b)) {
|
||||||
// Remove the book
|
// Remove the book
|
||||||
installedManager.removeBook(b);
|
boolean didRemove = installedManager.removeBook(b);
|
||||||
|
if (didRemove) {
|
||||||
isDownloaded.setImageResource(R.drawable.ic_action_download);
|
isDownloaded.setImageResource(R.drawable.ic_action_download);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(ctx, "Unable to remove book, might need to restart the application."
|
||||||
|
, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
bookDownloadManager.installBook(this.b);
|
bookDownloadManager.installBook(this.b);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.bspeice.minimalbible.activity.downloader;
|
package org.bspeice.minimalbible.activity.downloader;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import org.bspeice.minimalbible.Injector;
|
import org.bspeice.minimalbible.Injector;
|
||||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
import org.bspeice.minimalbible.MinimalBibleModules;
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadManager;
|
import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadManager;
|
||||||
@ -59,6 +61,16 @@ public class DownloadActivityModules {
|
|||||||
return activity;
|
return activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide the context for the DownloadActivity. We name it so that we don't have to
|
||||||
|
* \@Provides a specific class, but can keep track of what exactly we mean by "Context"
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Provides @Singleton @Named("DownloadActivityContext")
|
||||||
|
Context provideActivityContext() {
|
||||||
|
return activity;
|
||||||
|
}
|
||||||
|
|
||||||
@Provides @Singleton
|
@Provides @Singleton
|
||||||
BookDownloadManager provideBookDownloadManager() {
|
BookDownloadManager provideBookDownloadManager() {
|
||||||
return new BookDownloadManager(activity);
|
return new BookDownloadManager(activity);
|
||||||
|
@ -62,14 +62,23 @@ public class InstalledManager implements BooksListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeBook(Book b) {
|
/**
|
||||||
|
* Remove a book from being installed.
|
||||||
|
* Currently only supports books that have been installed outside the current application run.
|
||||||
|
* Not quite sure why this is, but And-Bible exhibits the same behavior.
|
||||||
|
* @param b The book to remove
|
||||||
|
* @return Whether the book was removed.
|
||||||
|
*/
|
||||||
|
public boolean removeBook(Book b) {
|
||||||
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);
|
||||||
Book realBook = installedBooks.getBook(b.getInitials());
|
Book realBook = installedBooks.getBook(b.getInitials());
|
||||||
b.getDriver().delete(realBook);
|
b.getDriver().delete(realBook);
|
||||||
|
return true;
|
||||||
} catch (BookException e) {
|
} catch (BookException e) {
|
||||||
Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage());
|
Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,4 +1,4 @@
|
|||||||
#Sun Jul 06 17:56:45 EDT 2014
|
#Sat Jul 19 23:18:06 EDT 2014
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
Loading…
Reference in New Issue
Block a user