Fix the tests.
Most of the failures were caused by proguard being more aggressive by the look
of it. Added some @VisibleForTesting's fixes those.
Also some failured caused by the move to a 2-pane UI breaking assumptions made
in the tests.
Dependand on change: Icb5c0302aa320575085b0258b478933cb10e9c6b
Change-Id: I3e0d53c3fb299d9b9b41f51e1b34b648a8e63d86
diff --git a/src/com/android/quicksearchbox/Config.java b/src/com/android/quicksearchbox/Config.java
index 1012385..6512199 100644
--- a/src/com/android/quicksearchbox/Config.java
+++ b/src/com/android/quicksearchbox/Config.java
@@ -52,7 +52,6 @@
private static final long MAX_STAT_AGE_MILLIS = 30 * DAY_MILLIS;
private static final int MIN_CLICKS_FOR_SOURCE_RANKING = 3;
- private static final int MAX_SHORTCUTS_RETURNED = MAX_PROMOTED_SUGGESTIONS;
private static final int NUM_WEB_CORPUS_THREADS = 2;
@@ -208,13 +207,6 @@
return MIN_CLICKS_FOR_SOURCE_RANKING;
}
- /**
- * The maximum number of shortcuts shown.
- */
- public int getMaxShortcutsReturned(){
- return MAX_SHORTCUTS_RETURNED;
- }
-
public int getNumWebCorpusThreads() {
return NUM_WEB_CORPUS_THREADS;
}
diff --git a/src/com/android/quicksearchbox/ListSuggestionCursor.java b/src/com/android/quicksearchbox/ListSuggestionCursor.java
index d2a6034..611fc4a 100644
--- a/src/com/android/quicksearchbox/ListSuggestionCursor.java
+++ b/src/com/android/quicksearchbox/ListSuggestionCursor.java
@@ -16,9 +16,10 @@
package com.android.quicksearchbox;
+import com.google.common.annotations.VisibleForTesting;
+
import android.database.DataSetObservable;
import android.database.DataSetObserver;
-import android.util.Log;
import java.util.ArrayList;
@@ -39,6 +40,7 @@
this(userQuery, DEFAULT_CAPACITY);
}
+ @VisibleForTesting
public ListSuggestionCursor(String userQuery, Suggestion...suggestions) {
this(userQuery, suggestions.length);
for (Suggestion suggestion : suggestions) {
diff --git a/src/com/android/quicksearchbox/NoLogger.java b/src/com/android/quicksearchbox/NoLogger.java
index b6b4f7f..cf0b8e6 100644
--- a/src/com/android/quicksearchbox/NoLogger.java
+++ b/src/com/android/quicksearchbox/NoLogger.java
@@ -16,12 +16,15 @@
package com.android.quicksearchbox;
+import com.google.common.annotations.VisibleForTesting;
+
import java.util.Collection;
import java.util.List;
/**
* Dummy {@link Logger} implementation.
*/
+@VisibleForTesting
public class NoLogger implements Logger {
public NoLogger() {
diff --git a/src/com/android/quicksearchbox/ShortcutCursor.java b/src/com/android/quicksearchbox/ShortcutCursor.java
index ae800d9..39a4a96 100644
--- a/src/com/android/quicksearchbox/ShortcutCursor.java
+++ b/src/com/android/quicksearchbox/ShortcutCursor.java
@@ -16,6 +16,8 @@
package com.android.quicksearchbox;
+import com.google.common.annotations.VisibleForTesting;
+
import android.os.Handler;
import android.util.Log;
@@ -52,6 +54,7 @@
mRefreshed = new HashSet<SuggestionCursor>();
}
+ @VisibleForTesting
public ShortcutCursor(String query, Handler uiThread,
ShortcutRefresher refresher, ShortcutRepository repository) {
this(query, null, uiThread, refresher, repository);
@@ -76,7 +79,7 @@
/**
* Refresh a shortcut from this cursor.
*
- * @param shortcut The shotrcut to refresh. Should be a shortcut taken from this cursor.
+ * @param shortcut The shortcut to refresh. Should be a shortcut taken from this cursor.
*/
public void refresh(Suggestion shortcut) {
mRefresher.refresh(shortcut, new ShortcutRefresher.Listener() {
diff --git a/tests/src/com/android/quicksearchbox/RankAwarePromoterTest.java b/tests/src/com/android/quicksearchbox/RankAwarePromoterTest.java
index 52ba9e6..850f39e 100644
--- a/tests/src/com/android/quicksearchbox/RankAwarePromoterTest.java
+++ b/tests/src/com/android/quicksearchbox/RankAwarePromoterTest.java
@@ -27,6 +27,7 @@
*/
@SmallTest
public class RankAwarePromoterTest extends AndroidTestCase {
+ public static final int NUM_SUGGESTIONS_ABOVE_KEYBOARD = 4;
public static final int MAX_PROMOTED_CORPORA = 3;
public static final int MAX_PROMOTED_SUGGESTIONS = 8;
public static final String TEST_QUERY = "query";
@@ -38,7 +39,12 @@
public void setUp() {
Corpora corpora = createMockCorpora(5, MAX_PROMOTED_CORPORA);
mRanker = new LexicographicalCorpusRanker(corpora);
- mPromoter = new RankAwarePromoter(new Config(mContext), corpora);
+ mPromoter = new RankAwarePromoter(new Config(mContext){
+ @Override
+ public int getNumSuggestionsAboveKeyboard() {
+ return NUM_SUGGESTIONS_ABOVE_KEYBOARD;
+ }
+ }, corpora);
}
public void testPromotesExpectedSuggestions() {
diff --git a/tests/src/com/android/quicksearchbox/ShortcutRepositoryTest.java b/tests/src/com/android/quicksearchbox/ShortcutRepositoryTest.java
index 7f0cbbe..08b73cf 100644
--- a/tests/src/com/android/quicksearchbox/ShortcutRepositoryTest.java
+++ b/tests/src/com/android/quicksearchbox/ShortcutRepositoryTest.java
@@ -69,6 +69,8 @@
static final Corpus CONTACTS_CORPUS = new MockCorpus(CONTACTS_SOURCE);
+ static final int MAX_SHORTCUTS = 8;
+
protected Config mConfig;
protected MockCorpora mCorpora;
protected MockExecutor mLogExecutor;
@@ -310,8 +312,7 @@
}
public void testMostRecentClickWinsEvenWithMoreThanLimitShortcuts() {
- // Create MaxShortcutsReturned shortcuts
- for (int i = 0; i < mConfig.getMaxShortcutsReturned(); i++) {
+ for (int i = 0; i < MAX_SHORTCUTS; i++) {
SuggestionData app = makeApp("TestApp" + i);
// Each of these shortcuts has two clicks
reportClick("app", app, NOW - 2);
@@ -641,18 +642,17 @@
}
public void testAppUpgradePromotesLowerRanked() {
- int maxShortcuts = mConfig.getMaxShortcutsReturned();
ListSuggestionCursor expected = new ListSuggestionCursor("a");
- for (int i = 0; i < maxShortcuts + 1; i++) {
+ for (int i = 0; i < MAX_SHORTCUTS + 1; i++) {
reportClick("app", mApp1, NOW);
}
expected.add(mApp1);
// Enough contact clicks to make one more shortcut than getMaxShortcutsReturned()
- for (int i = 0; i < maxShortcuts; i++) {
+ for (int i = 0; i < MAX_SHORTCUTS; i++) {
SuggestionData contact = makeContact("andy" + i);
- int numClicks = maxShortcuts - i; // use click count to get shortcuts in order
+ int numClicks = MAX_SHORTCUTS - i; // use click count to get shortcuts in order
for (int j = 0; j < numClicks; j++) {
reportClick("and", contact, NOW);
}
@@ -661,7 +661,7 @@
// Expect the app, and then all but one contact
assertShortcuts("app and all but one contact should be returned",
- "a", mAllowedCorpora, SuggestionCursorUtil.slice(expected, 0, maxShortcuts));
+ "a", mAllowedCorpora, SuggestionCursorUtil.slice(expected, 0, MAX_SHORTCUTS));
// Upgrade app corpus
MockCorpus upgradedCorpus = new MockCorpus(APP_SOURCE_V2);
@@ -671,7 +671,7 @@
List<Corpus> newAllowedCorpora = new ArrayList<Corpus>(mCorpora.getAllCorpora());
assertShortcuts("app shortcuts should be removed when the source was upgraded "
+ "and a contact should take its place",
- "a", newAllowedCorpora, SuggestionCursorUtil.slice(expected, 1, maxShortcuts));
+ "a", newAllowedCorpora, SuggestionCursorUtil.slice(expected, 1, MAX_SHORTCUTS));
}
public void testIrrelevantAppUpgrade() {