...
 
Commits (12)
......@@ -54,7 +54,8 @@ buildscript {
'junit' : '4.12',
'robolectric' : '3.7.1',
'robolectric' : '4.3.1',
'runner_rules' : '1.1.0',
'mockito' : '2.18.0',
'mockitoKotlin' : '1.5.0',
'truth' : '0.35',
......
......@@ -4,5 +4,6 @@ buildAutomatic=true
android.useAndroidX=true
android.enableJetifier=true
android.enableUnitTestBinaryResources=true
#org.gradle.configureondemand=false
#android.enableAapt2=false
\ No newline at end of file
......@@ -82,16 +82,6 @@ dependencies {
implementation "com.evernote:android-job:${versions.androidJob}"
implementation "androidx.work:work-runtime:${versions.workRuntime}"
//TODO: SWITCH TO ANDROID-X
androidTestImplementation "androidx.test.espresso:espresso-intents:${versions.espresso}"
androidTestImplementation ("androidx.test.espresso:espresso-core:${versions.espresso}") {
exclude module: 'support-annotations'
}
testImplementation "org.robolectric:robolectric:${versions.robolectric}"
testImplementation "junit:junit:${versions.junit}"
testImplementation "org.mockito:mockito-core:${versions.mockito}"
testImplementation "org.jdom:jdom2:${versions.jdom}"
// Arch dependencies
kapt "com.google.dagger:dagger-compiler:${versions.dagger}"
implementation "com.google.dagger:dagger:${versions.dagger}"
......@@ -103,12 +93,29 @@ dependencies {
implementation "org.koin:koin-android-architecture:${versions.koin}"
implementation "androidx.core:core-ktx:${versions.androidX}"
//androidTestImplementation "androidx.test.uiautomator:uiautomator:${versions.uiAutomator}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${versions.kotlinCoroutines}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.kotlinCoroutines}"
implementation "androidx.multidex:multidex:${versions.multidex}"
androidTestImplementation "androidx.test.espresso:espresso-intents:${versions.espresso}"
androidTestImplementation ("androidx.test.espresso:espresso-core:${versions.espresso}") {
exclude module: 'support-annotations'
}
androidTestImplementation "androidx.test.uiautomator:uiautomator:${versions.uiAutomator}"
testImplementation "org.robolectric:robolectric:${versions.robolectric}"
testImplementation "junit:junit:${versions.junit}"
testImplementation "org.mockito:mockito-core:${versions.mockito}"
testImplementation "org.jdom:jdom2:${versions.jdom}"
//TODO: SWITCH TO ANDROID-X
implementation "androidx.test.espresso:espresso-idling-resource:3.2.0"
implementation "androidx.test.espresso:espresso-idling-resource:${versions.espresso}"
androidTestImplementation "androidx.test.espresso.idling:idling-concurrent:${versions.espresso}"
androidTestImplementation "androidx.test.espresso:espresso-contrib:${versions.espresso}"
testImplementation "androidx.test:core:${versions.androidX}"
testImplementation "androidx.test.ext:junit:${versions.androidX}"
testImplementation "androidx.test:rules:${versions.runner_rules}"
testImplementation "androidx.test:runner:${versions.runner_rules}"
testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
testImplementation "org.robolectric:robolectric:${versions.robolectric}"
......@@ -118,14 +125,7 @@ dependencies {
testImplementation "com.nhaarman:mockito-kotlin:${versions.mockitoKotlin}"
testImplementation "org.jdom:jdom2:2.0.6"
testImplementation "org.koin:koin-test:${versions.koin}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${versions.kotlinCoroutines}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.kotlinCoroutines}"
implementation "androidx.multidex:multidex:${versions.multidex}"
implementation 'com.google.code.gson:gson:2.8.2'
testImplementation "org.robolectric:shadows-multidex:${versions.robolectric}"
// Cucumber
androidTestImplementation('info.cukes:cucumber-android:1.2.4') {
......@@ -138,24 +138,13 @@ dependencies {
androidTestImplementation 'info.cukes:cucumber-jvm-deps:1.0.5'
// Screenshots
androidTestImplementation 'com.squareup.spoon:spoon-client:1.7.1'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:core:1.2.1-alpha02'
androidTestImplementation('com.schibsted.spain:barista:2.8.0') {
exclude group: 'com.android.support'
//exclude group: 'org.jetbrains.kotlin' // Only if you already use Kotlin in your project
}
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
}
android {
sourceSets {
androidTest {
assets.srcDirs = ['src/androidTest/assets']
}
}
compileSdkVersion buildConfig.compileSdk
defaultConfig {
......@@ -169,7 +158,7 @@ android {
setProperty("archivesBaseName", "$buildConfig.versionName-$versionCode")
generatedDensities = ["mdpi", "hdpi", "xhdpi"]
//testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testApplicationId "com.fsck.k9.pEp.ui.activities.test"
testInstrumentationRunner "com.fsck.k9.pEp.ui.activities.runner.CucumberTestRunner"
......@@ -276,6 +265,20 @@ android {
}
}
testOptions{
unitTests{
includeAndroidResources = true
}
}
sourceSets {
test.manifest.srcFile "src/test/AndroidManifest.xml"
androidTest {
manifest.srcFile "src/androidTest/AndroidManifest.xml"
assets.srcDirs = ['src/androidTest/assets']
}
}
}
androidExtensions {
......
package com.fsck.k9.pEp.ui.activities;
import androidx.test.InstrumentationRegistry;
import android.test.suitebuilder.annotation.LargeTest;
import androidx.test.espresso.IdlingRegistry;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.UiDevice;
import com.fsck.k9.R;
......@@ -17,7 +18,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import foundation.pEp.jniadapter.Rating;
import pEp.jniadapter.Rating;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
......@@ -39,16 +40,16 @@ public class GreyStatusMessageTest {
public void startpEpApp() {
testUtils = new TestUtils(UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()), InstrumentationRegistry.getInstrumentation());
espressoTestingIdlingResource = new EspressoTestingIdlingResource();
IdlingRegistry.getInstance().register(espressoTestingIdlingResource.getIdlingResource());
IdlingRegistry.getInstance().register(EspressoTestingIdlingResource.getIdlingResource());
testUtils.startActivity();
}
@After
public void unregisterIdlingResource() {
IdlingRegistry.getInstance().unregister(espressoTestingIdlingResource.getIdlingResource());
IdlingRegistry.getInstance().unregister(EspressoTestingIdlingResource.getIdlingResource());
}
@Test (timeout = TIMEOUT_TEST)
@Test(timeout = TIMEOUT_TEST)
public void greyStatusEmail() {
greyStatusEmailTest(false);
}
......@@ -59,9 +60,9 @@ public class GreyStatusMessageTest {
testUtils.composeMessageButton();
testUtils.testStatusEmpty();
testUtils.testStatusMail(new TestUtils.BasicMessage("", "Subject", "Message", EMAIL),
new TestUtils.BasicIdentity(Rating.pEpRatingUnencrypted, ""));
new TestUtils.BasicIdentity(Rating.pEpRatingUnencrypted, ""));
testUtils.testStatusMail(new TestUtils.BasicMessage("", "", "", ""),
new TestUtils.BasicIdentity(Rating.pEpRatingUndefined, ""));
new TestUtils.BasicIdentity(Rating.pEpRatingUndefined, ""));
testUtils.testStatusMail(new TestUtils.BasicMessage("", "Subject", "Message", EMAIL),
new TestUtils.BasicIdentity(Rating.pEpRatingUnencrypted, ""));
testUtils.pressBack();
......
package com.fsck.k9.pEp.ui.fragments;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
import com.fsck.k9.R;
import com.fsck.k9.activity.setup.AccountSetupBasics;
......
This diff is collapsed.
package com.fsck.k9.activity.compose;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
......@@ -15,15 +10,22 @@ import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Contacts.Data;
import androidx.annotation.Nullable;
import androidx.loader.content.AsyncTaskLoader;
import androidx.core.content.ContextCompat;
import androidx.loader.content.AsyncTaskLoader;
import com.fsck.k9.R;
import com.fsck.k9.mail.Address;
import com.fsck.k9.view.RecipientSelectView.Recipient;
import com.fsck.k9.view.RecipientSelectView.RecipientCryptoStatus;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static android.Manifest.permission.READ_CONTACTS;
import static android.Manifest.permission.WRITE_CONTACTS;
......@@ -113,29 +115,35 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
@Override
public List<Recipient> loadInBackground() {
List<Recipient> recipients = new ArrayList<>();
Map<String, Recipient> recipientMap = new HashMap<>();
if (addresses != null) {
fillContactDataFromAddresses(addresses, recipients, recipientMap);
} else if (contactUri != null) {
fillContactDataFromEmailContentUri(contactUri, recipients, recipientMap);
} else if (query != null) {
fillContactDataFromQuery(query, recipients, recipientMap);
} else if (lookupKeyUri != null) {
fillContactDataFromLookupKey(lookupKeyUri, recipients, recipientMap);
} else {
throw new IllegalStateException("loader must be initialized with query or list of addresses!");
}
if (recipients.isEmpty()) {
return recipients;
}
int writeContactsPermission = ContextCompat.checkSelfPermission(getContext(), WRITE_CONTACTS);
int readContactsPermission = ContextCompat.checkSelfPermission(getContext(), READ_CONTACTS);
if (writeContactsPermission == PackageManager.PERMISSION_GRANTED &&
readContactsPermission == PackageManager.PERMISSION_GRANTED) {
Map<String, Recipient> recipientMap = new HashMap<>();
if (addresses != null) {
fillContactDataFromAddresses(addresses, recipients, recipientMap);
} else if (contactUri != null) {
fillContactDataFromEmailContentUri(contactUri, recipients, recipientMap);
} else if (query != null) {
fillContactDataFromQuery(query, recipients, recipientMap);
} else if (lookupKeyUri != null) {
fillContactDataFromLookupKey(lookupKeyUri, recipients, recipientMap);
} else {
throw new IllegalStateException("loader must be initialized with query or list of addresses!");
}
if (cryptoProvider != null) {
fillCryptoStatusData(recipientMap);
}
if (recipients.isEmpty()) {
return recipients;
}
if (cryptoProvider != null) {
fillCryptoStatusData(recipientMap);
}
}
return recipients;
}
......@@ -267,13 +275,9 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
String selection = Contacts.DISPLAY_NAME_PRIMARY + " LIKE ? " +
" OR (" + Email.ADDRESS + " LIKE ? AND " + Data.MIMETYPE + " = '" + Email.CONTENT_ITEM_TYPE + "')";
String[] selectionArgs = { query, query };
Cursor cursor = null;
int permissionCheck = ContextCompat.checkSelfPermission(getContext(),
WRITE_CONTACTS);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
cursor = contentResolver.query(queryUri, PROJECTION, selection, selectionArgs, SORT_ORDER);
}
String[] selectionArgs = {query, query};
Cursor cursor = contentResolver.query(queryUri, PROJECTION, selection, selectionArgs, SORT_ORDER);
if (cursor == null) {
return false;
......
......@@ -126,13 +126,6 @@ public class AccountSetupBasics extends PEpImporterActivity {
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.account_setup_basic_option, menu);
return true;
}
@Override
protected void refresh() {
}
......
......@@ -4427,8 +4427,9 @@ public class MessagingController implements Sync.MessageToSendCallback, KeyImpor
}
// Do not notify if the user does not have notifications enabled or if the message has
// been read.
if (!account.isNotifyNewMail() || message.isSet(Flag.SEEN)) {
// been read or it is an pep-autoconsume-message.
if (!account.isNotifyNewMail() || message.isSet(Flag.SEEN)
|| PEpUtils.isAutoConsumeMessage(message)) {
return false;
}
......
......@@ -80,7 +80,7 @@ class PEpMessageBuilder {
String charset = MimeUtility.getHeaderParameter(mm.getContentType(), "charset");
if (!Charset.isSupported(charset)) {
if (charset == null || !Charset.isSupported(charset)) {
// failback when the header doesn't have charset parameter or it is invalid, defaults to UTF-8
// FIXME: charset, trate non text bod4y types like application/pgp-keys
charset = Charset.defaultCharset().name();
......
......@@ -16,6 +16,8 @@ import android.text.InputType;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
......@@ -143,9 +145,16 @@ public class AccountSetupBasicsFragment extends PEpFragment
mEmailView.setText(email);
mPasswordView.setText(password);
}
setHasOptionsMenu(true);
return rootView;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.account_setup_basic_option, menu);
}
private void setupToolbar() {
((AccountSetupBasics) getActivity()).initializeToolbar(true, R.string.account_setup_basics_title);
((AccountSetupBasics) getActivity()).setStatusBarPepColor(getResources().getColor(R.color.pep_green));
......
......@@ -5,6 +5,7 @@ import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.preference.CheckBoxPreference
import androidx.preference.MultiSelectListPreference
import androidx.preference.Preference
import com.fsck.k9.BuildConfig
......@@ -43,6 +44,7 @@ class GeneralSettingsFragment : PreferenceFragmentCompat() {
initializeNotificationQuickDelete()
initializeExtraKeysManagement()
initializeGlobalpEpKeyReset()
initializeAfterMessageDeleteBehavior()
if (!BuildConfig.WITH_KEY_SYNC) {
hideKeySyncOptions()
......@@ -130,6 +132,22 @@ class GeneralSettingsFragment : PreferenceFragmentCompat() {
}
}
private fun initializeAfterMessageDeleteBehavior() {
val returnToList: CheckBoxPreference? = findPreference(MESSAGEVIEW_RETURN_TO_LIST) as? CheckBoxPreference
val showNextMsg: CheckBoxPreference? = findPreference(MESSAGEVIEW_SHOW_NEXT_MSG) as? CheckBoxPreference
returnToList?.setOnPreferenceChangeListener { _, check ->
showNextMsg?.isChecked = !(check as Boolean)
true
}
showNextMsg?.setOnPreferenceChangeListener { _, check ->
returnToList?.isChecked = !(check as Boolean)
true
}
}
private fun dopEpKeyReset() {
disableKeyResetClickListener()
loading?.visibility = View.VISIBLE
......@@ -194,6 +212,8 @@ class GeneralSettingsFragment : PreferenceFragmentCompat() {
private const val PREFERENCE_PEP_EXTRA_KEYS = "pep_extra_keys"
private const val PREFERENCE_PEP_OWN_IDS_KEY_RESET = "pep_key_reset"
private const val PREFERENCE_PEP_ENABLE_SYNC = "pep_enable_sync"
private const val MESSAGEVIEW_RETURN_TO_LIST = "messageview_return_to_list"
private const val MESSAGEVIEW_SHOW_NEXT_MSG = "messageview_show_next"
fun create(rootKey: String? = null) = GeneralSettingsFragment().withArguments(
......
......@@ -328,6 +328,7 @@
<string name="global_settings_messageview_return_to_list_summary">Return to message list after message deletion</string>
<string name="global_settings_messageview_show_next_label">Show next message after delete</string>
<string name="global_settings_messageview_show_next_summary">Show next message by default after message deletion</string>
<string name="global_settings_messageiew_after_delete_behavior_title">After message deleted behavior</string>
<string name="global_settings_confirm_actions_title">Confirm actions</string>
<string name="global_settings_confirm_actions_summary">Show a dialog whenever you perform selected actions</string>
......
<?xml version="1.0" encoding="utf-8"?>
<!--suppress AndroidElementNotAllowed -->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?><!--suppress AndroidElementNotAllowed -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/general_settings_title">
......@@ -198,8 +196,8 @@
android:title="@string/global_settings_messageview_autofit_width_label" />
<PreferenceCategory
android:key="message_view_advanced"
app:initialExpandedChildrenCount="0"
app:allowDividerAbove="false">
app:allowDividerAbove="false"
app:initialExpandedChildrenCount="0">
<CheckBoxPreference
android:key="messageview_fixedwidth_font"
android:summary="@string/global_settings_messageview_fixedwidth_summary"
......@@ -228,28 +226,32 @@
android:key="volume_navigation"
android:title="@string/volume_navigation_title" />
<CheckBoxPreference
android:key="messageview_return_to_list"
android:summary="@string/global_settings_messageview_return_to_list_summary"
android:title="@string/global_settings_messageview_return_to_list_label" />
<PreferenceCategory android:title="@string/global_settings_messageiew_after_delete_behavior_title">
<CheckBoxPreference
android:key="messageview_return_to_list"
android:summary="@string/global_settings_messageview_return_to_list_summary"
android:title="@string/global_settings_messageview_return_to_list_label" />
<CheckBoxPreference
android:key="messageview_show_next"
android:summary="@string/global_settings_messageview_show_next_summary"
android:title="@string/global_settings_messageview_show_next_label" />
<CheckBoxPreference
android:key="messageview_show_next"
android:summary="@string/global_settings_messageview_show_next_summary"
android:title="@string/global_settings_messageview_show_next_label" />
</PreferenceCategory>
<MultiSelectListPreference
android:dialogTitle="@string/global_settings_confirm_actions_title"
android:entries="@array/confirm_action_entries"
android:entryValues="@array/confirm_action_values"
android:key="confirm_actions"
android:summary="@string/global_settings_confirm_actions_summary"
android:title="@string/global_settings_confirm_actions_title" />
<PreferenceCategory>
<MultiSelectListPreference
android:dialogTitle="@string/global_settings_confirm_actions_title"
android:entries="@array/confirm_action_entries"
android:entryValues="@array/confirm_action_values"
android:key="confirm_actions"
android:summary="@string/global_settings_confirm_actions_summary"
android:title="@string/global_settings_confirm_actions_title" />
</PreferenceCategory>
<PreferenceCategory
android:key="advanced_interaction_preferences"
app:initialExpandedChildrenCount="0"
app:allowDividerAbove="false">
app:allowDividerAbove="false"
app:initialExpandedChildrenCount="0">
<CheckBoxPreference
android:key="start_integrated_inbox"
android:title="@string/start_integrated_inbox_title" />
......@@ -258,9 +260,9 @@
</PreferenceScreen>
<PreferenceScreen
android:title="@string/notifications_title"
android:icon="?attr/iconPreferencesNotifications"
android:key="notification_preferences">
android:key="notification_preferences"
android:title="@string/notifications_title">
<CheckBoxPreference
android:key="quiet_time_enabled"
......@@ -306,8 +308,8 @@
</PreferenceScreen>
<PreferenceScreen
android:key="pep_global"
android:icon="?attr/iconpEpShield"
android:key="pep_global"
android:title="@string/privacy_preferences">
<!--<EditTextPreference-->
......@@ -337,23 +339,22 @@
<Preference
android:key="pep_key_reset"
android:title="@string/reset"
android:summary="@string/pep_key_reset_all_own_ids_summary"/>
android:summary="@string/pep_key_reset_all_own_ids_summary"
android:title="@string/reset" />
<Preference
android:persistent="false"
android:key="pep_extra_keys"
android:persistent="false"
android:singleLine="true"
android:title="@string/master_key_management"
android:summary="Encrypt messages with additional keys.">
</Preference>
android:summary="Encrypt messages with additional keys."
android:title="@string/master_key_management"/>
<SwitchPreferenceCompat
android:key="pep_enable_sync"
android:title="@string/pep_sync"
android:summaryOff="@string/pep_sync_is_disabled_global"
android:summaryOn="@string/pep_sync_is_enabled_global"
android:summaryOff="@string/pep_sync_is_disabled_global" />
android:title="@string/pep_sync" />
<PreferenceCategory
android:key="pep_gpg_compatibility"
......@@ -367,7 +368,6 @@
android:title="@string/pep_subject_unprotected" />
<Preference
android:key="pep_gpg_blacklist"
android:title="Blacklist">
......@@ -417,8 +417,6 @@
<!--/>-->
<!--Preference
android:key="pep_manage_keysync"
android:persistent="false"
......@@ -441,12 +439,12 @@
</PreferenceScreen>
<PreferenceScreen
android:icon="@drawable/ic_advanced_light"
android:key="advanced_preferences"
android:title="@string/advanced"
android:icon="@drawable/ic_advanced_light">
android:title="@string/advanced">
<PreferenceCategory
android:title="@string/miscellaneous_preferences"
android:key="misc_preferences">
android:key="misc_preferences"
android:title="@string/miscellaneous_preferences">
<Preference
android:key="attachment_default_path"
......@@ -468,8 +466,8 @@
android:title="@string/debug_preferences">
<CheckBoxPreference
android:key="debug_logging"
android:icon="?attr/iconPreferencesDebug"
android:key="debug_logging"
android:summary="@string/debug_enable_debug_logging_summary"
android:title="@string/debug_enable_debug_logging_title" />
......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.fsck.k9">
<application
android:allowBackup="false"
android:allowTaskReparenting="false"
android:icon="@mipmap/ic_pep_launcher"
android:roundIcon="@mipmap/ic_pep_launcher_round"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/Theme.K9.Light.NoActionBar"
tools:replace="android:allowBackup">
<activity
android:name=".activity.SettingsActivity"
android:configChanges="locale"
android:label="@string/app_name"
android:launchMode="singleTop"
android:uiOptions="splitActionBarWhenNarrow">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
......@@ -3,21 +3,25 @@ package com.fsck.k9.activity;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.mail.Message;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(K9RobolectricTestRunner.class)
@RunWith(AndroidJUnit4.class)
@Config(sdk = 22)
public class ActivityListenerTest {
private static final String FOLDER = "folder";
private static final String ERROR_MESSAGE = "errorMessage";
......@@ -29,13 +33,13 @@ public class ActivityListenerTest {
private Message message;
private ActivityListener activityListener;
@Before
public void before() {
context = RuntimeEnvironment.application;
context = ApplicationProvider.getApplicationContext();
account = createAccount();
message = mock(Message.class);
activityListener = new ActivityListener();
}
......
package com.fsck.k9.activity;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.mail.Flag;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
......@@ -14,8 +12,6 @@ import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
@RunWith(K9RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class MessageReferenceTest {
@Test
......@@ -59,7 +55,7 @@ public class MessageReferenceTest {
public void checkMessageReferenceWithChangedUid() {
MessageReference messageReferenceOne = createMessageReferenceWithFlag(
"account", "folder", "uid", Flag.ANSWERED);
MessageReference messageReferenceTwo = messageReferenceOne.withModifiedUid("---");
assertEquals("account", messageReferenceTwo.getAccountUuid());
......@@ -72,7 +68,7 @@ public class MessageReferenceTest {
public void checkMessageReferenceWithChangedFlag() {
MessageReference messageReferenceOne = createMessageReferenceWithFlag(
"account", "folder", "uid", Flag.ANSWERED);
MessageReference messageReferenceTwo = messageReferenceOne.withModifiedFlag(Flag.DELETED);
assertEquals("account", messageReferenceTwo.getAccountUuid());
......@@ -214,7 +210,7 @@ public class MessageReferenceTest {
}
private MessageReference createMessageReferenceWithFlag(String accountUuid, String folderName, String uid,
Flag flag) {
Flag flag) {
return new MessageReference(accountUuid, folderName, uid, flag);
}
......
package com.fsck.k9.activity.misc;
import com.fsck.k9.K9RobolectricTestRunner;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.fsck.k9.mail.Address;
import org.junit.Test;
......@@ -9,7 +10,7 @@ import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
@RunWith(K9RobolectricTestRunner.class)
@RunWith(AndroidJUnit4.class)
public class ContactPictureLoaderTest {
@Test
......
package com.fsck.k9.cache;
import androidx.test.core.app.ApplicationProvider;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.LocalMessage;
......@@ -10,7 +12,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import java.util.Collections;
import java.util.UUID;
......@@ -39,7 +40,7 @@ public class EmailProviderCacheTest {
public void before() {
MockitoAnnotations.initMocks(this);
cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), RuntimeEnvironment.application);
cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), ApplicationProvider.getApplicationContext());
when(mockLocalMessage.getId()).thenReturn(localMessageId);
when(mockLocalMessage.getFolder()).thenReturn(mockLocalMessageFolder);
when(mockLocalMessageFolder.getId()).thenReturn(localMessageFolderId);
......@@ -47,16 +48,16 @@ public class EmailProviderCacheTest {
@Test
public void getCache_returnsDifferentCacheForEachUUID() {
EmailProviderCache cache = EmailProviderCache.getCache("u001", RuntimeEnvironment.application);
EmailProviderCache cache2 = EmailProviderCache.getCache("u002", RuntimeEnvironment.application);
EmailProviderCache cache = EmailProviderCache.getCache("u001", ApplicationProvider.getApplicationContext());
EmailProviderCache cache2 = EmailProviderCache.getCache("u002", ApplicationProvider.getApplicationContext());
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", ApplicationProvider.getApplicationContext());
EmailProviderCache cache2 = EmailProviderCache.getCache("u001", ApplicationProvider.getApplicationContext());
assertSame(cache, cache2);
}
......
package com.fsck.k9.crypto;
import java.util.ArrayList;
import java.util.List;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.mail.BodyPart;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException;
......@@ -17,10 +15,14 @@ import com.fsck.k9.mail.internet.MimeMessageHelper;
import com.fsck.k9.mail.internet.MimeMultipart;
import com.fsck.k9.mail.internet.TextBody;
import com.fsck.k9.ui.crypto.MessageCryptoAnnotations;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
......@@ -29,7 +31,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@RunWith(K9RobolectricTestRunner.class)
@RunWith(AndroidJUnit4.class)
@Config(manifest = Config.NONE)
public class MessageDecryptVerifierTest {
private static final String MIME_TYPE_MULTIPART_ENCRYPTED = "multipart/encrypted";
......@@ -94,8 +96,8 @@ public class MessageDecryptVerifierTest {
Message message = messageFromBody(
multipart("mixed",
multipart("alternative",
pgpInlinePart,
bodypart("text/html")
pgpInlinePart,
bodypart("text/html")
),
bodypart("application/octet-stream")
)
......@@ -227,8 +229,8 @@ public class MessageDecryptVerifierTest {
Message message = messageFromBody(
multipart("mixed",
multipart("encrypted",
bodypart("application/pgp-encrypted"),
bodypart("application/octet-stream")
bodypart("application/pgp-encrypted"),
bodypart("application/octet-stream")
)
)
);
......@@ -335,10 +337,10 @@ public class MessageDecryptVerifierTest {
public void findEncrypted__withMultipartMixedSubSigned__shouldReturnSigned() throws Exception {
Message message = messageFromBody(
multipart("mixed",
multipart("signed",
bodypart("text/plain"),
bodypart("application/pgp-signature")
)
multipart("signed",
bodypart("text/plain"),
bodypart("application/pgp-signature")
)
)
);
......
package com.fsck.k9.crypto;
import com.fsck.k9.Identity;
import com.fsck.k9.K9RobolectricTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals;
@RunWith(K9RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class OpenPgpApiHelperTest {
@Test
public void buildUserId_withName_shouldCreateOpenPgpAccountName() {
Identity identity = new Identity();
identity.setEmail("user@domain.com");
identity.setName("Name");
String result = OpenPgpApiHelper.buildUserId(identity);
assertEquals("Name <user@domain.com>", result);
}
@Test
public void buildUserId_withoutName_shouldCreateOpenPgpAccountName() {
Identity identity = new Identity();
identity.setEmail("user@domain.com");
String result = OpenPgpApiHelper.buildUserId(identity);
assertEquals("<user@domain.com>", result);
}
}
......@@ -3,25 +3,24 @@ package com.fsck.k9.helper;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import com.fsck.k9.Account;
import com.fsck.k9.Identity;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.internet.MimeMessage;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@RunWith(K9RobolectricTestRunner.class)
......@@ -33,7 +32,7 @@ public class IdentityHelperTest {
@Before
public void setUp() throws Exception {
Context context = RuntimeEnvironment.application;
Context context = ApplicationProvider.getApplicationContext();
createDummyAccount(context);
msg = parseWithoutRecurse(toStream(
"From: <adam@example.org>\r\n" +
......
......@@ -5,12 +5,14 @@ import android.content.Context;
import android.graphics.Color;
import android.text.SpannableString;
import androidx.test.core.app.ApplicationProvider;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.mail.Address;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static junit.framework.Assert.assertEquals;
......@@ -25,7 +27,7 @@ public class MessageHelperTest {
@Before
public void setUp() throws Exception {
Context context = RuntimeEnvironment.application;
Context context = ApplicationProvider.getApplicationContext();
contacts = new Contacts(context);
mockContacts = new Contacts(context) {
@Override public String getNameForAddress(String address) {
......
package com.fsck.k9.helper;
import java.lang.reflect.Array;
import java.util.ArrayList;
import com.fsck.k9.Account;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.helper.ReplyToParser.ReplyToAddresses;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.internet.ListHeaders;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import java.lang.reflect.Array;
import java.util.ArrayList;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
......@@ -26,8 +24,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(K9RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class ReplyToParserTest {
private static final Address[] REPLY_TO_ADDRESSES = Address.parse("replyTo1@example.com, replyTo2@example.com");
private static final Address[] LIST_POST_ADDRESSES = Address.parse("listPost@example.com");
......
package com.fsck.k9.mailstore;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.mailstore.util.FileFactory;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
......@@ -23,8 +21,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
@RunWith(K9RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class DeferredFileBodyTest {
public static final String TEST_ENCODING = "test-encoding";
public static final byte[] TEST_DATA_SHORT = "test data".getBytes();
......
package com.fsck.k9.mailstore;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collections;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import androidx.test.core.app.ApplicationProvider;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.K9RobolectricTestRunner;
......@@ -22,6 +16,7 @@ import com.fsck.k9.mail.Multipart;
import com.fsck.k9.mail.internet.MessageExtractor;
import com.fsck.k9.mail.internet.MimeHeader;
import com.fsck.k9.mail.internet.MimeUtility;
import org.apache.commons.io.IOUtils;
import org.apache.james.mime4j.util.MimeUtil;
import org.junit.Assert;
......@@ -29,10 +24,17 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openintents.openpgp.util.OpenPgpUtils;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowLog;
import org.robolectric.shadows.ShadowSQLiteConnection;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collections;
@RunWith(K9RobolectricTestRunner.class)
public class MigrationTest {
......@@ -48,18 +50,18 @@ public class MigrationTest {
account = getNewAccount();
StorageManager storageManager = StorageManager.getInstance(RuntimeEnvironment.application);
StorageManager storageManager = StorageManager.getInstance(ApplicationProvider.getApplicationContext());
databaseFile = storageManager.getDatabase(account.getUuid(), account.getLocalStorageProviderId());
Assert.assertTrue(databaseFile.getParentFile().isDirectory() || databaseFile.getParentFile().mkdir());
attachmentDir = StorageManager.getInstance(RuntimeEnvironment.application).getAttachmentDirectory(
attachmentDir = StorageManager.getInstance(ApplicationProvider.getApplicationContext()).getAttachmentDirectory(
account.getUuid(), account.getLocalStorageProviderId());
Assert.assertTrue(attachmentDir.isDirectory() || attachmentDir.mkdir());
}
private SQLiteDatabase createV50Database() {
SQLiteDatabase db = RuntimeEnvironment.application.openOrCreateDatabase(databaseFile.getName(),
SQLiteDatabase db = ApplicationProvider.getApplicationContext().openOrCreateDatabase(databaseFile.getName(),
Context.MODE_PRIVATE, null);
String[] v50SchemaSql = new String[] {
......@@ -155,7 +157,7 @@ public class MigrationTest {
insertSimplePlaintextMessage(db);
db.close();
LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
LocalStore localStore = LocalStore.getInstance(account, ApplicationProvider.getApplicationContext());
LocalMessage msg = localStore.getFolder("dev").getMessage("3");
FetchProfile fp = new FetchProfile();
......@@ -222,7 +224,7 @@ public class MigrationTest {
insertMixedWithAttachments(db);
db.close();
LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
LocalStore localStore = LocalStore.getInstance(account, ApplicationProvider.getApplicationContext());
LocalMessage msg = localStore.getFolder("dev").getMessage("4");
FetchProfile fp = new FetchProfile();
......@@ -294,7 +296,7 @@ public class MigrationTest {
insertPgpMimeSignedMessage(db);
db.close();
LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
LocalStore localStore = LocalStore.getInstance(account, ApplicationProvider.getApplicationContext());
LocalMessage msg = localStore.getFolder("dev").getMessage("5");
FetchProfile fp = new FetchProfile();
......@@ -353,7 +355,7 @@ public class MigrationTest {
insertPgpMimeEncryptedMessage(db);
db.close();
LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
LocalStore localStore = LocalStore.getInstance(account, ApplicationProvider.getApplicationContext());
LocalMessage msg = localStore.getFolder("dev").getMessage("6");
FetchProfile fp = new FetchProfile();
......@@ -471,7 +473,7 @@ public class MigrationTest {
insertPgpInlineEncryptedMessage(db);
db.close();
LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
LocalStore localStore = LocalStore.getInstance(account, ApplicationProvider.getApplicationContext());
LocalMessage msg = localStore.getFolder("dev").getMessage("7");
FetchProfile fp = new FetchProfile();
......@@ -558,7 +560,7 @@ public class MigrationTest {
insertPgpInlineClearsignedMessage(db);
db.close();
LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
LocalStore localStore = LocalStore.getInstance(account, ApplicationProvider.getApplicationContext());
LocalMessage msg = localStore.getFolder("dev").getMessage("8");
FetchProfile fp = new FetchProfile();
......@@ -616,7 +618,7 @@ public class MigrationTest {
insertMultipartAlternativeMessage(db);
db.close();
LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
LocalStore localStore = LocalStore.getInstance(account, ApplicationProvider.getApplicationContext());
LocalMessage msg = localStore.getFolder("dev").getMessage("9");
FetchProfile fp = new FetchProfile();
......@@ -681,7 +683,7 @@ public class MigrationTest {
insertHtmlWithRelatedMessage(db);
db.close();
LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
LocalStore localStore = LocalStore.getInstance(account, ApplicationProvider.getApplicationContext());
LocalMessage msg = localStore.getFolder("dev").getMessage("10");
FetchProfile fp = new FetchProfile();
......@@ -717,7 +719,7 @@ public class MigrationTest {
}
private Account getNewAccount() {
Preferences preferences = Preferences.getPreferences(RuntimeEnvironment.application);
Preferences preferences = Preferences.getPreferences(ApplicationProvider.getApplicationContext());
//FIXME: This is a hack to get Preferences into a state where it's safe to call newAccount()
preferences.loadAccounts();
......
package com.fsck.k9.mailstore;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import android.app.Application;
import android.content.ContentValues;
import android.content.Context;
......@@ -13,6 +8,8 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;
import androidx.test.core.app.ApplicationProvider;
import com.fsck.k9.Account;
import com.fsck.k9.BuildConfig;
import com.fsck.k9.GlobalsHelper;
......@@ -20,13 +17,18 @@ import com.fsck.k9.K9;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.R;
import com.fsck.k9.mail.MessagingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
......@@ -47,7 +49,7 @@ public class StoreSchemaDefinitionTest {
public void setUp() throws MessagingException {
ShadowLog.stream = System.out;
Application application = RuntimeEnvironment.application;
Application application = ApplicationProvider.getApplicationContext();
K9.app = application;
GlobalsHelper.setContext(application);
StorageManager.getInstance(application);
......@@ -244,7 +246,7 @@ public class StoreSchemaDefinitionTest {
}
private void assertMessageWithSubjectExists(SQLiteDatabase database, String subject) {
Cursor cursor = database.query("messages", new String[] { "subject" }, null, null, null, null, null);
Cursor cursor = database.query("messages", new String[]{"subject"}, null, null, null, null, null);
try {
assertTrue(cursor.moveToFirst());
assertEquals(subject, cursor.getString(0));
......@@ -298,7 +300,7 @@ public class StoreSchemaDefinitionTest {
private List<String> objectsInDatabase(SQLiteDatabase db, String type) {
List<String> databaseObjects = new ArrayList<>();
Cursor cursor = db.rawQuery("SELECT sql FROM sqlite_master WHERE type = ? AND sql IS NOT NULL",
new String[] { type });
new String[]{type});
try {
while (cursor.moveToNext()) {
String sql = cursor.getString(cursor.getColumnIndex("sql"));
......
package com.fsck.k9.message;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import android.app.Application;
import androidx.test.core.app.ApplicationProvider;
import com.fsck.k9.Account.QuoteStyle;
import com.fsck.k9.Identity;
import com.fsck.k9.RobolectricTest;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.activity.misc.Attachment;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.BodyPart;
import com.fsck.k9.mail.BoundaryGenerator;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.internet.MessageIdGenerator;
......@@ -28,11 +19,23 @@ import com.fsck.k9.mail.internet.MimeMessage;
import com.fsck.k9.mail.internet.MimeMultipart;
import com.fsck.k9.message.MessageBuilder.Callback;
import com.fsck.k9.message.quote.InsertableHtmlContent;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
......@@ -43,20 +46,21 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MessageBuilderTest extends RobolectricTest {
@RunWith(K9RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class MessageBuilderTest {
private static final String TEST_MESSAGE_TEXT = "soviet message\r\ntext ☭";
private static final String TEST_ATTACHMENT_TEXT = "text data in attachment";
private static final String TEST_SUBJECT = "test_subject";
private static final Address TEST_IDENTITY_ADDRESS = new Address("test@example.org", "tester");
private static final Address[] TEST_TO = new Address[] {
private static final Address[] TEST_TO = new Address[]{
new Address("to1@example.org", "recip 1"),
new Address("to2@example.org", "recip 2")
};
private static final Address[] TEST_CC = new Address[] {
new Address("cc@example.org", "cc recip") };
private static final Address[] TEST_BCC = new Address[] {
new Address("bcc@example.org", "bcc recip") };
private static final Address[] TEST_CC = new Address[]{
new Address("cc@example.org", "cc recip")};
private static final Address[] TEST_BCC = new Address[]{
new Address("bcc@example.org", "bcc recip")};
private static final String TEST_MESSAGE_ID = "<00000000-0000-007B-0000-0000000000EA@pretty.Easy.privacy>";
private static final Date SENT_DATE = new Date(10000000000L);
......@@ -110,28 +114,28 @@ public class MessageBuilderTest extends RobolectricTest {
private static final String MESSAGE_CONTENT_WITH_LONG_FILE_NAME =
"Content-Type: multipart/mixed; boundary=\"" + BOUNDARY_1 + "\"\r\n" +
"Content-Transfer-Encoding: 7bit\r\n" +
"\r\n" +
"--" + BOUNDARY_1 + "\r\n" +
"Content-Type: text/plain;\r\n" +
" charset=utf-8\r\n" +
"Content-Transfer-Encoding: quoted-printable\r\n" +
"\r\n" +
"soviet message\r\n" +
"text =E2=98=AD\r\n" +
"--" + BOUNDARY_1 + "\r\n" +
"Content-Type: text/plain;\r\n" +
" name*0*=UTF-8''~~~~~~~~~1~~~~~~~~~2~~~~~~~~~3~~~~~~~~~4~~~~~~~~~5~~~~~~~~~6~;\r\n" +
" name*1*=~~~~~~~~7.txt\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"Content-Disposition: attachment;\r\n" +
" filename*0*=UTF-8''~~~~~~~~~1~~~~~~~~~2~~~~~~~~~3~~~~~~~~~4~~~~~~~~~5~~~~~~~;\r\n" +
" filename*1*=~~6~~~~~~~~~7.txt;\r\n" +
" size=23\r\n" +
"\r\n" +
"dGV4dCBkYXRhIGluIGF0dGFjaG1lbnQ=\r\n" +
"\r\n" +
"--" + BOUNDARY_1 + "--\r\n";
"Content-Transfer-Encoding: 7bit\r\n" +
"\r\n" +
"--" + BOUNDARY_1 + "\r\n" +
"Content-Type: text/plain;\r\n" +
" charset=utf-8\r\n" +
"Content-Transfer-Encoding: quoted-printable\r\n" +
"\r\n" +
"soviet message\r\n" +
"text =E2=98=AD\r\n" +
"--" + BOUNDARY_1 + "\r\n" +
"Content-Type: text/plain;\r\n" +
" name*0*=UTF-8''~~~~~~~~~1~~~~~~~~~2~~~~~~~~~3~~~~~~~~~4~~~~~~~~~5~~~~~~~~~6~;\r\n" +
" name*1*=~~~~~~~~7.txt\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"Content-Disposition: attachment;\r\n" +
" filename*0*=UTF-8''~~~~~~~~~1~~~~~~~~~2~~~~~~~~~3~~~~~~~~~4~~~~~~~~~5~~~~~~~;\r\n" +
" filename*1*=~~6~~~~~~~~~7.txt;\r\n" +
" size=23\r\n" +
"\r\n" +
"dGV4dCBkYXRhIGluIGF0dGFjaG1lbnQ=\r\n" +
"\r\n" +
"--" + BOUNDARY_1 + "--\r\n";
private static final String ATTACHMENT_FILENAME_NON_ASCII = "テスト文書.txt";
private static final String MESSAGE_CONTENT_WITH_ATTACH_NON_ASCII_FILENAME = "" +
......@@ -195,7 +199,7 @@ public class MessageBuilderTest extends RobolectricTest {
when(boundaryGenerator.generateBoundary()).thenReturn(BOUNDARY_1, BOUNDARY_2, BOUNDARY_3);
callback = mock(Callback.class);
context = RuntimeEnvironment.application;
context = ApplicationProvider.getApplicationContext();
}
@Test
......@@ -266,7 +270,7 @@ public class MessageBuilderTest extends RobolectricTest {
MimeMessage message = getMessageFromCallback();
assertEquals(MimeMultipart.class, message.getBody().getClass());
assertEquals("multipart/alternative", ((MimeMultipart) message.getBody()).getMimeType());
List<BodyPart> parts = ((MimeMultipart) message.getBody()).getBodyParts();
List<BodyPart> parts = ((MimeMultipart) message.getBody()).getBodyParts();
//RFC 2046 - 5.1.4. - Best type is last displayable
assertEquals("text/plain", parts.get(0).getMimeType());
assertEquals("text/html", parts.get(1).getMimeType());
......@@ -360,7 +364,7 @@ public class MessageBuilderTest extends RobolectricTest {
fileOutputStream.write(bytes);
fileOutputStream.close();
return Attachment.createAttachment(null, 0, mimeType, true)
return Attachment.createAttachment(null, 0, mimeType)
.deriveWithMetadataLoaded(mimeType, filename, bytes.length)
.deriveWithLoadComplete(tempFile.getAbsolutePath());
}
......
......@@ -3,7 +3,9 @@ package com.fsck.k9.message.extractors;
import android.content.Context;
import android.net.Uri;
import androidx.annotation.Nullable;
import androidx.test.core.app.ApplicationProvider;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.mail.Part;
......@@ -11,13 +13,13 @@ import com.fsck.k9.mail.internet.MimeBodyPart;
import com.fsck.k9.mail.internet.MimeHeader;
import com.fsck.k9.mail.internet.TextBody;
import com.fsck.k9.mailstore.AttachmentViewInfo;
import com.fsck.k9.mailstore.LocalBodyPart;
import com.fsck.k9.mailstore.DeferredFileBody;
import com.fsck.k9.mailstore.LocalBodyPart;
import com.fsck.k9.provider.AttachmentProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals;
......@@ -44,7 +46,7 @@ public class AttachmentInfoExtractorTest {
@Before
public void setUp() throws Exception {
context = RuntimeEnvironment.application;
context = ApplicationProvider.getApplicationContext();
attachmentInfoExtractor = new AttachmentInfoExtractor(context);
}
......@@ -109,7 +111,7 @@ public class AttachmentInfoExtractorTest {
public void extractInfoForDb__withContentTypeAndEncodedWordName__shouldReturnDecodedName() throws Exception