Remove 'androidTest' tests

We don't regularly run them and most of them don't even compile anymore.
This commit is contained in:
cketti 2020-03-11 18:01:41 +01:00
parent f70f933cc0
commit c4ab630161
7 changed files with 0 additions and 696 deletions

View file

@ -36,8 +36,6 @@ dependencies {
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:${versions.mockitoKotlin}"
testImplementation "org.jdom:jdom2:2.0.6"
testImplementation "org.koin:koin-test:${versions.koin}"
androidTestImplementation "androidx.test.espresso:espresso-core:3.1.1"
}
android {

View file

@ -28,8 +28,6 @@ dependencies {
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:${versions.mockitoKotlin}"
testImplementation "org.jdom:jdom2:2.0.6"
testImplementation "org.koin:koin-test:${versions.koin}"
androidTestImplementation "androidx.test.espresso:espresso-core:3.1.1"
}
android {

View file

@ -1,137 +0,0 @@
package com.fsck.k9.external;
import java.util.List;
import android.database.Cursor;
import android.net.Uri;
import androidx.test.runner.AndroidJUnit4;
import android.test.ProviderTestCase2;
import android.test.mock.MockContentResolver;
import com.fsck.k9.Account;
import com.fsck.k9.Preferences;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class MessageProviderTest extends ProviderTestCase2 {
private MockContentResolver mMockResolver;
private Cursor cursor;
public MessageProviderTest() {
super(MessageProvider.class, MessageProvider.AUTHORITY);
}
@Before
@Override
public void setUp() throws Exception {
super.setUp();
mMockResolver = getMockContentResolver();
mContext = getMockContext();
Preferences preferences = Preferences.getPreferences(getMockContext());
List<Account> accountList = preferences.getAccounts();
for (Account account: accountList) {
preferences.deleteAccount(account);
}
}
@After
@Override
public void tearDown() throws Exception {
if (cursor != null) {
cursor.close();
}
super.tearDown();
}
private void createAccount() {
Preferences preferences = Preferences.getPreferences(getMockContext());
Account account = preferences.newAccount();
account.setDescription("TestAccount");
account.setChipColor(10);
account.setStoreUri("imap://user@domain.com/");
preferences.saveAccount(account);
}
@Test
public void query_forAccounts_withNoAccounts_returnsEmptyCursor() {
cursor = mMockResolver.query(
Uri.parse("content://" + MessageProvider.AUTHORITY + "/accounts/"),
null, null, null, null);
boolean isNotEmpty = cursor.moveToFirst();
assertFalse(isNotEmpty);
}
@Test
public void query_forAccounts_withAccount_returnsCursorWithData() {
createAccount();
cursor = mMockResolver.query(
Uri.parse("content://" + MessageProvider.AUTHORITY + "/accounts/"),
null, null, null, null);
boolean isNotEmpty = cursor.moveToFirst();
assertTrue(isNotEmpty);
}
@Test
public void query_forAccounts_withAccount_withNoProjection_returnsNumberAndName() {
createAccount();
cursor = mMockResolver.query(
Uri.parse("content://" + MessageProvider.AUTHORITY + "/accounts/"),
null, null, null, null);
cursor.moveToFirst();
assertEquals(2, cursor.getColumnCount());
assertEquals(0, cursor.getColumnIndex(MessageProvider.AccountColumns.ACCOUNT_NUMBER));
assertEquals(1, cursor.getColumnIndex(MessageProvider.AccountColumns.ACCOUNT_NAME));
assertEquals(0, cursor.getInt(0));
assertEquals("TestAccount", cursor.getString(1));
}
@Test
public void query_forInboxMessages_whenEmpty_returnsEmptyCursor() {
cursor = mMockResolver.query(
Uri.parse("content://" + MessageProvider.AUTHORITY + "/inbox_messages/"),
null, null, null, null);
boolean isNotEmpty = cursor.moveToFirst();
assertFalse(isNotEmpty);
}
@Test
public void query_forAccountUnreadMessages_whenNoAccount_returnsEmptyCursor() {
cursor = mMockResolver.query(
Uri.parse("content://" + MessageProvider.AUTHORITY + "/account_unread/0"),
null, null, null, null);
boolean isNotEmpty = cursor.moveToFirst();
assertFalse(isNotEmpty);
}
@Test
public void query_forAccountUnreadMessages_whenNoMessages_returns0Unread() {
createAccount();
cursor = mMockResolver.query(
Uri.parse("content://" + MessageProvider.AUTHORITY + "/account_unread/0"),
null, null, null, null);
cursor.moveToFirst();
assertEquals(2, cursor.getColumnCount());
assertEquals(1, cursor.getColumnIndex(MessageProvider.UnreadColumns.ACCOUNT_NAME));
assertEquals(0, cursor.getColumnIndex(MessageProvider.UnreadColumns.UNREAD));
assertEquals(0, cursor.getInt(0));
assertEquals("TestAccount", cursor.getString(1));
}
}

View file

@ -1,42 +0,0 @@
package com.fsck.k9.helper;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static junit.framework.Assert.assertEquals;
@RunWith(AndroidJUnit4.class)
public class FileHelperTest {
@Test
public void testSanitize1() {
checkSanitization(".._bla_", "../bla_");
}
@Test
public void testSanitize2() {
checkSanitization("_etc_bla", "/etc/bla");
}
@Test
public void testSanitize3() {
checkSanitization("_пPп", "+пPп");
}
@Test
public void testSanitize4() {
checkSanitization(".東京_!", ".東京?!");
}
@Test
public void testSanitize5() {
checkSanitization("Plan 9", "Plan 9");
}
private void checkSanitization(String expected, String actual) {
assertEquals(expected, FileHelper.sanitizeFilename(actual));
}
}

View file

@ -1,177 +0,0 @@
package com.fsck.k9.mailstore;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import android.content.Context;
import android.test.ApplicationTestCase;
import android.test.RenamingDelegatingContext;
import com.fsck.k9.Account;
import com.fsck.k9.DI;
import com.fsck.k9.K9;
import com.fsck.k9.mail.Body;
import com.fsck.k9.mail.FetchProfile;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.internet.BinaryTempFileBody;
import com.fsck.k9.mail.internet.MimeHeader;
import com.fsck.k9.mail.internet.MimeMessage;
public class ReconstructMessageFromDatabaseTest extends ApplicationTestCase<K9> {
public static final String MESSAGE_SOURCE = "From: from@example.com\r\n" +
"To: to@example.com\r\n" +
"Subject: Test Message \r\n" +
"Date: Thu, 13 Nov 2014 17:09:38 +0100\r\n" +
"Content-Type: multipart/mixed;\r\n" +
" boundary=\"----Boundary\"\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"MIME-Version: 1.0\r\n" +
"\r\n" +
"This is a multipart MIME message.\r\n" +
"------Boundary\r\n" +
"Content-Type: text/plain; charset=utf-8\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n" +
"Testing.\r\n" +
"This is a text body with some greek characters.\r\n" +
"αβγδεζηθ\r\n" +
"End of test.\r\n" +
"\r\n" +
"------Boundary\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"\r\n" +
"VGhpcyBpcyBhIHRl\r\n" +
"c3QgbWVzc2FnZQ==\r\n" +
"\r\n" +
"------Boundary--\r\n" +
"Hi, I'm the epilogue";
private Account account;
public ReconstructMessageFromDatabaseTest() {
super(K9.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
RenamingDelegatingContext context = new RenamingDelegatingContext(getContext(), "db-test-");
setContext(context);
BinaryTempFileBody.setTempDirectory(context.getCacheDir());
createApplication();
createDummyAccount(context);
}
private void createDummyAccount(Context context) {
account = new DummyAccount(context);
}
public void testThatByteIdenticalCopyOfMessageIsReconstructed() throws IOException, MessagingException {
LocalFolder folder = createFolderInDatabase();
MimeMessage message = parseMessage();
saveMessageToDatabase(folder, message);
LocalMessage localMessage = readMessageFromDatabase(folder, message);
String reconstructedMessage = writeMessageToString(localMessage);
assertEquals(MESSAGE_SOURCE, reconstructedMessage);
}
public void testAddMissingPart() throws MessagingException, IOException {
LocalFolder folder = createFolderInDatabase();
MimeMessage message = new MimeMessage();
message.addHeader("To", "to@example.com");
message.addHeader("MIME-Version", "1.0");
message.addHeader("Content-Type", "text/plain");
message.setServerExtra("text");
saveMessageToDatabase(folder, message);
LocalMessage localMessage = readMessageFromDatabase(folder, message);
assertEquals("to@example.com", localMessage.getHeader("To")[0]);
assertEquals("text/plain", localMessage.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0]);
assertEquals("text", localMessage.getServerExtra());
assertNull(localMessage.getBody());
Body body = new BinaryMemoryBody("Test message body".getBytes(), MimeUtil.ENC_7BIT);
localMessage.setBody(body);
folder.addPartToMessage(localMessage, localMessage);
LocalMessage completeLocalMessage = readMessageFromDatabase(folder, message);
String reconstructedMessage = writeMessageToString(completeLocalMessage);
assertEquals("To: to@example.com\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"Test message body",
reconstructedMessage);
}
protected MimeMessage parseMessage() throws IOException, MessagingException {
InputStream messageInputStream = new ByteArrayInputStream(MESSAGE_SOURCE.getBytes());
try {
return MimeMessage.parseMimeMessage(messageInputStream, true);
} finally {
messageInputStream.close();
}
}
protected LocalFolder createFolderInDatabase() throws MessagingException {
LocalStore localStore = DI.get(LocalStoreProvider.class).getInstance(account);
LocalFolder inbox = localStore.getFolder("INBOX");
localStore.createFolders(Collections.singletonList(inbox), 10);
return inbox;
}
protected void saveMessageToDatabase(LocalFolder folder, MimeMessage message) throws MessagingException {
folder.appendMessages(Collections.singletonList(message));
}
protected LocalMessage readMessageFromDatabase(LocalFolder folder, MimeMessage message) throws MessagingException {
LocalMessage localMessage = folder.getMessage(message.getUid());
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.BODY);
folder.fetch(Collections.singletonList(localMessage), fp, null);
folder.close();
return localMessage;
}
protected String writeMessageToString(LocalMessage localMessage) throws IOException, MessagingException {
ByteArrayOutputStream messageOutputStream = new ByteArrayOutputStream();
try {
localMessage.writeTo(messageOutputStream);
} finally {
messageOutputStream.close();
}
return new String(messageOutputStream.toByteArray());
}
static class DummyAccount extends Account {
protected DummyAccount(Context context) {
super(context);
}
}
}

View file

@ -1,333 +0,0 @@
package com.fsck.k9.provider;
import java.util.Arrays;
import java.util.Collections;
import java.util.GregorianCalendar;
import android.database.Cursor;
import android.database.SQLException;
import android.net.Uri;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import android.test.ProviderTestCase2;
import com.fsck.k9.Account;
import com.fsck.k9.DI;
import com.fsck.k9.Preferences;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.internet.MimeMessage;
import com.fsck.k9.mailstore.LocalStoreProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class EmailProviderTest extends ProviderTestCase2<EmailProvider> {
private MimeMessage message;
private MimeMessage laterMessage;
private MimeMessage reply;
private MimeMessage replyAtSameTime;
public EmailProviderTest() {
super(EmailProvider.class, EmailProvider.AUTHORITY);
}
private void buildMessages() {
message = new MimeMessage();
message.setSubject("Test Subject");
message.setSentDate(new GregorianCalendar(2016, 1, 2).getTime(), false);
message.setMessageId("<uid001@email.com>");
laterMessage = new MimeMessage();
laterMessage.setSubject("Test Subject2");
laterMessage.setSentDate(new GregorianCalendar(2016, 1, 3).getTime(), false);
reply = new MimeMessage();
reply.setSubject("Re: Test Subject");
reply.setSentDate(new GregorianCalendar(2016, 1, 3).getTime(), false);
reply.setMessageId("<uid002@email.com>");
reply.setInReplyTo("<uid001@email.com>");
replyAtSameTime = new MimeMessage();
replyAtSameTime.setSubject("Re: Test Subject");
replyAtSameTime.setSentDate(new GregorianCalendar(2016, 1, 2).getTime(), false);
replyAtSameTime.setMessageId("<uid002@email.com>");
replyAtSameTime.setInReplyTo("<uid001@email.com>");
}
@Before
@Override
public void setUp() throws Exception {
setContext(InstrumentationRegistry.getTargetContext());
super.setUp();
buildMessages();
}
@Test
public void onCreate_shouldReturnTrue() {
assertNotNull(getProvider());
boolean returnValue = getProvider().onCreate();
assertEquals(true, returnValue);
}
@Test(expected = IllegalArgumentException.class)
public void query_withInvalidURI_throwsIllegalArgumentException() {
getProvider().query(
Uri.parse("content://com.google.www"),
new String[] {},
"",
new String[] {},
"");
}
@Test(expected = IllegalArgumentException.class)
public void query_forMessagesWithInvalidAccount_throwsIllegalArgumentException() {
Cursor cursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/1/messages"),
new String[] {},
"",
new String[] {},
"");
assertNotNull(cursor);
}
@Test(expected = IllegalArgumentException.class)
public void query_forMessagesWithAccountAndWithoutRequiredFields_throwsIllegalArgumentException() {
Account account = Preferences.getPreferences(getContext()).newAccount();
account.getUuid();
Cursor cursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages"),
new String[] {},
"",
new String[] {},
"");
assertNotNull(cursor);
assertTrue(cursor.isAfterLast());
}
@Test(expected = SQLException.class) //Handle this better?
public void query_forMessagesWithAccountAndRequiredFieldsWithNoOrderBy_throwsSQLiteException() {
Account account = Preferences.getPreferences(getContext()).newAccount();
account.getUuid();
Cursor cursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages"),
new String[] {
EmailProvider.MessageColumns.ID,
EmailProvider.MessageColumns.FOLDER_ID,
EmailProvider.ThreadColumns.ROOT
},
"",
new String[] {},
"");
assertNotNull(cursor);
assertTrue(cursor.isAfterLast());
}
@Test
public void query_forMessagesWithEmptyAccountAndRequiredFieldsAndOrderBy_providesEmptyResult() {
Account account = Preferences.getPreferences(getContext()).newAccount();
account.getUuid();
Cursor cursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages"),
new String[] {
EmailProvider.MessageColumns.ID,
EmailProvider.MessageColumns.FOLDER_ID,
EmailProvider.ThreadColumns.ROOT,
EmailProvider.MessageColumns.SUBJECT
},
"",
new String[] {},
EmailProvider.MessageColumns.DATE);
assertNotNull(cursor);
assertFalse(cursor.moveToFirst());
}
@Test
public void query_forMessagesWithAccountAndRequiredFieldsAndOrderBy_providesResult() throws MessagingException {
Account account = Preferences.getPreferences(getContext()).newAccount();
account.getUuid();
DI.get(LocalStoreProvider.class).getInstance(account).getFolder("Inbox").appendMessages(Collections.singletonList(message));
Cursor cursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages"),
new String[] {
EmailProvider.MessageColumns.ID,
EmailProvider.MessageColumns.FOLDER_ID,
EmailProvider.ThreadColumns.ROOT,
EmailProvider.MessageColumns.SUBJECT },
"",
new String[] {},
EmailProvider.MessageColumns.DATE);
assertNotNull(cursor);
assertTrue(cursor.moveToFirst());
assertEquals(message.getSubject(), cursor.getString(3));
}
@Test
public void query_forMessagesWithAccountAndRequiredFieldsAndOrderBy_sortsCorrectly() throws MessagingException {
Account account = Preferences.getPreferences(getContext()).newAccount();
account.getUuid();
DI.get(LocalStoreProvider.class).getInstance(account)
.getFolder("Inbox").appendMessages(Arrays.asList(message, laterMessage));
Cursor cursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages"),
new String[] {
EmailProvider.MessageColumns.ID,
EmailProvider.MessageColumns.FOLDER_ID,
EmailProvider.ThreadColumns.ROOT,
EmailProvider.MessageColumns.SUBJECT
},
"",
new String[] {},
EmailProvider.MessageColumns.DATE + " DESC");
assertNotNull(cursor);
assertTrue(cursor.moveToFirst());
assertEquals(laterMessage.getSubject(), cursor.getString(3));
cursor.moveToNext();
assertEquals(message.getSubject(), cursor.getString(3));
}
@Test
public void query_forThreadedMessages_sortsCorrectly() throws MessagingException {
Account account = Preferences.getPreferences(getContext()).newAccount();
account.getUuid();
DI.get(LocalStoreProvider.class).getInstance(account)
.getFolder("Inbox").appendMessages(Arrays.asList(message, laterMessage));
Cursor cursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() +
"/messages/threaded"),
new String[] {
EmailProvider.MessageColumns.ID,
EmailProvider.MessageColumns.FOLDER_ID,
EmailProvider.ThreadColumns.ROOT,
EmailProvider.MessageColumns.SUBJECT,
EmailProvider.MessageColumns.DATE
},
"",
new String[] {},
EmailProvider.MessageColumns.DATE + " DESC");
assertNotNull(cursor);
assertTrue(cursor.moveToFirst());
assertEquals(laterMessage.getSubject(), cursor.getString(3));
cursor.moveToNext();
assertEquals(message.getSubject(), cursor.getString(3));
}
@Test
public void query_forThreadedMessages_showsThreadOfEmailOnce() throws MessagingException {
Account account = Preferences.getPreferences(getContext()).newAccount();
account.getUuid();
DI.get(LocalStoreProvider.class).getInstance(account).getFolder("Inbox").appendMessages(Collections.singletonList(message));
DI.get(LocalStoreProvider.class).getInstance(account).getFolder("Inbox").appendMessages(Collections.singletonList(reply));
Cursor cursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() +
"/messages/threaded"),
new String[] {
EmailProvider.MessageColumns.ID,
EmailProvider.MessageColumns.FOLDER_ID,
EmailProvider.ThreadColumns.ROOT,
EmailProvider.MessageColumns.SUBJECT,
EmailProvider.MessageColumns.DATE,
EmailProvider.SpecialColumns.THREAD_COUNT
},
"",
new String[] {},
EmailProvider.MessageColumns.DATE + " DESC");
assertNotNull(cursor);
assertTrue(cursor.moveToFirst());
assertEquals(2, cursor.getInt(5));
assertFalse(cursor.moveToNext());
}
@Test
public void query_forThreadedMessages_showsThreadOfEmailWithSameSendTimeOnce() throws MessagingException {
Account account = Preferences.getPreferences(getContext()).newAccount();
account.getUuid();
DI.get(LocalStoreProvider.class).getInstance(account).getFolder("Inbox").appendMessages(Collections.singletonList(message));
DI.get(LocalStoreProvider.class).getInstance(account).getFolder("Inbox").appendMessages(Collections.singletonList(replyAtSameTime));
Cursor cursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() +
"/messages/threaded"),
new String[] {
EmailProvider.MessageColumns.ID,
EmailProvider.MessageColumns.FOLDER_ID,
EmailProvider.ThreadColumns.ROOT,
EmailProvider.MessageColumns.SUBJECT,
EmailProvider.MessageColumns.DATE,
EmailProvider.SpecialColumns.THREAD_COUNT
},
"",
new String[] {},
EmailProvider.MessageColumns.DATE + " DESC");
assertNotNull(cursor);
assertTrue(cursor.moveToFirst());
assertEquals(2, cursor.getInt(5));
assertFalse(cursor.moveToNext());
}
@Test
public void query_forAThreadOfMessages_returnsMessage() throws MessagingException {
Account account = Preferences.getPreferences(getContext()).newAccount();
account.getUuid();
Message message = new MimeMessage();
message.setSubject("Test Subject");
message.setSentDate(new GregorianCalendar(2016, 1, 2).getTime(), false);
DI.get(LocalStoreProvider.class).getInstance(account).getFolder("Inbox").appendMessages(Collections.singletonList(message));
//Now get the thread id we just put in.
Cursor cursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages"),
new String[] {
EmailProvider.MessageColumns.ID,
EmailProvider.MessageColumns.FOLDER_ID,
EmailProvider.ThreadColumns.ROOT,
},
"",
new String[] {},
EmailProvider.MessageColumns.DATE);
assertNotNull(cursor);
cursor.moveToFirst();
String threadId = cursor.getString(2);
//Now check the message is listed under that thread
Cursor threadCursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() +
"/thread/" + threadId),
new String[] {
EmailProvider.MessageColumns.ID,
EmailProvider.MessageColumns.FOLDER_ID,
EmailProvider.ThreadColumns.ROOT,
EmailProvider.MessageColumns.SUBJECT,
EmailProvider.MessageColumns.DATE
},
"",
new String[] {},
EmailProvider.MessageColumns.DATE);
assertNotNull(threadCursor);
assertTrue(threadCursor.moveToFirst());
assertEquals(message.getSubject(), threadCursor.getString(3));
}
}

View file

@ -16,9 +16,6 @@ dependencies {
implementation "androidx.annotation:annotation:${versions.androidxAnnotation}"
implementation "com.jakewharton.timber:timber:${versions.timber}"
androidTestImplementation "androidx.test:runner:${versions.androidxTestRunner}"
androidTestImplementation "com.madgag.spongycastle:pg:1.51.0.0"
testImplementation project(":mail:testing")
testImplementation "org.robolectric:robolectric:${versions.robolectric}"
testImplementation "junit:junit:${versions.junit}"