Adding test coverage for "AppProvider.Helper.findIgnored()"
Also added tests for canAndWantToUpdate() while I was at it.
This commit is contained in:
parent
81fcd44b66
commit
9fd8da42a1
@ -137,23 +137,14 @@ public class AppProvider extends FDroidProvider {
|
|||||||
public static final String SUGGESTED_VERSION_CODE = "suggestedVercode";
|
public static final String SUGGESTED_VERSION_CODE = "suggestedVercode";
|
||||||
public static final String UPSTREAM_VERSION = "upstreamVersion";
|
public static final String UPSTREAM_VERSION = "upstreamVersion";
|
||||||
public static final String UPSTREAM_VERSION_CODE = "upstreamVercode";
|
public static final String UPSTREAM_VERSION_CODE = "upstreamVercode";
|
||||||
public static final String CURRENT_APK = null;
|
|
||||||
public static final String ADDED = "added";
|
public static final String ADDED = "added";
|
||||||
public static final String LAST_UPDATED = "lastUpdated";
|
public static final String LAST_UPDATED = "lastUpdated";
|
||||||
public static final String INSTALLED_VERSION = null;
|
|
||||||
public static final String INSTALLED_VERCODE = null;
|
|
||||||
public static final String USER_INSTALLED = null;
|
|
||||||
public static final String CATEGORIES = "categories";
|
public static final String CATEGORIES = "categories";
|
||||||
public static final String ANTI_FEATURES = "antiFeatures";
|
public static final String ANTI_FEATURES = "antiFeatures";
|
||||||
public static final String REQUIREMENTS = "requirements";
|
public static final String REQUIREMENTS = "requirements";
|
||||||
public static final String FILTERED = null;
|
|
||||||
public static final String HAS_UPDATES = null;
|
|
||||||
public static final String TO_UPDATE = null;
|
|
||||||
public static final String IGNORE_ALLUPDATES = "ignoreAllUpdates";
|
public static final String IGNORE_ALLUPDATES = "ignoreAllUpdates";
|
||||||
public static final String IGNORE_THISUPDATE = "ignoreThisUpdate";
|
public static final String IGNORE_THISUPDATE = "ignoreThisUpdate";
|
||||||
public static final String ICON_URL = "iconUrl";
|
public static final String ICON_URL = "iconUrl";
|
||||||
public static final String UPDATED = null;
|
|
||||||
public static final String APKS = null;
|
|
||||||
|
|
||||||
public interface SuggestedApk {
|
public interface SuggestedApk {
|
||||||
public static final String VERSION = "suggestedApkVersion";
|
public static final String VERSION = "suggestedApkVersion";
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package org.fdroid.fdroid;
|
package org.fdroid.fdroid;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
|
||||||
import mock.MockCategoryResources;
|
import mock.MockCategoryResources;
|
||||||
|
import mock.MockContextSwappableComponents;
|
||||||
import mock.MockInstallablePackageManager;
|
import mock.MockInstallablePackageManager;
|
||||||
|
|
||||||
import org.fdroid.fdroid.data.ApkProvider;
|
import org.fdroid.fdroid.data.ApkProvider;
|
||||||
@ -33,6 +35,10 @@ public class AppProviderTest extends FDroidProviderTest<AppProvider> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCantFindApp() {
|
||||||
|
assertNull(AppProvider.Helper.findById(getMockContentResolver(), "com.example.doesnt-exist"));
|
||||||
|
}
|
||||||
|
|
||||||
public void testUris() {
|
public void testUris() {
|
||||||
assertInvalidUri(AppProvider.getAuthority());
|
assertInvalidUri(AppProvider.getAuthority());
|
||||||
assertInvalidUri(ApkProvider.getContentUri());
|
assertInvalidUri(ApkProvider.getContentUri());
|
||||||
@ -65,6 +71,110 @@ public class AppProviderTest extends FDroidProviderTest<AppProvider> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void insertAndInstallApp(
|
||||||
|
MockInstallablePackageManager packageManager,
|
||||||
|
String id, int installedVercode, int suggestedVercode,
|
||||||
|
boolean ignoreAll, int ignoreVercode) {
|
||||||
|
ContentValues values = new ContentValues(3);
|
||||||
|
values.put(AppProvider.DataColumns.SUGGESTED_VERSION_CODE, suggestedVercode);
|
||||||
|
values.put(AppProvider.DataColumns.IGNORE_ALLUPDATES, ignoreAll);
|
||||||
|
values.put(AppProvider.DataColumns.IGNORE_THISUPDATE, ignoreVercode);
|
||||||
|
insertApp(id, "App: " + id, values);
|
||||||
|
|
||||||
|
packageManager.install(id, installedVercode, "v" + installedVercode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCanUpdate() {
|
||||||
|
|
||||||
|
MockContextSwappableComponents c = getSwappableContext();
|
||||||
|
|
||||||
|
MockInstallablePackageManager pm = new MockInstallablePackageManager();
|
||||||
|
c.setPackageManager(pm);
|
||||||
|
|
||||||
|
insertApp("not installed", "not installed");
|
||||||
|
insertAndInstallApp(pm, "installed, only one version available", 1, 1, false, 0);
|
||||||
|
insertAndInstallApp(pm, "installed, already latest, no ignore", 10, 10, false, 0);
|
||||||
|
insertAndInstallApp(pm, "installed, already latest, ignore all", 10, 10, true, 0);
|
||||||
|
insertAndInstallApp(pm, "installed, already latest, ignore latest", 10, 10, false, 10);
|
||||||
|
insertAndInstallApp(pm, "installed, already latest, ignore old", 10, 10, false, 5);
|
||||||
|
insertAndInstallApp(pm, "installed, old version, no ignore", 5, 10, false, 0);
|
||||||
|
insertAndInstallApp(pm, "installed, old version, ignore all", 5, 10, true, 0);
|
||||||
|
insertAndInstallApp(pm, "installed, old version, ignore latest", 5, 10, false, 10);
|
||||||
|
insertAndInstallApp(pm, "installed, old version, ignore newer, but not latest", 5, 10, false, 8);
|
||||||
|
|
||||||
|
ContentResolver r = getMockContentResolver();
|
||||||
|
|
||||||
|
// Can't "update", although can "install"...
|
||||||
|
App notInstalled = AppProvider.Helper.findById(r, "not installed");
|
||||||
|
assertFalse(notInstalled.canAndWantToUpdate(c));
|
||||||
|
|
||||||
|
App installedOnlyOneVersionAvailable = AppProvider.Helper.findById(r, "installed, only one version available");
|
||||||
|
App installedAlreadyLatestNoIgnore = AppProvider.Helper.findById(r, "installed, already latest, no ignore");
|
||||||
|
App installedAlreadyLatestIgnoreAll = AppProvider.Helper.findById(r, "installed, already latest, ignore all");
|
||||||
|
App installedAlreadyLatestIgnoreLatest = AppProvider.Helper.findById(r, "installed, already latest, ignore latest");
|
||||||
|
App installedAlreadyLatestIgnoreOld = AppProvider.Helper.findById(r, "installed, already latest, ignore old");
|
||||||
|
|
||||||
|
assertFalse(installedOnlyOneVersionAvailable.canAndWantToUpdate(c));
|
||||||
|
assertFalse(installedAlreadyLatestNoIgnore.canAndWantToUpdate(c));
|
||||||
|
assertFalse(installedAlreadyLatestIgnoreAll.canAndWantToUpdate(c));
|
||||||
|
assertFalse(installedAlreadyLatestIgnoreLatest.canAndWantToUpdate(c));
|
||||||
|
assertFalse(installedAlreadyLatestIgnoreOld.canAndWantToUpdate(c));
|
||||||
|
|
||||||
|
App installedOldNoIgnore = AppProvider.Helper.findById(r, "installed, old version, no ignore");
|
||||||
|
App installedOldIgnoreAll = AppProvider.Helper.findById(r, "installed, old version, ignore all");
|
||||||
|
App installedOldIgnoreLatest = AppProvider.Helper.findById(r, "installed, old version, ignore latest");
|
||||||
|
App installedOldIgnoreNewerNotLatest = AppProvider.Helper.findById(r, "installed, old version, ignore newer, but not latest");
|
||||||
|
|
||||||
|
assertTrue(installedOldNoIgnore.canAndWantToUpdate(c));
|
||||||
|
assertFalse(installedOldIgnoreAll.canAndWantToUpdate(c));
|
||||||
|
assertFalse(installedOldIgnoreLatest.canAndWantToUpdate(c));
|
||||||
|
assertTrue(installedOldIgnoreNewerNotLatest.canAndWantToUpdate(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIgnored() {
|
||||||
|
|
||||||
|
MockInstallablePackageManager pm = new MockInstallablePackageManager();
|
||||||
|
getSwappableContext().setPackageManager(pm);
|
||||||
|
|
||||||
|
insertApp("not installed", "not installed");
|
||||||
|
insertAndInstallApp(pm, "installed, only one version available", 1, 1, false, 0);
|
||||||
|
insertAndInstallApp(pm, "installed, already latest, no ignore", 10, 10, false, 0);
|
||||||
|
insertAndInstallApp(pm, "installed, already latest, ignore all", 10, 10, true, 0);
|
||||||
|
insertAndInstallApp(pm, "installed, already latest, ignore latest", 10, 10, false, 10);
|
||||||
|
insertAndInstallApp(pm, "installed, already latest, ignore old", 10, 10, false, 5);
|
||||||
|
insertAndInstallApp(pm, "installed, old version, no ignore", 5, 10, false, 0);
|
||||||
|
insertAndInstallApp(pm, "installed, old version, ignore all", 5, 10, true, 0);
|
||||||
|
insertAndInstallApp(pm, "installed, old version, ignore latest", 5, 10, false, 10);
|
||||||
|
insertAndInstallApp(pm, "installed, old version, ignore newer, but not latest", 5, 10, false, 8);
|
||||||
|
|
||||||
|
assertResultCount(10, AppProvider.getContentUri());
|
||||||
|
|
||||||
|
String[] projection = { AppProvider.DataColumns.APP_ID };
|
||||||
|
List<App> ignoredApps = AppProvider.Helper.findIgnored(getMockContext(), 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
|
||||||
|
|
||||||
|
"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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertContainsOnlyIds(List<App> actualApps, String[] expectedIds) {
|
||||||
|
List<String> actualIds = new ArrayList<String>(actualApps.size());
|
||||||
|
for (App app : actualApps) {
|
||||||
|
actualIds.add(app.id);
|
||||||
|
}
|
||||||
|
TestUtils.assertContainsOnly(actualIds, expectedIds);
|
||||||
|
}
|
||||||
|
|
||||||
public void testInstalled() {
|
public void testInstalled() {
|
||||||
|
|
||||||
Utils.clearInstalledApksCache();
|
Utils.clearInstalledApksCache();
|
||||||
|
@ -24,7 +24,7 @@ public class TestUtils {
|
|||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
string += ", ";
|
string += ", ";
|
||||||
}
|
}
|
||||||
string += list.get(i);
|
string += "'" + list.get(i) + "'";
|
||||||
}
|
}
|
||||||
string += "]";
|
string += "]";
|
||||||
return string;
|
return string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user