diff --git a/app/core/src/test/java/com/fsck/k9/helper/ListHeadersTest.java b/app/core/src/test/java/com/fsck/k9/helper/ListHeadersTest.java index b3d77e2ca..1f0fdfcd6 100644 --- a/app/core/src/test/java/com/fsck/k9/helper/ListHeadersTest.java +++ b/app/core/src/test/java/com/fsck/k9/helper/ListHeadersTest.java @@ -1,19 +1,17 @@ package com.fsck.k9.helper; +import com.fsck.k9.RobolectricTest; import com.fsck.k9.mail.Address; -import com.fsck.k9.mail.K9LibRobolectricTestRunner; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.internet.MimeMessage; 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 ListHeadersTest { +public class ListHeadersTest extends RobolectricTest { private static final String[] TEST_EMAIL_ADDRESSES = new String[] { "prettyandsimple@example.com", "very.common@example.com", diff --git a/app/core/src/test/java/com/fsck/k9/helper/MailToTest.java b/app/core/src/test/java/com/fsck/k9/helper/MailToTest.java index bca04c1c4..d388d4136 100644 --- a/app/core/src/test/java/com/fsck/k9/helper/MailToTest.java +++ b/app/core/src/test/java/com/fsck/k9/helper/MailToTest.java @@ -1,21 +1,19 @@ package com.fsck.k9.helper; -import android.net.Uri; - -import com.fsck.k9.helper.MailTo.CaseInsensitiveParamWrapper; -import com.fsck.k9.mail.Address; -import com.fsck.k9.mail.K9LibRobolectricTestRunner; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; - import java.util.Arrays; import java.util.Collections; import java.util.List; +import android.net.Uri; + +import com.fsck.k9.RobolectricTest; +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 static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; @@ -23,8 +21,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -@RunWith(K9LibRobolectricTestRunner.class) -public class MailToTest { +public class MailToTest extends RobolectricTest { @Rule public ExpectedException exception = ExpectedException.none(); @@ -235,4 +232,4 @@ public class MailToTest { } -} \ No newline at end of file +} diff --git a/mail/common/build.gradle b/mail/common/build.gradle index 55ddff0df..43823598d 100644 --- a/mail/common/build.gradle +++ b/mail/common/build.gradle @@ -15,7 +15,6 @@ dependencies { implementation "com.squareup.moshi:moshi:${versions.moshi}" testImplementation project(":mail:testing") - testImplementation "org.robolectric:robolectric:${versions.robolectric}" testImplementation "junit:junit:${versions.junit}" testImplementation "com.google.truth:truth:${versions.truth}" testImplementation "org.mockito:mockito-inline:${versions.mockito}" diff --git a/mail/common/src/test/java/com/fsck/k9/mail/AddressTest.java b/mail/common/src/test/java/com/fsck/k9/mail/AddressTest.java index 190bfc226..5ec058566 100644 --- a/mail/common/src/test/java/com/fsck/k9/mail/AddressTest.java +++ b/mail/common/src/test/java/com/fsck/k9/mail/AddressTest.java @@ -2,7 +2,6 @@ package com.fsck.k9.mail; import org.junit.Test; -import org.junit.runner.RunWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -10,7 +9,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -@RunWith(K9LibRobolectricTestRunner.class) public class AddressTest { /** * test the possibility to parse "From:" fields with no email. diff --git a/mail/common/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java b/mail/common/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java index 8c8698425..6de516565 100644 --- a/mail/common/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java +++ b/mail/common/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java @@ -2,12 +2,10 @@ package com.fsck.k9.mail; import org.junit.Test; -import org.junit.runner.RunWith; import static org.junit.Assert.assertEquals; -@RunWith(K9LibRobolectricTestRunner.class) public class Address_quoteAtoms { @Test public void testNoQuote() { diff --git a/mail/common/src/test/java/com/fsck/k9/mail/MessageTest.kt b/mail/common/src/test/java/com/fsck/k9/mail/MessageTest.kt index cf885b32b..65125df5a 100644 --- a/mail/common/src/test/java/com/fsck/k9/mail/MessageTest.kt +++ b/mail/common/src/test/java/com/fsck/k9/mail/MessageTest.kt @@ -10,24 +10,30 @@ import com.fsck.k9.mail.internet.MimeMultipart import com.fsck.k9.mail.internet.TextBody import com.google.common.truth.Truth.assertThat import java.io.ByteArrayOutputStream +import java.io.File +import java.nio.file.Files import java.util.Date import java.util.TimeZone import okio.Buffer import org.apache.james.mime4j.util.MimeUtil +import org.junit.After import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RuntimeEnvironment -@RunWith(K9LibRobolectricTestRunner::class) class MessageTest { - private val context = RuntimeEnvironment.application + private lateinit var tempDirectory: File private var mimeBoundary: Int = 0 @Before fun setUp() { TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo")) - BinaryTempFileBody.setTempDirectory(context.cacheDir) + tempDirectory = Files.createTempDirectory("MessageTest").toFile() + BinaryTempFileBody.setTempDirectory(tempDirectory) + } + + @After + fun tearDown() { + tempDirectory.deleteRecursively() } @Test diff --git a/mail/common/src/test/java/com/fsck/k9/mail/internet/AddressHeaderBuilderTest.kt b/mail/common/src/test/java/com/fsck/k9/mail/internet/AddressHeaderBuilderTest.kt index 3c6f6b816..672b8eddf 100644 --- a/mail/common/src/test/java/com/fsck/k9/mail/internet/AddressHeaderBuilderTest.kt +++ b/mail/common/src/test/java/com/fsck/k9/mail/internet/AddressHeaderBuilderTest.kt @@ -1,13 +1,10 @@ package com.fsck.k9.mail.internet import com.fsck.k9.mail.Address -import com.fsck.k9.mail.K9LibRobolectricTestRunner import com.fsck.k9.mail.crlf import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith -@RunWith(K9LibRobolectricTestRunner::class) class AddressHeaderBuilderTest { @Test diff --git a/mail/common/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java b/mail/common/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java index c9205be78..d1918be58 100644 --- a/mail/common/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java +++ b/mail/common/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java @@ -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 CharsetSupportTest { @Test diff --git a/mail/common/src/test/java/com/fsck/k9/mail/internet/MessageIdGeneratorTest.kt b/mail/common/src/test/java/com/fsck/k9/mail/internet/MessageIdGeneratorTest.kt index 477afdfbb..6ce7a4654 100644 --- a/mail/common/src/test/java/com/fsck/k9/mail/internet/MessageIdGeneratorTest.kt +++ b/mail/common/src/test/java/com/fsck/k9/mail/internet/MessageIdGeneratorTest.kt @@ -1,12 +1,9 @@ package com.fsck.k9.mail.internet import com.fsck.k9.mail.Address -import com.fsck.k9.mail.K9LibRobolectricTestRunner import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.runner.RunWith -@RunWith(K9LibRobolectricTestRunner::class) class MessageIdGeneratorTest { private val messageIdGenerator = MessageIdGenerator( object : UuidGenerator { diff --git a/mail/common/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java b/mail/common/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java index 390fad798..3046a9191 100644 --- a/mail/common/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java +++ b/mail/common/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java @@ -9,23 +9,18 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import com.fsck.k9.mail.Address; +import com.fsck.k9.mail.Body; +import com.fsck.k9.mail.BodyPart; +import com.fsck.k9.mail.Message.RecipientType; +import com.fsck.k9.mail.Multipart; import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; -import com.fsck.k9.mail.Address; -import com.fsck.k9.mail.Body; -import com.fsck.k9.mail.BodyPart; -import com.fsck.k9.mail.K9LibRobolectricTestRunner; -import com.fsck.k9.mail.Message.RecipientType; -import com.fsck.k9.mail.Multipart; - -import org.junit.runner.RunWith; - import static org.junit.Assert.assertEquals; -@RunWith(K9LibRobolectricTestRunner.class) public class MimeMessageParseTest { @Before public void setup() { diff --git a/mail/protocols/imap/build.gradle b/mail/protocols/imap/build.gradle index 683d0155b..09597e2b6 100644 --- a/mail/protocols/imap/build.gradle +++ b/mail/protocols/imap/build.gradle @@ -13,7 +13,6 @@ dependencies { implementation "commons-io:commons-io:${versions.commonsIo}" testImplementation project(":mail:testing") - testImplementation "org.robolectric:robolectric:${versions.robolectric}" testImplementation "junit:junit:${versions.junit}" testImplementation "com.google.truth:truth:${versions.truth}" testImplementation "org.mockito:mockito-core:${versions.mockito}" diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.java b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.java index e707fce1c..fc8764c62 100644 --- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.java +++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.java @@ -10,7 +10,6 @@ import com.fsck.k9.mail.AuthenticationFailedException; import com.fsck.k9.mail.CertificateValidationException; import com.fsck.k9.mail.CertificateValidationException.Reason; import com.fsck.k9.mail.ConnectionSecurity; -import com.fsck.k9.mail.K9LibRobolectricTestRunner; import com.fsck.k9.mail.K9MailLib; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.XOAuth2ChallengeParserTest; @@ -21,8 +20,6 @@ import com.fsck.k9.mail.store.imap.mockserver.MockImapServer; import okio.ByteString; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.shadows.ShadowLog; import static org.hamcrest.core.StringContains.containsString; import static org.junit.Assert.assertEquals; @@ -32,7 +29,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -@RunWith(K9LibRobolectricTestRunner.class) public class RealImapConnectionTest { private static final boolean DEBUGGING = false; @@ -63,7 +59,6 @@ public class RealImapConnectionTest { settings.setPassword(PASSWORD); if (DEBUGGING) { - ShadowLog.stream = System.out; K9MailLib.setDebug(true); K9MailLib.setDebugSensitive(true); } diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt index 9e5866a50..558ff33e0 100644 --- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt +++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt @@ -4,7 +4,6 @@ import com.fsck.k9.mail.Body import com.fsck.k9.mail.DefaultBodyFactory import com.fsck.k9.mail.FetchProfile import com.fsck.k9.mail.Flag -import com.fsck.k9.mail.K9LibRobolectricTestRunner import com.fsck.k9.mail.MessageRetrievalListener import com.fsck.k9.mail.MessagingException import com.fsck.k9.mail.Part @@ -12,11 +11,14 @@ import com.fsck.k9.mail.internet.BinaryTempFileBody import com.fsck.k9.mail.internet.MimeHeader import com.fsck.k9.mail.store.imap.ImapResponseHelper.createImapResponse import com.google.common.truth.Truth.assertThat +import java.io.File import java.io.IOException +import java.nio.file.Files import java.util.Date import java.util.TimeZone import okio.Buffer import org.apache.james.mime4j.util.MimeUtil +import org.junit.After import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotNull @@ -25,7 +27,6 @@ import org.junit.Assert.assertTrue import org.junit.Assert.fail import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.anySet import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.eq @@ -40,9 +41,7 @@ import org.mockito.kotlin.doReturn import org.mockito.kotlin.doThrow import org.mockito.kotlin.mock import org.mockito.kotlin.whenever -import org.robolectric.RuntimeEnvironment -@RunWith(K9LibRobolectricTestRunner::class) class RealImapFolderTest { private val internalImapStore = object : InternalImapStore { override val logLabel = "Account" @@ -52,9 +51,17 @@ class RealImapFolderTest { private val imapConnection = mock() private val testConnectionManager = TestConnectionManager(imapConnection) + private lateinit var tempDirectory: File + @Before fun setUp() { - BinaryTempFileBody.setTempDirectory(RuntimeEnvironment.application.cacheDir) + tempDirectory = Files.createTempDirectory("RealImapFolderTest").toFile() + BinaryTempFileBody.setTempDirectory(tempDirectory) + } + + @After + fun tearDown() { + tempDirectory.deleteRecursively() } @Test diff --git a/mail/protocols/pop3/build.gradle b/mail/protocols/pop3/build.gradle index d041d7afb..37d6a8536 100644 --- a/mail/protocols/pop3/build.gradle +++ b/mail/protocols/pop3/build.gradle @@ -8,7 +8,6 @@ dependencies { api project(":mail:common") testImplementation project(":mail:testing") - testImplementation "org.robolectric:robolectric:${versions.robolectric}" testImplementation "junit:junit:${versions.junit}" testImplementation "com.google.truth:truth:${versions.truth}" testImplementation "org.mockito:mockito-core:${versions.mockito}" diff --git a/mail/protocols/smtp/build.gradle b/mail/protocols/smtp/build.gradle index 10a602852..d44c134cd 100644 --- a/mail/protocols/smtp/build.gradle +++ b/mail/protocols/smtp/build.gradle @@ -12,7 +12,6 @@ dependencies { implementation "com.squareup.okio:okio:${versions.okio}" testImplementation project(":mail:testing") - testImplementation "org.robolectric:robolectric:${versions.robolectric}" testImplementation "junit:junit:${versions.junit}" testImplementation "com.google.truth:truth:${versions.truth}" testImplementation "org.mockito.kotlin:mockito-kotlin:${versions.mockitoKotlin}" diff --git a/mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpTransportTest.kt b/mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpTransportTest.kt index ed9ae481d..be5083687 100644 --- a/mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpTransportTest.kt +++ b/mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpTransportTest.kt @@ -4,7 +4,6 @@ import com.fsck.k9.mail.AuthType import com.fsck.k9.mail.AuthenticationFailedException import com.fsck.k9.mail.CertificateValidationException import com.fsck.k9.mail.ConnectionSecurity -import com.fsck.k9.mail.K9LibRobolectricTestRunner import com.fsck.k9.mail.Message import com.fsck.k9.mail.MessagingException import com.fsck.k9.mail.ServerSettings @@ -18,7 +17,6 @@ import com.fsck.k9.mail.transport.mockServer.MockSmtpServer import com.google.common.truth.Truth.assertThat import org.junit.Assert.fail import org.junit.Test -import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.anyLong import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.doReturn @@ -32,7 +30,6 @@ private const val USERNAME = "user" private const val PASSWORD = "password" private val CLIENT_CERTIFICATE_ALIAS: String? = null -@RunWith(K9LibRobolectricTestRunner::class) class SmtpTransportTest { private val socketFactory = TestTrustedSocketFactory.newInstance() private val oAuth2TokenProvider = createMockOAuth2TokenProvider() diff --git a/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavStoreTest.java b/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavStoreTest.java index 8cb66466e..153e22c0f 100644 --- a/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavStoreTest.java +++ b/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavStoreTest.java @@ -8,11 +8,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import android.app.Application; + import com.fsck.k9.mail.AuthType; import com.fsck.k9.mail.CertificateValidationException; import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.FolderType; -import com.fsck.k9.mail.K9LibRobolectricTestRunner; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.ServerSettings; import com.fsck.k9.mail.filter.Base64; @@ -44,6 +45,8 @@ import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.mockito.stubbing.OngoingStubbing; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import static junit.framework.Assert.assertSame; import static org.junit.Assert.assertEquals; @@ -52,7 +55,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(K9LibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) +@Config(application = Application.class) public class WebDavStoreTest { private static final HttpResponse OK_200_RESPONSE = createOkResponse(); private static final HttpResponse UNAUTHORIZED_401_RESPONSE = createResponse(401); diff --git a/mail/testing/build.gradle b/mail/testing/build.gradle index 7f6ed262b..0c7548544 100644 --- a/mail/testing/build.gradle +++ b/mail/testing/build.gradle @@ -5,7 +5,6 @@ dependencies { api project(":mail:common") api "com.squareup.okio:okio:${versions.okio}" - api "org.robolectric:robolectric:${versions.robolectric}" api "junit:junit:${versions.junit}" } diff --git a/mail/testing/src/main/java/com/fsck/k9/mail/K9LibRobolectricTestRunner.java b/mail/testing/src/main/java/com/fsck/k9/mail/K9LibRobolectricTestRunner.java deleted file mode 100644 index 561c594e8..000000000 --- a/mail/testing/src/main/java/com/fsck/k9/mail/K9LibRobolectricTestRunner.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.fsck.k9.mail; - -import org.junit.runners.model.InitializationError; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.annotation.Config; - -public class K9LibRobolectricTestRunner extends RobolectricTestRunner { - - public K9LibRobolectricTestRunner(Class testClass) throws InitializationError { - super(testClass); - } - - @Override - protected Config buildGlobalConfig() { - return new Config.Builder() - .setSdk(22) - .setManifest(Config.NONE) - .build(); - } -} \ No newline at end of file