mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-04 23:28:19 -05:00
Boundary refactor, and add some tests
This commit is contained in:
parent
18d3620da3
commit
05d2d006e4
@ -0,0 +1,52 @@
|
||||
package org.bspeice.minimalbible.activity.downloader
|
||||
|
||||
import org.jetbrains.spek.api.Spek
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* Created by bspeice on 11/22/14.
|
||||
*/
|
||||
|
||||
class BookListFragmentSpek : Spek() {{
|
||||
|
||||
given("A BookListFragment with showDialog() mocked out") {
|
||||
class TestableFragment : BookListFragment() {
|
||||
var condition = false
|
||||
|
||||
override fun showDialog() {
|
||||
condition = true
|
||||
}
|
||||
}
|
||||
|
||||
val fragment = TestableFragment()
|
||||
|
||||
on("attempting to display modules with the dialog not shown already") {
|
||||
fragment.displayModules(false)
|
||||
|
||||
it("should show the download dialog") {
|
||||
assertTrue(fragment.condition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
given("a BookListFragment with displayLanguageSpinner() mocked out") {
|
||||
class TestableFragment : BookListFragment() {
|
||||
var condition = false
|
||||
|
||||
override fun displayLanguageSpinner() {
|
||||
condition = true
|
||||
}
|
||||
}
|
||||
|
||||
val fragment = TestableFragment()
|
||||
|
||||
on("attempting to display modules with the dialog already shown") {
|
||||
fragment.displayModules(true)
|
||||
|
||||
it("should show the available languages spinner") {
|
||||
assertTrue(fragment.condition)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package org.bspeice.minimalbible.test.activity.downloader;
|
||||
|
||||
import org.bspeice.minimalbible.MBTestCase;
|
||||
import org.bspeice.minimalbible.activity.downloader.BookListFragment;
|
||||
import org.crosswire.common.util.Language;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.BookCategory;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.functions.Action1;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class BookListFragmentTest extends MBTestCase {
|
||||
|
||||
public void testBooksByLanguage() throws Exception {
|
||||
BookCategory bibleCategory = BookCategory.BIBLE;
|
||||
BookCategory dictionaryCategory = BookCategory.DICTIONARY;
|
||||
Language russianLanguage = new Language("ru");
|
||||
Language englishLanguage = new Language("en");
|
||||
|
||||
final Book russianBible = Mockito.mock(Book.class);
|
||||
when(russianBible.getBookCategory()).thenReturn(bibleCategory);
|
||||
when(russianBible.getLanguage()).thenReturn(russianLanguage);
|
||||
|
||||
final Book englishBible = Mockito.mock(Book.class);
|
||||
when(englishBible.getBookCategory()).thenReturn(bibleCategory);
|
||||
when(englishBible.getLanguage()).thenReturn(englishLanguage);
|
||||
|
||||
final Book englishDictionary = Mockito.mock(Book.class);
|
||||
when(englishDictionary.getBookCategory()).thenReturn(dictionaryCategory);
|
||||
when(englishDictionary.getLanguage()).thenReturn(englishLanguage);
|
||||
|
||||
Observable<Book> mockBooks = Observable.just(russianBible, englishBible,
|
||||
englishDictionary);
|
||||
|
||||
// Since we're not testing lifecycle here, don't worry about newInstance()
|
||||
TestableBookListFragment fragment = new TestableBookListFragment();
|
||||
|
||||
fragment.booksByLanguage(mockBooks, englishLanguage, bibleCategory)
|
||||
.subscribe(new Action1<Book>() {
|
||||
@Override
|
||||
public void call(Book book) {
|
||||
assertEquals(englishBible, book);
|
||||
}
|
||||
});
|
||||
fragment.booksByLanguage(mockBooks, russianLanguage, bibleCategory)
|
||||
.subscribe(new Action1<Book>() {
|
||||
@Override
|
||||
public void call(Book book) {
|
||||
assertEquals(russianBible, book);
|
||||
}
|
||||
});
|
||||
fragment.booksByLanguage(mockBooks, englishLanguage, dictionaryCategory)
|
||||
.subscribe(new Action1<Book>() {
|
||||
@Override
|
||||
public void call(Book book) {
|
||||
assertEquals(englishDictionary, book);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static class TestableBookListFragment extends BookListFragment {
|
||||
@Override
|
||||
public Observable<Book> booksByLanguage(Observable<Book> books, Language language, BookCategory category) {
|
||||
return super.booksByLanguage(books, language, category);
|
||||
}
|
||||
}
|
||||
}
|
@ -93,26 +93,32 @@ public class BookListFragment extends BaseFragment {
|
||||
.getString(ARG_BOOK_CATEGORY));
|
||||
}
|
||||
|
||||
void displayModules() {
|
||||
displayModules(downloadPrefs.hasShownDownloadDialog());
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger the functionality to display a list of modules. Prompts user if downloading
|
||||
* from the internet is allowable.
|
||||
*/
|
||||
void displayModules() {
|
||||
boolean dialogDisplayed = downloadPrefs.hasShownDownloadDialog();
|
||||
|
||||
if (!dialogDisplayed) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
DownloadDialogListener dialogListener = new DownloadDialogListener();
|
||||
builder.setMessage(
|
||||
"About to contact servers to download content. Continue?")
|
||||
.setPositiveButton("Yes", dialogListener)
|
||||
.setNegativeButton("No", dialogListener)
|
||||
.setCancelable(false).show();
|
||||
} else {
|
||||
void displayModules(boolean dialogDisplayed) {
|
||||
if (!dialogDisplayed) {
|
||||
showDialog();
|
||||
} else {
|
||||
displayLanguageSpinner();
|
||||
}
|
||||
}
|
||||
|
||||
void showDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
DownloadDialogListener dialogListener = new DownloadDialogListener();
|
||||
builder.setMessage(
|
||||
"About to contact servers to download content. Continue?")
|
||||
.setPositiveButton("Yes", dialogListener)
|
||||
.setNegativeButton("No", dialogListener)
|
||||
.setCancelable(false).show();
|
||||
}
|
||||
|
||||
void displayLanguageSpinner() {
|
||||
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(this.getActivity(),
|
||||
android.R.layout.simple_spinner_item,
|
||||
|
Loading…
Reference in New Issue
Block a user