Skip to content

Commit

Permalink
Merge pull request #3214 from k9mail/simplify_robolectric_tests
Browse files Browse the repository at this point in the history
Update Robolectric to 3.7.1 and simplify test annotations
  • Loading branch information
cketti authored Feb 27, 2018
2 parents 1496036 + 5d93d11 commit a8c4f69
Show file tree
Hide file tree
Showing 47 changed files with 116 additions and 169 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ androidBuildToolsVersion=27.0.3
androidSupportLibraryVersion=27.0.2
timberVersion=4.5.1

robolectricVersion=3.2.2
robolectricVersion=3.7.1
junitVersion=4.12
mockitoVersion=1.10.19
okioVersion=1.11.0
Expand Down
6 changes: 6 additions & 0 deletions k9mail/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ android {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

testOptions {
unitTests {
includeAndroidResources = true
}
}
}

if (project.hasProperty('keyAlias')) {
Expand Down
20 changes: 0 additions & 20 deletions k9mail/src/test/java/com/fsck/k9/K9RobolectricTestRunner.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

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.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import static junit.framework.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;


@RunWith(K9RobolectricTestRunner.class)
@RunWith(RobolectricTestRunner.class)
public class ActivityListenerTest {
private static final String FOLDER = "folder";
private static final String ERROR_MESSAGE = "errorMessage";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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 org.robolectric.RobolectricTestRunner;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
Expand All @@ -14,8 +13,7 @@
import static org.junit.Assert.assertNotNull;


@RunWith(K9RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class MessageReferenceTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Email;

import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.mail.Address;
import com.fsck.k9.view.RecipientSelectView.Recipient;
import com.fsck.k9.view.RecipientSelectView.RecipientCryptoStatus;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import static android.provider.ContactsContract.CommonDataKinds.Email.TYPE_HOME;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.mockito.AdditionalMatchers.aryEq;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
Expand All @@ -29,7 +29,7 @@


@SuppressWarnings("WeakerAccess")
@RunWith(K9RobolectricTestRunner.class)
@RunWith(RobolectricTestRunner.class)
public class RecipientLoaderTest {
static final String CRYPTO_PROVIDER = "cryptoProvider";
static final String[] PROJECTION = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.activity.compose.RecipientMvpView.CryptoSpecialModeDisplayType;
import com.fsck.k9.activity.compose.RecipientMvpView.CryptoStatusDisplayType;
import com.fsck.k9.activity.compose.RecipientPresenter.CryptoMode;
Expand All @@ -34,6 +33,7 @@
import org.openintents.openpgp.util.OpenPgpServiceConnection;
import org.openintents.openpgp.util.ShadowOpenPgpAsyncTask;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;

Expand All @@ -49,8 +49,8 @@


@SuppressWarnings("ConstantConditions")
@RunWith(K9RobolectricTestRunner.class)
@Config(shadows = {ShadowOpenPgpAsyncTask.class})
@RunWith(RobolectricTestRunner.class)
@Config(shadows = { ShadowOpenPgpAsyncTask.class })
public class RecipientPresenterTest {
private static final ReplyToAddresses TO_ADDRESSES = new ReplyToAddresses(Address.parse("[email protected]"));
private static final List<Address> ALL_TO_ADDRESSES = Arrays.asList(Address.parse("[email protected]"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.fsck.k9.activity.misc;


import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.mail.Address;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

import static org.junit.Assert.assertEquals;

@RunWith(K9RobolectricTestRunner.class)

@RunWith(RobolectricTestRunner.class)
public class ContactPictureLoaderTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.fsck.k9.autocrypt;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -14,16 +13,13 @@
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;


@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = 21)
@SuppressWarnings("WeakerAccess")
public class AutocryptHeaderParserTest {
AutocryptHeaderParser autocryptHeaderParser = AutocryptHeaderParser.getInstance();

Expand Down Expand Up @@ -123,8 +119,6 @@ private MimeMessage parseFromResource(String resourceName) throws IOException, M
}

private InputStream readFromResourceFile(String name) throws FileNotFoundException {
return new FileInputStream(RuntimeEnvironment.application.getPackageResourcePath() + "/src/test/resources/" + name);
return getClass().getResourceAsStream("/" + name);
}


}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.fsck.k9.cache;


import com.fsck.k9.K9RobolectricTestRunner;
import java.util.Collections;
import java.util.UUID;

import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.LocalMessage;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import java.util.Collections;
import java.util.UUID;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
Expand All @@ -24,7 +23,7 @@
import static org.mockito.Mockito.when;


@RunWith(K9RobolectricTestRunner.class)
@RunWith(RobolectricTestRunner.class)
public class EmailProviderCacheTest {

private EmailProviderCache cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.fsck.k9.Account;
import com.fsck.k9.AccountStats;
import com.fsck.k9.K9;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.Preferences;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.mail.AuthenticationFailedException;
Expand Down Expand Up @@ -46,6 +45,7 @@
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.shadows.ShadowLog;

Expand All @@ -70,7 +70,7 @@


@SuppressWarnings("unchecked")
@RunWith(K9RobolectricTestRunner.class)
@RunWith(RobolectricTestRunner.class)
public class MessagingControllerTest {
private static final String FOLDER_NAME = "Folder";
private static final String SENT_FOLDER_NAME = "Sent";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import com.fsck.k9.Account;
import com.fsck.k9.AccountStats;
import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.controller.MessagingListener;
import com.fsck.k9.controller.SimpleMessagingListener;
Expand All @@ -34,6 +33,7 @@
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.shadows.ShadowLog;

Expand All @@ -51,7 +51,7 @@


@SuppressWarnings("unchecked")
@RunWith(K9RobolectricTestRunner.class)
@RunWith(RobolectricTestRunner.class)
public class ImapSyncTest {
private static final String FOLDER_NAME = "Folder";
private static final int MAXIMUM_SMALL_MESSAGE_SIZE = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.ArrayList;
import java.util.List;

import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.mail.BodyPart;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.Multipart;
Expand All @@ -15,7 +14,7 @@
import com.fsck.k9.ui.crypto.MessageCryptoAnnotations;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.RobolectricTestRunner;

import static com.fsck.k9.message.TestMessageConstructionUtils.bodypart;
import static com.fsck.k9.message.TestMessageConstructionUtils.messageFromBody;
Expand All @@ -29,8 +28,7 @@


@SuppressWarnings("WeakerAccess")
@RunWith(K9RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class MessageCryptoStructureDetectorTest {
MessageCryptoAnnotations messageCryptoAnnotations = mock(MessageCryptoAnnotations.class);
static final String PGP_INLINE_DATA = "" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@


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 org.robolectric.RobolectricTestRunner;

import static org.junit.Assert.assertEquals;

@RunWith(K9RobolectricTestRunner.class)
@Config(manifest = Config.NONE)

@RunWith(RobolectricTestRunner.class)
public class OpenPgpApiHelperTest {

@Test
Expand Down
4 changes: 2 additions & 2 deletions k9mail/src/test/java/com/fsck/k9/helper/IdentityHelperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package com.fsck.k9.helper

import com.fsck.k9.Account
import com.fsck.k9.Identity
import com.fsck.k9.K9RobolectricTestRunner
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.MimeMessage
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment

@RunWith(K9RobolectricTestRunner::class)
@RunWith(RobolectricTestRunner::class)
class IdentityHelperTest {
private val account = createDummyAccount()

Expand Down
6 changes: 2 additions & 4 deletions k9mail/src/test/java/com/fsck/k9/helper/MailToTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

import android.net.Uri;

import com.fsck.k9.K9RobolectricTestRunner;
import com.fsck.k9.helper.MailTo.CaseInsensitiveParamWrapper;
import com.fsck.k9.mail.Address;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.RobolectricTestRunner;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
Expand All @@ -23,8 +22,7 @@
import static org.junit.Assert.assertThat;


@RunWith(K9RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class MailToTest {
@Rule
public ExpectedException exception = ExpectedException.none();
Expand Down
Loading

0 comments on commit a8c4f69

Please sign in to comment.