Replace usages of the deprecated RuntimeEnvironment.application

This commit is contained in:
cketti 2022-08-09 18:33:18 +02:00
parent 46ca47facd
commit 03189fae46
18 changed files with 35 additions and 30 deletions

View file

@ -23,7 +23,7 @@ public class AutocryptHeaderParserTest extends RobolectricTest {
@Before
public void setUp() throws Exception {
BinaryTempFileBody.setTempDirectory(RuntimeEnvironment.application.getCacheDir());
BinaryTempFileBody.setTempDirectory(RuntimeEnvironment.getApplication().getCacheDir());
}
// Test cases taken from: https://github.com/mailencrypt/autocrypt/tree/master/src/tests/data

View file

@ -4,6 +4,7 @@ package com.fsck.k9.cache;
import java.util.Collections;
import java.util.UUID;
import android.content.Context;
import android.net.Uri;
import com.fsck.k9.RobolectricTest;
@ -26,6 +27,7 @@ import static org.mockito.Mockito.when;
public class EmailProviderCacheTest extends RobolectricTest {
private final Context context = RuntimeEnvironment.getApplication();
private EmailProviderCache cache;
@Mock
@ -40,7 +42,7 @@ public class EmailProviderCacheTest extends RobolectricTest {
MockitoAnnotations.initMocks(this);
EmailProvider.CONTENT_URI = Uri.parse("content://test.provider.email");
cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), RuntimeEnvironment.application);
cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), context);
when(mockLocalMessage.getDatabaseId()).thenReturn(localMessageId);
when(mockLocalMessage.getFolder()).thenReturn(mockLocalMessageFolder);
when(mockLocalMessageFolder.getDatabaseId()).thenReturn(localMessageFolderId);
@ -48,16 +50,16 @@ public class EmailProviderCacheTest extends RobolectricTest {
@Test
public void getCache_returnsDifferentCacheForEachUUID() {
EmailProviderCache cache = EmailProviderCache.getCache("u001", RuntimeEnvironment.application);
EmailProviderCache cache2 = EmailProviderCache.getCache("u002", RuntimeEnvironment.application);
EmailProviderCache cache = EmailProviderCache.getCache("u001", context);
EmailProviderCache cache2 = EmailProviderCache.getCache("u002", context);
assertNotEquals(cache, cache2);
}
@Test
public void getCache_returnsSameCacheForAUUID() {
EmailProviderCache cache = EmailProviderCache.getCache("u001", RuntimeEnvironment.application);
EmailProviderCache cache2 = EmailProviderCache.getCache("u001", RuntimeEnvironment.application);
EmailProviderCache cache = EmailProviderCache.getCache("u001", context);
EmailProviderCache cache2 = EmailProviderCache.getCache("u001", context);
assertSame(cache, cache2);
}

View file

@ -137,7 +137,7 @@ public class MessagingControllerTest extends K9RobolectricTest {
public void setUp() throws MessagingException {
ShadowLog.stream = System.out;
MockitoAnnotations.initMocks(this);
appContext = RuntimeEnvironment.application;
appContext = RuntimeEnvironment.getApplication();
preferences = Preferences.getPreferences();

View file

@ -22,7 +22,7 @@ public class MessageHelperTest extends RobolectricTest {
@Before
public void setUp() throws Exception {
Context context = RuntimeEnvironment.application;
Context context = RuntimeEnvironment.getApplication();
contacts = new Contacts(context);
contactsWithFakeContact = new Contacts(context) {
@Override public String getNameForAddress(String address) {

View file

@ -73,7 +73,7 @@ public class MessageViewInfoExtractorTest extends K9RobolectricTest {
@Before
public void setUp() throws Exception {
context = RuntimeEnvironment.application;
context = RuntimeEnvironment.getApplication();
HtmlProcessor htmlProcessor = createFakeHtmlProcessor();
attachmentInfoExtractor = spy(DI.get(AttachmentInfoExtractor.class));

View file

@ -41,7 +41,7 @@ public class AttachmentInfoExtractorTest extends RobolectricTest {
@Before
public void setUp() throws Exception {
AttachmentProvider.CONTENT_URI = Uri.parse("content://test.attachmentprovider");
context = RuntimeEnvironment.application;
context = RuntimeEnvironment.getApplication();
attachmentInfoExtractor = new AttachmentInfoExtractor(context);
}

View file

@ -15,7 +15,7 @@ import org.mockito.kotlin.mock
import org.robolectric.RuntimeEnvironment
class SettingsExporterTest : K9RobolectricTest() {
private val contentResolver = RuntimeEnvironment.application.contentResolver
private val contentResolver = RuntimeEnvironment.getApplication().contentResolver
private val preferences: Preferences by inject()
private val folderSettingsProvider: FolderSettingsProvider by inject()
private val folderRepository: FolderRepository by inject()

View file

@ -6,6 +6,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import android.content.Context;
import com.fsck.k9.K9RobolectricTest;
import com.fsck.k9.Preferences;
import com.fsck.k9.mail.AuthType;
@ -20,6 +22,7 @@ import static org.junit.Assert.assertTrue;
public class SettingsImporterTest extends K9RobolectricTest {
private final Context context = RuntimeEnvironment.getApplication();
@Before
public void before() {
@ -36,7 +39,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("");
List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true);
SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
}
@Test(expected = SettingsImportExportException.class)
@ -44,7 +47,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings version=\"1\"></k9settings>");
List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true);
SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
}
@Test(expected = SettingsImportExportException.class)
@ -52,7 +55,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings version=\"1\" format=\"A\"></k9settings>");
List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true);
SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
}
@Test(expected = SettingsImportExportException.class)
@ -60,7 +63,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings version=\"1\" format=\"0\"></k9settings>");
List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true);
SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
}
@Test(expected = SettingsImportExportException.class)
@ -68,7 +71,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings format=\"1\"></k9settings>");
List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true);
SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
}
@Test(expected = SettingsImportExportException.class)
@ -76,7 +79,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings format=\"1\" version=\"A\"></k9settings>");
List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true);
SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
}
@Test(expected = SettingsImportExportException.class)
@ -84,7 +87,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
InputStream inputStream = inputStreamOf("<k9settings format=\"1\" version=\"0\"></k9settings>");
List<String> accountUuids = new ArrayList<>();
SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true);
SettingsImporter.importSettings(context, inputStream, true, accountUuids, true);
}
@Test
@ -162,7 +165,7 @@ public class SettingsImporterTest extends K9RobolectricTest {
accountUuids.add(validUUID);
SettingsImporter.ImportResults results = SettingsImporter.importSettings(
RuntimeEnvironment.application, inputStream, true, accountUuids, false);
context, inputStream, true, accountUuids, false);
assertEquals(0, results.erroneousAccounts.size());
assertEquals(1, results.importedAccounts.size());

View file

@ -39,8 +39,8 @@ class DependencyInjectionTest : AutoCloseKoinTest() {
getKoin().checkModules {
withParameter<OpenPgpApiManager> { lifecycleOwner }
create<AutocryptKeyTransferPresenter> { parametersOf(lifecycleOwner, autocryptTransferView) }
withParameter<FolderNameFormatter> { RuntimeEnvironment.application }
withParameter<SizeFormatter> { RuntimeEnvironment.application }
withParameter<FolderNameFormatter> { RuntimeEnvironment.getApplication() }
withParameter<SizeFormatter> { RuntimeEnvironment.getApplication() }
withParameter<ChangelogViewModel> { ChangeLogMode.CHANGE_LOG }
}
}

View file

@ -21,7 +21,7 @@ import org.mockito.kotlin.mock
import org.robolectric.RuntimeEnvironment
class UnreadWidgetDataProviderTest : AppRobolectricTest() {
val context: Context = RuntimeEnvironment.application
val context: Context = RuntimeEnvironment.getApplication()
val account = createAccount()
val preferences = createPreferences()
val messagingController = createMessagingController()

View file

@ -18,7 +18,7 @@ import org.mockito.kotlin.verifyNoMoreInteractions
import org.robolectric.RuntimeEnvironment
class StoragePersisterTest : K9RobolectricTest() {
private var context: Context = RuntimeEnvironment.application
private var context: Context = RuntimeEnvironment.getApplication()
private var storagePersister = K9StoragePersister(context)
@Test

View file

@ -45,7 +45,7 @@ public class StoreSchemaDefinitionTest extends K9RobolectricTest {
public void setUp() throws MessagingException {
ShadowLog.stream = System.out;
Application application = RuntimeEnvironment.application;
Application application = RuntimeEnvironment.getApplication();
StorageManager.getInstance(application);
storeSchemaDefinition = createStoreSchemaDefinition();

View file

@ -77,7 +77,7 @@ public class RecipientLoaderTest extends RobolectricTest {
@Before
public void setUp() throws Exception {
Application application = RuntimeEnvironment.application;
Application application = RuntimeEnvironment.getApplication();
shadowApp = Shadows.shadowOf(application);
shadowApp.grantPermissions(Manifest.permission.READ_CONTACTS);
shadowApp.grantPermissions(Manifest.permission.WRITE_CONTACTS);

View file

@ -81,7 +81,7 @@ class PgpMessageBuilderTest : K9RobolectricTest() {
@Before
@Throws(Exception::class)
fun setUp() {
BinaryTempFileBody.setTempDirectory(RuntimeEnvironment.application.cacheDir)
BinaryTempFileBody.setTempDirectory(RuntimeEnvironment.getApplication().cacheDir)
`when`(autocryptOpenPgpApiInteractor.getKeyMaterialForKeyId(openPgpApi, TEST_KEY_ID, SENDER_EMAIL))
.thenReturn(AUTOCRYPT_KEY_MATERIAL)
}

View file

@ -8,7 +8,7 @@ import org.robolectric.RuntimeEnvironment
class K9DrawerTest : RobolectricTest() {
@Test
fun testAccountColorLengthEqualsDrawerColorLength() {
val resources = RuntimeEnvironment.application.resources
val resources = RuntimeEnvironment.getApplication().resources
val lightColors = resources.getIntArray(R.array.account_colors)
val darkColors = resources.getIntArray(R.array.drawer_account_accent_color_dark_theme)

View file

@ -70,7 +70,7 @@ public class MessageCryptoHelperTest extends RobolectricTest {
when(openPgpApiFactory.createOpenPgpApi(any(Context.class), nullable(IOpenPgpService2.class)))
.thenReturn(openPgpApi);
messageCryptoHelper = new MessageCryptoHelper(RuntimeEnvironment.application, openPgpApiFactory,
messageCryptoHelper = new MessageCryptoHelper(RuntimeEnvironment.getApplication(), openPgpApiFactory,
autocryptOperations, "org.example.dummy");
messageCryptoCallback = mock(MessageCryptoCallback.class);
}

View file

@ -16,7 +16,7 @@ import org.robolectric.annotation.Config
@Config(qualifiers = "en")
class RelativeDateTimeFormatterTest : RobolectricTest() {
private val context = RuntimeEnvironment.application.applicationContext
private val context = RuntimeEnvironment.getApplication().applicationContext
private val clock = TestClock()
private val dateTimeFormatter = RelativeDateTimeFormatter(context, clock)

View file

@ -8,7 +8,7 @@ import org.robolectric.annotation.Config
@Config(qualifiers = "en")
class SizeFormatterTest : RobolectricTest() {
private val sizeFormatter = SizeFormatter(RuntimeEnvironment.application.resources)
private val sizeFormatter = SizeFormatter(RuntimeEnvironment.getApplication().resources)
@Test
fun bytes_lower_bound() {