Merge pull request #3277 from k9mail/derobolectrify_tests

Remove Robolectric from tests where we don't need it
This commit is contained in:
Vincent Breitmoser 2018-03-24 13:14:32 +01:00 committed by GitHub
commit 5ebc9e400c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 83 additions and 125 deletions

View file

@ -1,15 +1,11 @@
package com.fsck.k9.mail.internet;
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
@RunWith(K9LibRobolectricTestRunner.class)
public class DecoderUtilTest {
private static final String INVALID = "=?utf-8?Q??=";

View file

@ -2,13 +2,11 @@ package com.fsck.k9.mail.internet;
import com.fsck.k9.mail.Body;
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mailstore.BinaryMemoryBody;
import org.apache.james.mime4j.util.MimeUtil;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -17,7 +15,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(K9LibRobolectricTestRunner.class)
public class MessageExtractorTest {
private MimeBodyPart part;

View file

@ -1,16 +1,12 @@
package com.fsck.k9.mail.store.imap;
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@RunWith(K9LibRobolectricTestRunner.class)
public class ImapPushStateTest {
@Test
public void parse_withValidArgument() throws Exception {

View file

@ -6,12 +6,10 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
import com.fsck.k9.mail.PushReceiver;
import com.fsck.k9.mail.store.StoreConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doThrow;
@ -20,7 +18,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(K9LibRobolectricTestRunner.class)
public class ImapPusherTest {
private ImapStore imapStore;
private TestImapPusher imapPusher;

View file

@ -6,11 +6,9 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
import com.fsck.k9.mail.filter.FixedLengthInputStream;
import com.fsck.k9.mail.filter.PeekableInputStream;
import org.junit.Test;
import org.junit.runner.RunWith;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
@ -19,7 +17,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(K9LibRobolectricTestRunner.class)
public class ImapResponseParserTest {
private PeekableInputStream peekableInputStream;

View file

@ -17,17 +17,14 @@
package com.fsck.k9.mail.store.imap;
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
@RunWith(K9LibRobolectricTestRunner.class)
public class ImapUtilityTest {
@Test
public void testGetImapSequenceValues() {

View file

@ -1,13 +1,23 @@
package com.fsck.k9.mail.store.webdav;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fsck.k9.mail.FetchProfile;
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessageRetrievalListener;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.internet.BinaryTempFileBody;
import com.fsck.k9.mail.store.StoreConfig;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpUriRequest;
@ -16,7 +26,6 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.protocol.HttpContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Matchers;
@ -25,11 +34,10 @@ import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import static java.util.Collections.singletonList;
import static com.fsck.k9.mail.Folder.OPEN_MODE_RW;
import static com.fsck.k9.mail.Folder.OPEN_MODE_RO;
import static com.fsck.k9.mail.Folder.OPEN_MODE_RW;
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
@ -44,21 +52,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings("deprecation")
@RunWith(K9LibRobolectricTestRunner.class)
public class WebDavFolderTest {
@Mock
private MessageRetrievalListener<WebDavMessage> listener;

View file

@ -1,22 +1,19 @@
package com.fsck.k9.mail.store.webdav;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
import com.fsck.k9.mail.MessagingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.Collections;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.MessagingException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(K9LibRobolectricTestRunner.class)
public class WebDavMessageTest {
private WebDavMessage message;

View file

@ -43,7 +43,7 @@ dependencies {
implementation 'com.xwray:groupie-kotlin-android-extensions:2.0.3'
implementation "org.jetbrains.anko:anko-coroutines:0.10.4"
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
testImplementation "org.robolectric:robolectric:${robolectricVersion}"
testImplementation "junit:junit:${junitVersion}"

View file

@ -16,7 +16,6 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
@ -110,18 +109,6 @@ public class Account implements BaseAccount, StoreConfig {
public static final String IDENTITY_EMAIL_KEY = "email";
public static final String IDENTITY_DESCRIPTION_KEY = "description";
/*
* https://developer.android.com/design/style/color.html
* Note: Order does matter, it's the order in which they will be picked.
*/
private static final Integer[] PREDEFINED_COLORS = new Integer[] {
Color.parseColor("#0099CC"), // blue
Color.parseColor("#669900"), // green
Color.parseColor("#FF8800"), // orange
Color.parseColor("#CC0000"), // red
Color.parseColor("#9933CC") // purple
};
public enum SortType {
SORT_DATE(R.string.sort_earliest_first, R.string.sort_latest_first, false),
SORT_ARRIVAL(R.string.sort_earliest_first, R.string.sort_latest_first, false),
@ -296,7 +283,6 @@ public class Account implements BaseAccount, StoreConfig {
autoExpandFolder = INBOX;
inboxFolder = INBOX;
maxPushFolders = 10;
chipColor = pickColor(context);
goToUnreadMessageSearch = false;
subscribedFoldersOnly = false;
maximumPolledMessageAge = -1;
@ -339,28 +325,6 @@ public class Account implements BaseAccount, StoreConfig {
cacheChips();
}
/*
* Pick a nice Android guidelines color if we haven't used them all yet.
*/
private int pickColor(Context context) {
List<Account> accounts = Preferences.getPreferences(context).getAccounts();
List<Integer> availableColors = new ArrayList<>(PREDEFINED_COLORS.length);
Collections.addAll(availableColors, PREDEFINED_COLORS);
for (Account account : accounts) {
Integer color = account.getChipColor();
if (availableColors.contains(color)) {
availableColors.remove(color);
if (availableColors.isEmpty()) {
break;
}
}
}
return (availableColors.isEmpty()) ? ColorPicker.getRandomColor() : availableColors.get(0);
}
protected Account(Preferences preferences, String uuid) {
this.accountUuid = uuid;
loadAccount(preferences);

View file

@ -1,9 +1,19 @@
package com.fsck.k9.account;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import android.content.Context;
import android.graphics.Color;
import com.fsck.k9.Account;
import com.fsck.k9.Account.DeletePolicy;
import com.fsck.k9.Preferences;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.ServerSettings.Type;
import com.larswerkman.colorpicker.ColorPicker;
/**
@ -12,6 +22,18 @@ import com.fsck.k9.mail.ServerSettings.Type;
* TODO Move much of the code from com.fsck.k9.activity.setup.* into here
*/
public class AccountCreator {
/*
* https://developer.android.com/design/style/color.html
* Note: Order does matter, it's the order in which they will be picked.
*/
private static final Integer[] PREDEFINED_COLORS = new Integer[] {
Color.parseColor("#0099CC"), // blue
Color.parseColor("#669900"), // green
Color.parseColor("#FF8800"), // orange
Color.parseColor("#CC0000"), // red
Color.parseColor("#9933CC") // purple
};
public static DeletePolicy getDefaultDeletePolicy(Type type) {
switch (type) {
@ -45,4 +67,26 @@ public class AccountCreator {
throw new AssertionError("Unhandled ConnectionSecurity type encountered: " + securityType);
}
/*
* Pick a nice Android guidelines color if we haven't used them all yet.
*/
public static int pickColor(Context context) {
List<Account> accounts = Preferences.getPreferences(context).getAccounts();
List<Integer> availableColors = new ArrayList<>(PREDEFINED_COLORS.length);
Collections.addAll(availableColors, PREDEFINED_COLORS);
for (Account account : accounts) {
Integer color = account.getChipColor();
if (availableColors.contains(color)) {
availableColors.remove(color);
if (availableColors.isEmpty()) {
break;
}
}
}
return (availableColors.isEmpty()) ? ColorPicker.getRandomColor() : availableColors.get(0);
}
}

View file

@ -314,6 +314,7 @@ public class AccountSetupBasics extends K9Activity
}
if (mAccount == null) {
mAccount = Preferences.getPreferences(this).newAccount();
mAccount.setChipColor(AccountCreator.pickColor(this));
}
mAccount.setName(getOwnerName());
mAccount.setEmail(email);
@ -400,6 +401,7 @@ public class AccountSetupBasics extends K9Activity
if (mAccount == null) {
mAccount = Preferences.getPreferences(this).newAccount();
mAccount.setChipColor(AccountCreator.pickColor(this));
}
mAccount.setName(getOwnerName());
mAccount.setEmail(email);

View file

@ -9,8 +9,8 @@ import java.util.Stack;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import com.fsck.k9.helper.StringHelper;
import com.fsck.k9.mail.Body;
import com.fsck.k9.mail.BodyPart;
import com.fsck.k9.mail.MessagingException;
@ -278,7 +278,7 @@ public class MessageCryptoStructureDetector {
return false;
}
String text = MessageExtractor.getTextFromPart(part, TEXT_LENGTH_FOR_INLINE_CHECK);
if (TextUtils.isEmpty(text)) {
if (StringHelper.isNullOrEmpty(text)) {
return false;
}
text = text.trim();
@ -293,7 +293,7 @@ public class MessageCryptoStructureDetector {
return false;
}
String text = MessageExtractor.getTextFromPart(part, TEXT_LENGTH_FOR_INLINE_CHECK);
if (TextUtils.isEmpty(text)) {
if (StringHelper.isNullOrEmpty(text)) {
return false;
}
text = text.trim();

View file

@ -1,8 +1,8 @@
package com.fsck.k9.crypto;
import android.text.TextUtils;
import com.fsck.k9.Identity;
import com.fsck.k9.helper.StringHelper;
public class OpenPgpApiHelper {
@ -20,7 +20,7 @@ public class OpenPgpApiHelper {
StringBuilder sb = new StringBuilder();
String name = identity.getName();
if (!TextUtils.isEmpty(name)) {
if (!StringHelper.isNullOrEmpty(name)) {
sb.append(name).append(" ");
}
sb.append("<").append(identity.getEmail()).append(">");

View file

@ -0,0 +1,4 @@
@file:JvmName("StringHelper")
package com.fsck.k9.helper
fun isNullOrEmpty(text: String?) = text.isNullOrEmpty()

View file

@ -5,10 +5,13 @@ import com.fsck.k9.Account.DeletePolicy;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.ServerSettings.Type;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
public class AccountCreatorTest {
@Test

View file

@ -3,8 +3,6 @@ package com.fsck.k9.activity;
import com.fsck.k9.mail.Flag;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
@ -13,7 +11,6 @@ import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
@RunWith(RobolectricTestRunner.class)
public class MessageReferenceTest {
@Test

View file

@ -13,8 +13,6 @@ import com.fsck.k9.mail.internet.MimeMessageHelper;
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.RobolectricTestRunner;
import static com.fsck.k9.message.TestMessageConstructionUtils.bodypart;
import static com.fsck.k9.message.TestMessageConstructionUtils.messageFromBody;
@ -28,7 +26,6 @@ import static org.mockito.Mockito.mock;
@SuppressWarnings("WeakerAccess")
@RunWith(RobolectricTestRunner.class)
public class MessageCryptoStructureDetectorTest {
MessageCryptoAnnotations messageCryptoAnnotations = mock(MessageCryptoAnnotations.class);
static final String PGP_INLINE_DATA = "" +

View file

@ -3,13 +3,10 @@ package com.fsck.k9.crypto;
import com.fsck.k9.Identity;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
public class OpenPgpApiHelperTest {
@Test

View file

@ -12,8 +12,6 @@ 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.RobolectricTestRunner;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@ -22,7 +20,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
@RunWith(RobolectricTestRunner.class)
public class DeferredFileBodyTest {
public static final String TEST_ENCODING = "test-encoding";
public static final byte[] TEST_DATA_SHORT = "test data".getBytes();

View file

@ -4,8 +4,6 @@ package com.fsck.k9.message.extractors;
import com.fsck.k9.mail.Message;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static com.fsck.k9.message.MessageCreationHelper.createMessage;
import static com.fsck.k9.message.MessageCreationHelper.createMultipartMessage;
@ -17,7 +15,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(RobolectricTestRunner.class)
public class EncryptionDetectorTest {
private static final String CRLF = "\r\n";

View file

@ -14,13 +14,10 @@ import org.jsoup.nodes.Document;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static junit.framework.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
public class HtmlConverterTest {
// Useful if you want to write stuff to a file for debugging in a browser.
private static final boolean WRITE_TO_FILE = Boolean.parseBoolean(System.getProperty("k9.htmlConverterTest.writeToFile", "false"));

View file

@ -2,14 +2,11 @@ package com.fsck.k9.message.signature;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static com.fsck.k9.message.html.HtmlHelper.extractText;
import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
public class HtmlSignatureRemoverTest {
@Test
public void shouldStripSignatureFromK9StyleHtml() throws Exception {

View file

@ -11,8 +11,6 @@ import com.fsck.k9.MockHelper;
import com.fsck.k9.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -22,7 +20,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(RobolectricTestRunner.class)
public class BaseNotificationsTest {
private static final int ACCOUNT_COLOR = 0xAABBCC;
private static final String ACCOUNT_NAME = "AccountName";

View file

@ -3,15 +3,12 @@ package com.fsck.k9.notification;
import com.fsck.k9.Account;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(RobolectricTestRunner.class)
public class NotificationIdsTest {
private static final boolean INCOMING = true;
private static final boolean OUTGOING = false;

View file

@ -4,13 +4,10 @@ package com.fsck.k9.setup;
import com.fsck.k9.mail.ServerSettings.Type;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
public class ServerNameSuggesterTest {
private ServerNameSuggester serverNameSuggester;