Remove unused test code.
Many of the `Mock*` classes are there to deal with idiosyncrosies of the Android SDK, including `final`/package local/`@Hide` annotations/etc. They are no longer required with robolectric tests.
This commit is contained in:
parent
839ebebd87
commit
60451a050f
@ -1,29 +0,0 @@
|
||||
package mock;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@SuppressLint("ParcelCreator")
|
||||
public class MockApplicationInfo extends ApplicationInfo {
|
||||
|
||||
private final PackageInfo info;
|
||||
|
||||
public MockApplicationInfo(PackageInfo info) {
|
||||
this.info = info;
|
||||
try {
|
||||
this.publicSourceDir = File.createTempFile(info.packageName, "apk").getAbsolutePath();
|
||||
} catch (IOException e) {
|
||||
this.publicSourceDir = "/data/app/" + info.packageName + "-4.apk";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence loadLabel(PackageManager pm) {
|
||||
return "Mock app: " + info.packageName;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package mock;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.fdroid.fdroid.R;
|
||||
|
||||
public class MockCategoryResources extends MockFDroidResources {
|
||||
|
||||
public MockCategoryResources(Context getStringDelegatingContext) {
|
||||
super(getStringDelegatingContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(int id) {
|
||||
switch (id) {
|
||||
case R.string.category_All:
|
||||
return "All";
|
||||
case R.string.category_Recently_Updated:
|
||||
return "Recently Updated";
|
||||
case R.string.category_Whats_New:
|
||||
return "Whats New";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package mock;
|
||||
|
||||
/**
|
||||
* As more components are required to test different parts of F-Droid, we can
|
||||
* create them and add them here (and accessors to the parent class).
|
||||
*/
|
||||
public class MockContextEmptyComponents extends MockContextSwappableComponents {
|
||||
|
||||
public MockContextEmptyComponents() {
|
||||
setPackageManager(new MockEmptyPackageManager());
|
||||
setResources(new MockEmptyResources());
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package mock;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.test.mock.MockContentResolver;
|
||||
import android.test.mock.MockContext;
|
||||
|
||||
public class MockContextSwappableComponents extends MockContext {
|
||||
|
||||
private PackageManager packageManager;
|
||||
private Resources resources;
|
||||
private MockContentResolver contentResolver;
|
||||
|
||||
public MockContextSwappableComponents setPackageManager(PackageManager pm) {
|
||||
packageManager = pm;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MockContextSwappableComponents setResources(Resources resources) {
|
||||
this.resources = resources;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MockContextSwappableComponents setContentResolver(MockContentResolver contentResolver) {
|
||||
this.contentResolver = contentResolver;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageManager getPackageManager() {
|
||||
return packageManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resources getResources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockContentResolver getContentResolver() {
|
||||
return contentResolver;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package mock;
|
||||
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.test.mock.MockPackageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MockEmptyPackageManager extends MockPackageManager {
|
||||
|
||||
@Override
|
||||
public List<PackageInfo> getInstalledPackages(int flags) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package mock;
|
||||
|
||||
import android.test.mock.MockResources;
|
||||
|
||||
public class MockEmptyResources extends MockResources {
|
||||
|
||||
@Override
|
||||
public String getString(int id) {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package mock;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.mock.MockResources;
|
||||
|
||||
import org.fdroid.fdroid.R;
|
||||
|
||||
public class MockFDroidResources extends MockResources {
|
||||
|
||||
private final Context getStringDelegatingContext;
|
||||
|
||||
public MockFDroidResources(Context getStringDelegatingContext) {
|
||||
this.getStringDelegatingContext = getStringDelegatingContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(int id) {
|
||||
return getStringDelegatingContext.getString(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(int id) {
|
||||
switch (id) {
|
||||
case R.integer.fdroid_repo_inuse:
|
||||
return 1;
|
||||
case R.integer.fdroid_archive_inuse:
|
||||
return 0;
|
||||
case R.integer.fdroid_repo_priority:
|
||||
return 10;
|
||||
case R.integer.fdroid_archive_priority:
|
||||
return 20;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package mock;
|
||||
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.test.mock.MockPackageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class MockInstallablePackageManager extends MockPackageManager {
|
||||
|
||||
private final List<PackageInfo> info = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public List<PackageInfo> getInstalledPackages(int flags) {
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageInfo getPackageInfo(String id, int flags) {
|
||||
for (PackageInfo i : info) {
|
||||
if (i.packageName.equals(id)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void install(String id, int version, String versionName) {
|
||||
PackageInfo existing = getPackageInfo(id, 0);
|
||||
if (existing != null) {
|
||||
existing.versionCode = version;
|
||||
existing.versionName = versionName;
|
||||
} else {
|
||||
PackageInfo p = new PackageInfo();
|
||||
p.packageName = id;
|
||||
p.versionCode = version;
|
||||
p.versionName = versionName;
|
||||
p.applicationInfo = new MockApplicationInfo(p);
|
||||
p.lastUpdateTime = System.currentTimeMillis();
|
||||
info.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationInfo getApplicationInfo(String packageName, int flags) throws NameNotFoundException {
|
||||
return new MockApplicationInfo(getPackageInfo(packageName, 0));
|
||||
}
|
||||
|
||||
public void remove(String id) {
|
||||
for (Iterator<PackageInfo> it = info.iterator(); it.hasNext();) {
|
||||
PackageInfo info = it.next();
|
||||
if (info.packageName.equals(id)) {
|
||||
it.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,144 +1,21 @@
|
||||
package org.fdroid.fdroid;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.fdroid.fdroid.data.ApkProvider;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.data.FDroidProviderTestOld;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
private static final String TAG = "TestUtils";
|
||||
|
||||
public static <T extends Comparable> void assertContainsOnly(List<T> actualList, T[] expectedArray) {
|
||||
List<T> expectedList = new ArrayList<>(expectedArray.length);
|
||||
Collections.addAll(expectedList, expectedArray);
|
||||
assertContainsOnly(actualList, expectedList);
|
||||
}
|
||||
|
||||
public static <T extends Comparable> void assertContainsOnly(T[] actualArray, List<T> expectedList) {
|
||||
List<T> actualList = new ArrayList<>(actualArray.length);
|
||||
Collections.addAll(actualList, actualArray);
|
||||
assertContainsOnly(actualList, expectedList);
|
||||
}
|
||||
|
||||
public static <T extends Comparable> void assertContainsOnly(T[] actualArray, T[] expectedArray) {
|
||||
List<T> expectedList = new ArrayList<>(expectedArray.length);
|
||||
Collections.addAll(expectedList, expectedArray);
|
||||
assertContainsOnly(actualArray, expectedList);
|
||||
}
|
||||
|
||||
public static <T> String listToString(List<T> list) {
|
||||
String string = "[";
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (i > 0) {
|
||||
string += ", ";
|
||||
}
|
||||
string += "'" + list.get(i) + "'";
|
||||
}
|
||||
string += "]";
|
||||
return string;
|
||||
}
|
||||
|
||||
public static <T extends Comparable> void assertContainsOnly(List<T> actualList, List<T> expectedContains) {
|
||||
if (actualList.size() != expectedContains.size()) {
|
||||
String message =
|
||||
"List sizes don't match.\n" +
|
||||
"Expected: " +
|
||||
listToString(expectedContains) + "\n" +
|
||||
"Actual: " +
|
||||
listToString(actualList);
|
||||
throw new AssertionFailedError(message);
|
||||
}
|
||||
for (T required : expectedContains) {
|
||||
boolean containsRequired = false;
|
||||
for (T itemInList : actualList) {
|
||||
if (required.equals(itemInList)) {
|
||||
containsRequired = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!containsRequired) {
|
||||
String message =
|
||||
"List doesn't contain \"" + required + "\".\n" +
|
||||
"Expected: " +
|
||||
listToString(expectedContains) + "\n" +
|
||||
"Actual: " +
|
||||
listToString(actualList);
|
||||
throw new AssertionFailedError(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void insertApp(ContentResolver resolver, String appId, String name) {
|
||||
insertApp(resolver, appId, name, new ContentValues());
|
||||
}
|
||||
|
||||
public static void insertApp(ContentResolver resolver, String id, String name, ContentValues additionalValues) {
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(AppProvider.DataColumns.PACKAGE_NAME, id);
|
||||
values.put(AppProvider.DataColumns.NAME, name);
|
||||
|
||||
// Required fields (NOT NULL in the database).
|
||||
values.put(AppProvider.DataColumns.SUMMARY, "test summary");
|
||||
values.put(AppProvider.DataColumns.DESCRIPTION, "test description");
|
||||
values.put(AppProvider.DataColumns.LICENSE, "GPL?");
|
||||
values.put(AppProvider.DataColumns.IS_COMPATIBLE, 1);
|
||||
values.put(AppProvider.DataColumns.IGNORE_ALLUPDATES, 0);
|
||||
values.put(AppProvider.DataColumns.IGNORE_THISUPDATE, 0);
|
||||
|
||||
values.putAll(additionalValues);
|
||||
|
||||
Uri uri = AppProvider.getContentUri();
|
||||
|
||||
resolver.insert(uri, values);
|
||||
}
|
||||
|
||||
public static Uri insertApk(FDroidProviderTestOld<ApkProvider> providerTest, String id, int versionCode) {
|
||||
return insertApk(providerTest, id, versionCode, new ContentValues());
|
||||
}
|
||||
|
||||
public static Uri insertApk(FDroidProviderTestOld<ApkProvider> providerTest, String id, int versionCode, ContentValues additionalValues) {
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
values.put(ApkProvider.DataColumns.PACKAGE_NAME, id);
|
||||
values.put(ApkProvider.DataColumns.VERSION_CODE, versionCode);
|
||||
|
||||
// Required fields (NOT NULL in the database).
|
||||
values.put(ApkProvider.DataColumns.REPO_ID, 1);
|
||||
values.put(ApkProvider.DataColumns.VERSION_NAME, "The good one");
|
||||
values.put(ApkProvider.DataColumns.HASH, "11111111aaaaaaaa");
|
||||
values.put(ApkProvider.DataColumns.NAME, "Test Apk");
|
||||
values.put(ApkProvider.DataColumns.SIZE, 10000);
|
||||
values.put(ApkProvider.DataColumns.IS_COMPATIBLE, 1);
|
||||
|
||||
values.putAll(additionalValues);
|
||||
|
||||
Uri uri = ApkProvider.getContentUri();
|
||||
|
||||
return providerTest.getMockContentResolver().insert(uri, values);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File copyAssetToDir(Context context, String assetName, File directory) {
|
||||
File tempFile;
|
||||
|
@ -1,177 +0,0 @@
|
||||
package org.fdroid.fdroid.data;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
import android.test.ProviderTestCase2MockContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import mock.MockContextEmptyComponents;
|
||||
import mock.MockContextSwappableComponents;
|
||||
import mock.MockFDroidResources;
|
||||
|
||||
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
|
||||
public abstract class FDroidProviderTestOld<T extends FDroidProvider> extends ProviderTestCase2MockContext<T> {
|
||||
|
||||
private FDroidProvider[] allProviders = {
|
||||
new AppProvider(),
|
||||
new RepoProvider(),
|
||||
new ApkProvider(),
|
||||
new InstalledAppProvider(),
|
||||
};
|
||||
|
||||
private MockContextSwappableComponents swappableContext;
|
||||
|
||||
public FDroidProviderTestOld(Class<T> providerClass, String providerAuthority) {
|
||||
super(providerClass, providerAuthority);
|
||||
}
|
||||
|
||||
protected Resources getMockResources() {
|
||||
return new MockFDroidResources(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
FDroidProvider.clearDbHelperSingleton();
|
||||
|
||||
// Instantiate all providers other than the one which was already created by the base class.
|
||||
// This is because F-Droid providers tend to perform joins onto tables managed by other
|
||||
// providers, and so we need to be able to insert into those other providers for these
|
||||
// joins to be tested correctly.
|
||||
for (FDroidProvider provider : allProviders) {
|
||||
if (!provider.getName().equals(getProvider().getName())) {
|
||||
provider.attachInfo(getMockContext(), null);
|
||||
getMockContentResolver().addProvider(provider.getName(), provider);
|
||||
}
|
||||
}
|
||||
|
||||
getSwappableContext().setResources(getMockResources());
|
||||
|
||||
// The *Provider.Helper.* functions tend to take a Context as their
|
||||
// first parameter. This context is used to connect to the relevant
|
||||
// content provider. Thus, we need a context that is able to connect
|
||||
// to the mock content resolver, in order to reach the provider
|
||||
// under test.
|
||||
getSwappableContext().setContentResolver(getMockContentResolver());
|
||||
|
||||
}
|
||||
|
||||
public void testObviouslyInvalidUris() {
|
||||
assertInvalidUri("http://www.google.com");
|
||||
assertInvalidUri(ContactsContract.AUTHORITY_URI);
|
||||
assertInvalidUri("junk");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Context createMockContext(Context delegate) {
|
||||
swappableContext = new MockContextEmptyComponents();
|
||||
return swappableContext;
|
||||
}
|
||||
|
||||
public MockContextSwappableComponents getSwappableContext() {
|
||||
return swappableContext;
|
||||
}
|
||||
|
||||
protected void assertCantDelete(Uri uri) {
|
||||
try {
|
||||
getMockContentResolver().delete(uri, null, null);
|
||||
fail();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
} catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertCantUpdate(Uri uri) {
|
||||
try {
|
||||
getMockContentResolver().update(uri, new ContentValues(), null, null);
|
||||
fail();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
} catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertInvalidUri(String uri) {
|
||||
assertInvalidUri(Uri.parse(uri));
|
||||
}
|
||||
|
||||
protected void assertValidUri(String uri) {
|
||||
assertValidUri(Uri.parse(uri));
|
||||
}
|
||||
|
||||
protected void assertInvalidUri(Uri uri) {
|
||||
try {
|
||||
// Use getProvdider instead of getContentResolver, because the mock
|
||||
// content resolver wont result in the provider we are testing, and
|
||||
// hence we don't get to see how our provider responds to invalid
|
||||
// uris.
|
||||
getProvider().query(uri, getMinimalProjection(), null, null, null);
|
||||
fail();
|
||||
} catch (UnsupportedOperationException e) { }
|
||||
}
|
||||
|
||||
protected void assertValidUri(Uri uri) {
|
||||
Cursor cursor = getMockContentResolver().query(uri, getMinimalProjection(), null, null, null);
|
||||
assertNotNull(cursor);
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
protected void assertValidUri(Uri actualUri, String expectedUri) {
|
||||
assertValidUri(actualUri);
|
||||
assertEquals(expectedUri, actualUri.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Many queries need at least some sort of projection in order to produce
|
||||
* valid SQL. As such, we also need to know about that, so we can provide
|
||||
* helper functions that revolve around the contnet provider under test.
|
||||
*/
|
||||
protected abstract String[] getMinimalProjection();
|
||||
|
||||
protected void assertResultCount(int expectedCount, Uri uri) {
|
||||
Cursor cursor = getMockContentResolver().query(uri, getMinimalProjection(), null, null, null);
|
||||
assertResultCount(expectedCount, cursor);
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
protected void assertResultCount(int expectedCount, List items) {
|
||||
assertNotNull(items);
|
||||
assertEquals(expectedCount, items.size());
|
||||
}
|
||||
|
||||
protected void assertResultCount(int expectedCount, Cursor result) {
|
||||
assertNotNull(result);
|
||||
assertEquals(expectedCount, result.getCount());
|
||||
}
|
||||
|
||||
protected void assertIsInstalledVersionInDb(String appId, int versionCode, String versionName) {
|
||||
Uri uri = InstalledAppProvider.getAppUri(appId);
|
||||
|
||||
String[] projection = {
|
||||
InstalledAppProvider.DataColumns.PACKAGE_NAME,
|
||||
InstalledAppProvider.DataColumns.VERSION_CODE,
|
||||
InstalledAppProvider.DataColumns.VERSION_NAME,
|
||||
InstalledAppProvider.DataColumns.APPLICATION_LABEL,
|
||||
};
|
||||
|
||||
Cursor cursor = getMockContentResolver().query(uri, projection, null, null, null);
|
||||
|
||||
assertNotNull(cursor);
|
||||
assertEquals("App \"" + appId + "\" not installed", 1, cursor.getCount());
|
||||
|
||||
cursor.moveToFirst();
|
||||
|
||||
assertEquals(appId, cursor.getString(cursor.getColumnIndex(InstalledAppProvider.DataColumns.PACKAGE_NAME)));
|
||||
assertEquals(versionCode, cursor.getInt(cursor.getColumnIndex(InstalledAppProvider.DataColumns.VERSION_CODE)));
|
||||
assertEquals(versionName, cursor.getString(cursor.getColumnIndex(InstalledAppProvider.DataColumns.VERSION_NAME)));
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
}
|
@ -1,177 +0,0 @@
|
||||
package org.fdroid.fdroid.data;
|
||||
|
||||
import mock.MockInstallablePackageManager;
|
||||
|
||||
/**
|
||||
* Tests the ability of the {@link InstalledAppCacheUpdater} to stay in sync with
|
||||
* the {@link android.content.pm.PackageManager}.
|
||||
* For practical reasons, it extends FDroidProviderTestOld<InstalledAppProvider>, although there is also a
|
||||
* separate test for the InstalledAppProvider which tests the CRUD operations in more detail.
|
||||
*/
|
||||
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
|
||||
public class InstalledAppCacheTest extends FDroidProviderTestOld<InstalledAppProvider> {
|
||||
|
||||
private MockInstallablePackageManager packageManager;
|
||||
|
||||
public InstalledAppCacheTest() {
|
||||
super(InstalledAppProvider.class, InstalledAppProvider.getAuthority());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
packageManager = new MockInstallablePackageManager();
|
||||
getSwappableContext().setPackageManager(packageManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getMinimalProjection() {
|
||||
return new String[] {
|
||||
InstalledAppProvider.DataColumns.PACKAGE_NAME,
|
||||
};
|
||||
}
|
||||
|
||||
public void install(String appId, int versionCode, String versionName) {
|
||||
packageManager.install(appId, versionCode, versionName);
|
||||
}
|
||||
|
||||
public void remove(String appId) {
|
||||
packageManager.remove(appId);
|
||||
}
|
||||
|
||||
/* TODO fix me
|
||||
public void testFromEmptyCache() {
|
||||
assertResultCount(0, InstalledAppProvider.getContentUri());
|
||||
for (int i = 1; i <= 15; i ++) {
|
||||
install("com.example.app" + i, 200, "2.0");
|
||||
}
|
||||
InstalledAppCacheUpdater.updateInForeground(getMockContext());
|
||||
|
||||
String[] expectedInstalledIds = {
|
||||
"com.example.app1",
|
||||
"com.example.app2",
|
||||
"com.example.app3",
|
||||
"com.example.app4",
|
||||
"com.example.app5",
|
||||
"com.example.app6",
|
||||
"com.example.app7",
|
||||
"com.example.app8",
|
||||
"com.example.app9",
|
||||
"com.example.app10",
|
||||
"com.example.app11",
|
||||
"com.example.app12",
|
||||
"com.example.app13",
|
||||
"com.example.app14",
|
||||
"com.example.app15",
|
||||
};
|
||||
|
||||
TestUtils.assertContainsOnly(getInstalledAppIdsFromProvider(), expectedInstalledIds);
|
||||
}
|
||||
|
||||
private String[] getInstalledAppIdsFromProvider() {
|
||||
Uri uri = InstalledAppProvider.getContentUri();
|
||||
String[] projection = { InstalledAppProvider.DataColumns.PACKAGE_NAME };
|
||||
Cursor result = getMockContext().getContentResolver().query(uri, projection, null, null, null);
|
||||
if (result == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
String[] installedAppIds = new String[result.getCount()];
|
||||
result.moveToFirst();
|
||||
int i = 0;
|
||||
while (!result.isAfterLast()) {
|
||||
installedAppIds[i] = result.getString(result.getColumnIndex(InstalledAppProvider.DataColumns.PACKAGE_NAME));
|
||||
result.moveToNext();
|
||||
i ++;
|
||||
}
|
||||
result.close();
|
||||
return installedAppIds;
|
||||
}
|
||||
|
||||
public void testAppsAdded() {
|
||||
assertResultCount(0, InstalledAppProvider.getContentUri());
|
||||
|
||||
install("com.example.app1", 1, "v1");
|
||||
install("com.example.app2", 1, "v1");
|
||||
install("com.example.app3", 1, "v1");
|
||||
InstalledAppCacheUpdater.updateInForeground(getMockContext());
|
||||
|
||||
assertResultCount(3, InstalledAppProvider.getContentUri());
|
||||
assertIsInstalledVersionInDb("com.example.app1", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app2", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app3", 1, "v1");
|
||||
|
||||
install("com.example.app10", 1, "v1");
|
||||
install("com.example.app11", 1, "v1");
|
||||
install("com.example.app12", 1, "v1");
|
||||
InstalledAppCacheUpdater.updateInForeground(getMockContext());
|
||||
|
||||
assertResultCount(6, InstalledAppProvider.getContentUri());
|
||||
assertIsInstalledVersionInDb("com.example.app10", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app11", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app12", 1, "v1");
|
||||
}
|
||||
|
||||
public void testAppsRemoved() {
|
||||
install("com.example.app1", 1, "v1");
|
||||
install("com.example.app2", 1, "v1");
|
||||
install("com.example.app3", 1, "v1");
|
||||
InstalledAppCacheUpdater.updateInForeground(getMockContext());
|
||||
|
||||
assertResultCount(3, InstalledAppProvider.getContentUri());
|
||||
assertIsInstalledVersionInDb("com.example.app1", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app2", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app3", 1, "v1");
|
||||
|
||||
remove("com.example.app2");
|
||||
InstalledAppCacheUpdater.updateInForeground(getMockContext());
|
||||
|
||||
assertResultCount(2, InstalledAppProvider.getContentUri());
|
||||
assertIsInstalledVersionInDb("com.example.app1", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app3", 1, "v1");
|
||||
}
|
||||
|
||||
public void testAppsUpdated() {
|
||||
install("com.example.app1", 1, "v1");
|
||||
install("com.example.app2", 1, "v1");
|
||||
InstalledAppCacheUpdater.updateInForeground(getMockContext());
|
||||
|
||||
assertResultCount(2, InstalledAppProvider.getContentUri());
|
||||
assertIsInstalledVersionInDb("com.example.app1", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app2", 1, "v1");
|
||||
|
||||
install("com.example.app2", 20, "v2.0");
|
||||
InstalledAppCacheUpdater.updateInForeground(getMockContext());
|
||||
|
||||
assertResultCount(2, InstalledAppProvider.getContentUri());
|
||||
assertIsInstalledVersionInDb("com.example.app1", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app2", 20, "v2.0");
|
||||
}
|
||||
|
||||
public void testAppsAddedRemovedAndUpdated() {
|
||||
install("com.example.app1", 1, "v1");
|
||||
install("com.example.app2", 1, "v1");
|
||||
install("com.example.app3", 1, "v1");
|
||||
install("com.example.app4", 1, "v1");
|
||||
InstalledAppCacheUpdater.updateInForeground(getMockContext());
|
||||
|
||||
assertResultCount(4, InstalledAppProvider.getContentUri());
|
||||
assertIsInstalledVersionInDb("com.example.app1", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app2", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app3", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app4", 1, "v1");
|
||||
|
||||
install("com.example.app1", 13, "v1.3");
|
||||
remove("com.example.app2");
|
||||
remove("com.example.app3");
|
||||
install("com.example.app10", 1, "v1");
|
||||
InstalledAppCacheUpdater.updateInForeground(getMockContext());
|
||||
|
||||
assertResultCount(3, InstalledAppProvider.getContentUri());
|
||||
assertIsInstalledVersionInDb("com.example.app1", 13, "v1.3");
|
||||
assertIsInstalledVersionInDb("com.example.app4", 1, "v1");
|
||||
assertIsInstalledVersionInDb("com.example.app10", 1, "v1");
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user