From 9637de5e4c31ef19ae7bbca8c19b3d34f692353a Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 28 Jul 2016 11:15:23 +1000 Subject: [PATCH] Make ignored app tests actually test code in use. The test was using a `findIgnored` method in `AppProvider`, which only existed for the purpose of testing. The test has been changed to instead check for apps which would end up in the "can update" list (which is really where the "ignored" apps are useful). --- .../org/fdroid/fdroid/data/AppProvider.java | 30 ++++--------------- .../fdroid/data/AppPrefsProviderTest.java | 3 +- .../fdroid/fdroid/data/AppProviderTest.java | 28 ++++++++++------- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/data/AppProvider.java b/app/src/main/java/org/fdroid/fdroid/data/AppProvider.java index 8ff64b039..4e90d4550 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/AppProvider.java +++ b/app/src/main/java/org/fdroid/fdroid/data/AppProvider.java @@ -59,12 +59,6 @@ public class AppProvider extends FDroidProvider { return cursorToList(cursor); } - public static List findIgnored(Context context, String[] projection) { - final Uri uri = AppProvider.getIgnoredUri(); - Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); - return cursorToList(cursor); - } - static List cursorToList(Cursor cursor) { int knownAppCount = cursor != null ? cursor.getCount() : 0; List apps = new ArrayList<>(knownAppCount); @@ -154,6 +148,10 @@ public class AppProvider extends FDroidProvider { final Uri fromUpstream = calcAppDetailsFromIndexUri(); context.getContentResolver().update(fromUpstream, null, null, null); } + + public static List findCanUpdate(Context context, String[] projection) { + return cursorToList(context.getContentResolver().query(AppProvider.getCanUpdateUri(), projection, null, null, null)); + } } /** @@ -406,7 +404,6 @@ public class AppProvider extends FDroidProvider { private static final String PATH_RECENTLY_UPDATED = "recentlyUpdated"; private static final String PATH_NEWLY_ADDED = "newlyAdded"; private static final String PATH_CATEGORY = "category"; - private static final String PATH_IGNORED = "ignored"; private static final String PATH_CALC_APP_DETAILS_FROM_INDEX = "calcDetailsFromIndex"; private static final String PATH_REPO = "repo"; @@ -417,8 +414,7 @@ public class AppProvider extends FDroidProvider { private static final int RECENTLY_UPDATED = NO_APKS + 1; private static final int NEWLY_ADDED = RECENTLY_UPDATED + 1; private static final int CATEGORY = NEWLY_ADDED + 1; - private static final int IGNORED = CATEGORY + 1; - private static final int CALC_APP_DETAILS_FROM_INDEX = IGNORED + 1; + private static final int CALC_APP_DETAILS_FROM_INDEX = CATEGORY + 1; private static final int REPO = CALC_APP_DETAILS_FROM_INDEX + 1; private static final int SEARCH_REPO = REPO + 1; private static final int SEARCH_INSTALLED = SEARCH_REPO + 1; @@ -427,7 +423,6 @@ public class AppProvider extends FDroidProvider { static { MATCHER.addURI(getAuthority(), null, CODE_LIST); MATCHER.addURI(getAuthority(), PATH_CALC_APP_DETAILS_FROM_INDEX, CALC_APP_DETAILS_FROM_INDEX); - MATCHER.addURI(getAuthority(), PATH_IGNORED, IGNORED); MATCHER.addURI(getAuthority(), PATH_RECENTLY_UPDATED, RECENTLY_UPDATED); MATCHER.addURI(getAuthority(), PATH_NEWLY_ADDED, NEWLY_ADDED); MATCHER.addURI(getAuthority(), PATH_CATEGORY + "/*", CATEGORY); @@ -454,10 +449,6 @@ public class AppProvider extends FDroidProvider { return Uri.withAppendedPath(getContentUri(), PATH_NEWLY_ADDED); } - public static Uri getIgnoredUri() { - return Uri.withAppendedPath(getContentUri(), PATH_IGNORED); - } - private static Uri calcAppDetailsFromIndexUri() { return Uri.withAppendedPath(getContentUri(), PATH_CALC_APP_DETAILS_FROM_INDEX); } @@ -636,13 +627,6 @@ public class AppProvider extends FDroidProvider { return new AppQuerySelection(selection, args); } - private AppQuerySelection queryIgnored() { - final String table = getTableName(); - final String selection = "COALESCE(prefs." + AppPrefsTable.Cols.IGNORE_ALL_UPDATES + ", 0) = 1 OR " + - "COALESCE(prefs." + AppPrefsTable.Cols.IGNORE_THIS_UPDATE + ", 0) >= " + table + "." + Cols.SUGGESTED_VERSION_CODE; - return new AppQuerySelection(selection).requireLeftJoinPrefs(); - } - private AppQuerySelection queryExcludeSwap() { // fdroid_repo will have null fields if the LEFT JOIN didn't resolve, e.g. due to there // being no apks for the app in the result set. In that case, we can't tell if it is from @@ -751,10 +735,6 @@ public class AppProvider extends FDroidProvider { selection = selection.add(queryNoApks()); break; - case IGNORED: - selection = selection.add(queryIgnored()); - break; - case CATEGORY: selection = selection.add(queryCategory(uri.getLastPathSegment())); includeSwap = false; diff --git a/app/src/test/java/org/fdroid/fdroid/data/AppPrefsProviderTest.java b/app/src/test/java/org/fdroid/fdroid/data/AppPrefsProviderTest.java index fb42642a8..128f52cb2 100644 --- a/app/src/test/java/org/fdroid/fdroid/data/AppPrefsProviderTest.java +++ b/app/src/test/java/org/fdroid/fdroid/data/AppPrefsProviderTest.java @@ -16,7 +16,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; -@Config(constants = BuildConfig.class, application = Application.class) +// TODO: Use sdk=24 when Robolectric supports this +@Config(constants = BuildConfig.class, application = Application.class, sdk = 23) @RunWith(RobolectricGradleTestRunner.class) public class AppPrefsProviderTest extends FDroidProviderTest { diff --git a/app/src/test/java/org/fdroid/fdroid/data/AppProviderTest.java b/app/src/test/java/org/fdroid/fdroid/data/AppProviderTest.java index c0c770f5c..f4cb5e01b 100644 --- a/app/src/test/java/org/fdroid/fdroid/data/AppProviderTest.java +++ b/app/src/test/java/org/fdroid/fdroid/data/AppProviderTest.java @@ -170,21 +170,27 @@ public class AppProviderTest extends FDroidProviderTest { assertResultCount(contentResolver, 10, AppProvider.getContentUri(), PROJ); String[] projection = {Cols.PACKAGE_NAME}; - List ignoredApps = AppProvider.Helper.findIgnored(context, projection); + List canUpdateApps = AppProvider.Helper.findCanUpdate(context, projection); - String[] expectedIgnored = { - "installed, already latest, ignore all", - "installed, already latest, ignore latest", - // NOT "installed, already latest, ignore old" - because it - // is should only ignore if "ignored version" is >= suggested + String[] expectedCanUpdate = { + "installed, old version, no ignore", + "installed, old version, ignore newer, but not latest", + + // These are ignored because they don't have updates available: + // "installed, only one version available", + // "installed, already latest, no ignore", + // "installed, already latest, ignore old", + // "not installed", + + // These four should be ignored due to the app preferences: + // "installed, already latest, ignore all", + // "installed, already latest, ignore latest", + // "installed, old version, ignore all", + // "installed, old version, ignore latest", - "installed, old version, ignore all", - "installed, old version, ignore latest", - // NOT "installed, old version, ignore newer, but not latest" - // for the same reason as above. }; - assertContainsOnlyIds(ignoredApps, expectedIgnored); + assertContainsOnlyIds(canUpdateApps, expectedCanUpdate); } private void assertContainsOnlyIds(List actualApps, String[] expectedIds) {