Fix library test content matcher

This commit is contained in:
mhutti1 2017-12-04 20:20:08 +00:00 committed by Isaac Hutt
parent 8c98e885d8
commit b9930252e1
3 changed files with 18 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package org.kiwix.kiwixmobile.testutils; package org.kiwix.kiwixmobile.testutils;
import android.Manifest; import android.Manifest;
import android.app.LauncherActivity;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
@ -42,13 +43,17 @@ public class TestUtils {
} }
public static Matcher<Object> withContent(final String content) { public static Matcher<Object> withContent(final String content) {
return new BoundedMatcher<Object, Book>(Book.class) { return new BoundedMatcher<Object, Object>(Object.class) {
@Override @Override
public boolean matchesSafely(Book myObj) { public boolean matchesSafely(Object myObj) {
if (myObj.getUrl() != null) { if (!(myObj instanceof Book)) {
return myObj.getUrl().contains(content); return false;
}
Book book = (Book) myObj;
if (book.getUrl() != null) {
return book.getUrl().contains(content);
} else { } else {
return myObj.file.getPath().contains(content); return book.file.getPath().contains(content);
} }
} }

View File

@ -107,7 +107,7 @@ public class LibraryAdapter extends BaseAdapter {
@Override @Override
public Object getItem(int i) { public Object getItem(int i) {
return listItems.get(i); return listItems.get(i).data;
} }
@Override @Override
@ -118,6 +118,9 @@ public class LibraryAdapter extends BaseAdapter {
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder; ViewHolder holder;
if (position + 1 >= listItems.size()) {
return convertView;
}
ListItem item = listItems.get(position); ListItem item = listItems.get(position);
if (item.type == LIST_ITEM_TYPE_BOOK) { if (item.type == LIST_ITEM_TYPE_BOOK) {
@ -248,9 +251,9 @@ public class LibraryAdapter extends BaseAdapter {
.filter(book -> !LibraryFragment.downloadingBooks.contains(book)) .filter(book -> !LibraryFragment.downloadingBooks.contains(book))
.toList().toBlocking().single(); .toList().toBlocking().single();
listItems.add(new ListItem("In your language:", LIST_ITEM_TYPE_DIVIDER)); listItems.add(new ListItem(context.getResources().getString(R.string.your_languages), LIST_ITEM_TYPE_DIVIDER));
addBooks(selectedLanguages); addBooks(selectedLanguages);
listItems.add(new ListItem("In other languages:", LIST_ITEM_TYPE_DIVIDER)); listItems.add(new ListItem(context.getResources().getString(R.string.other_languages), LIST_ITEM_TYPE_DIVIDER));
addBooks(unselectedLanguages); addBooks(unselectedLanguages);
} else { } else {
List<Book> selectedLanguages = Observable.from(allBooks) List<Book> selectedLanguages = Observable.from(allBooks)

View File

@ -187,4 +187,6 @@
<string name="external_link_popup_dialog_title">Entering External Link</string> <string name="external_link_popup_dialog_title">Entering External Link</string>
<string name="external_link_popup_dialog_message">You are entering an external link. This could lead to additional costs for data transfer or will just not work when you are offline. Do you want to continue?</string> <string name="external_link_popup_dialog_message">You are entering an external link. This could lead to additional costs for data transfer or will just not work when you are offline. Do you want to continue?</string>
<string name="do_not_ask_anymore">Do not ask anymore</string> <string name="do_not_ask_anymore">Do not ask anymore</string>
<string name="your_languages">Selected languages:</string>
<string name="other_languages">Other languages:</string>
</resources> </resources>