tests: run shutdown() on tested ContentProviders to reduce memory usage
Hopefully?
This commit is contained in:
parent
a4e66540c2
commit
857bc5c29e
@ -18,6 +18,7 @@ import org.fdroid.fdroid.data.RepoProviderTest;
|
||||
import org.fdroid.fdroid.data.Schema;
|
||||
import org.mockito.AdditionalAnswers;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.android.controller.ContentProviderController;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@ -118,10 +119,11 @@ public class TestUtils {
|
||||
return RepoProviderTest.insertRepo(context, repoUrl, "", "", "");
|
||||
}
|
||||
|
||||
public static <T extends ContentProvider> void registerContentProvider(String authority, Class<T> providerClass) {
|
||||
public static <T extends ContentProvider> ContentProviderController<T> registerContentProvider(
|
||||
String authority, Class<T> providerClass) {
|
||||
ProviderInfo info = new ProviderInfo();
|
||||
info.authority = authority;
|
||||
Robolectric.buildContentProvider(providerClass).create(info);
|
||||
return Robolectric.buildContentProvider(providerClass).create(info);
|
||||
}
|
||||
|
||||
public static File copyResourceToTempFile(String resourceName) {
|
||||
|
@ -2,8 +2,6 @@ package org.fdroid.fdroid.data;
|
||||
|
||||
import android.app.Application;
|
||||
import org.fdroid.fdroid.Assert;
|
||||
import org.fdroid.fdroid.TestUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@ -18,11 +16,6 @@ import static org.junit.Assert.assertTrue;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AppPrefsProviderTest extends FDroidProviderTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"PMD.EqualsNull", "EqualsWithItself", "EqualsBetweenInconvertibleTypes", "ObjectEqualsNull"})
|
||||
@Test
|
||||
public void prefEquality() {
|
||||
|
@ -50,7 +50,6 @@ public class AppProviderTest extends FDroidProviderTest {
|
||||
@Before
|
||||
public void setup() {
|
||||
defaultLocale = Locale.getDefault();
|
||||
TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class);
|
||||
Preferences.setupForTests(context);
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,9 @@ import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import org.fdroid.fdroid.TestUtils;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.Schema.AppMetadataTable.Cols;
|
||||
import org.fdroid.fdroid.mock.MockRepo;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@ -28,11 +26,6 @@ import static org.junit.Assert.assertEquals;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class CategoryProviderTest extends FDroidProviderTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Different repositories can specify a different set of categories for the same package.
|
||||
* In this case, only the repository with the highest priority should get to choose which
|
||||
|
@ -7,16 +7,16 @@ import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.TestUtils;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.android.controller.ContentProviderController;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@Config(application = Application.class)
|
||||
@ -26,11 +26,18 @@ public class DatabaseMigration {
|
||||
protected ContentResolver contentResolver;
|
||||
protected ContextWrapper context;
|
||||
|
||||
protected ContentProviderController contentProviderController;
|
||||
|
||||
@Before
|
||||
public final void setupBase() {
|
||||
contentResolver = ApplicationProvider.getApplicationContext().getContentResolver();
|
||||
context = TestUtils.createContextWithContentResolver(contentResolver);
|
||||
TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class);
|
||||
contentProviderController = TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() {
|
||||
contentProviderController.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3,27 +3,28 @@ package org.fdroid.fdroid.data;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.ContextWrapper;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.fdroid.fdroid.TestUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.robolectric.android.controller.ContentProviderController;
|
||||
|
||||
public abstract class FDroidProviderTest { // NOPMD This abstract class does not have any abstract methods
|
||||
|
||||
protected ContentResolver contentResolver;
|
||||
protected ContentProviderController<AppProvider> contentProviderController;
|
||||
protected ContextWrapper context;
|
||||
|
||||
@Before
|
||||
public final void setupBase() {
|
||||
contentResolver = ApplicationProvider.getApplicationContext().getContentResolver();
|
||||
context = TestUtils.createContextWithContentResolver(contentResolver);
|
||||
TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class);
|
||||
contentProviderController = TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public final void tearDownBase() {
|
||||
contentProviderController.shutdown();
|
||||
CategoryProvider.Helper.clearCategoryIdCache();
|
||||
DBHelper.clearDbHelperSingleton();
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ public class PreferredSignatureTest extends FDroidProviderTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class);
|
||||
Preferences.setupForTests(context);
|
||||
|
||||
// This is what the FDroidApp does when this preference is changed. Need to also do this under testing.
|
||||
@ -132,6 +131,7 @@ public class PreferredSignatureTest extends FDroidProviderTest {
|
||||
* the same apps/apks. The only difference is in the order with which they get added to the database. They both
|
||||
* then delegate here and assert that everything works as expected. The reason for testing like this is to ensure
|
||||
* that the order of rows in the database has no bearing on the correct suggestions of signatures.
|
||||
*
|
||||
* @see #fdroidThenDev1()
|
||||
* @see #fdroidThenDev2()
|
||||
*/
|
||||
|
@ -21,7 +21,6 @@ public class SuggestedVersionTest extends FDroidProviderTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class);
|
||||
Preferences.setupForTests(context);
|
||||
|
||||
// This is what the FDroidApp does when this preference is changed. Need to also do this under testing.
|
||||
|
Loading…
x
Reference in New Issue
Block a user