From f96ffdcd4e4a86b22ab3cb0e3fa8bae6576a6ae5 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 20 May 2015 18:04:20 +0200 Subject: [PATCH 1/8] Update Gradle Android plugin to 1.2.3 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6f91a86ec..16a8c0754 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' + classpath 'com.android.tools.build:gradle:1.2.3' classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0' } } From b45065a5b2cee4e5d917c8bba41cf8f27eceb471 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 20 May 2015 20:55:24 +0200 Subject: [PATCH 2/8] Improve FindBugs Gradle task Based on https://github.com/square/sqlbrite/blob/master/gradle/android-findbugs.gradle --- gradle/plugins/findbugs-android.gradle | 37 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/gradle/plugins/findbugs-android.gradle b/gradle/plugins/findbugs-android.gradle index ee83f1808..7a22caf72 100644 --- a/gradle/plugins/findbugs-android.gradle +++ b/gradle/plugins/findbugs-android.gradle @@ -1,14 +1,29 @@ apply plugin: 'findbugs' -check.dependsOn 'findbugs' -task findbugs(type: FindBugs, dependsOn: ['compileDebugJava', 'compileDebugTestJava']) { - ignoreFailures = true - classes = fileTree('build/intermediates/classes/debug/') + - fileTree('build/intermediates/classes/test/debug/') - source = project.android.sourceSets.main.java.getSrcDirs() + - project.android.sourceSets.androidTest.java.getSrcDirs() - classpath = files() - effort = 'max' - includeFilter = file("$rootProject.projectDir/config/findbugs/include_filter.xml") - excludeFilter = file("$rootProject.projectDir/config/findbugs/exclude_filter.xml") +afterEvaluate { + def variants = plugins.hasPlugin('com.android.application') ? + android.applicationVariants : android.libraryVariants + + variants.each { variant -> + def task = project.task("findBugs${variant.name.capitalize()}", type: FindBugs) { + group = 'verification' + description = "Run FindBugs for the ${variant.description}." + + effort = 'max' + ignoreFailures = true + + includeFilter = file("$rootProject.projectDir/config/findbugs/include_filter.xml") + excludeFilter = file("$rootProject.projectDir/config/findbugs/exclude_filter.xml") + + def variantCompile = variant.javaCompile + + classes = fileTree(variantCompile.destinationDir) + source = variantCompile.source + classpath = variantCompile.classpath.plus(project.files(android.bootClasspath)) + + dependsOn(variantCompile) + } + + tasks.getByName('check').dependsOn(task) + } } From 0f66cacf1025ea6ced103d7806ad52466e596523 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 20 May 2015 19:21:33 +0200 Subject: [PATCH 3/8] Move JVM tests into main k9mail module Use Robolectric for the tests that use framework classes. --- k9mail/build.gradle | 8 ++++++++ .../test/java/com/fsck/k9/helper/HtmlSanitizerTest.java | 0 .../src/test/java/com/fsck/k9/mail/AddressTest.java | 5 +++++ .../test/java/com/fsck/k9/mail/Address_quoteAtoms.java | 5 +++++ .../k9/mail/filter/EOLConvertingOutputStreamTest.java | 0 .../com/fsck/k9/mail/internet/CharsetSupportTest.java | 5 +++++ .../java/com/fsck/k9/mail/internet/DecoderUtilTest.java | 5 +++++ .../com/fsck/k9/mail/internet/MimeMessageParseTest.java | 5 +++++ .../java/com/fsck/k9/mail/internet/MimeUtilityTest.java | 0 .../java/com/fsck/k9/mail/store/imap/ImapListTest.java | 0 .../fsck/k9/mail/store/imap/ImapResponseParserTest.java | 5 +++++ .../com/fsck/k9/mail/store/imap/ImapStoreUriTest.java | 0 .../java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java | 5 +++++ .../java/com/fsck/k9/message/TextBodyBuilderTest.java | 3 +++ settings.gradle | 1 - 15 files changed, 46 insertions(+), 1 deletion(-) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/helper/HtmlSanitizerTest.java (100%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/mail/AddressTest.java (88%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java (87%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java (100%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java (95%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java (94%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java (98%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java (100%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/mail/store/imap/ImapListTest.java (100%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java (95%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java (100%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java (96%) rename {tests-on-jvm => k9mail}/src/test/java/com/fsck/k9/message/TextBodyBuilderTest.java (99%) diff --git a/k9mail/build.gradle b/k9mail/build.gradle index a9efee7da..ff71994bd 100644 --- a/k9mail/build.gradle +++ b/k9mail/build.gradle @@ -25,6 +25,14 @@ dependencies { exclude group: 'junit' } androidTestCompile 'com.madgag.spongycastle:pg:1.51.0.0' + + testCompile('org.robolectric:robolectric:3.0-rc3') { + exclude group: 'org.hamcrest', module: 'hamcrest-core' + } + testCompile 'org.hamcrest:hamcrest-core:1.3' + testCompile('junit:junit:4.10') { + exclude group: 'org.hamcrest', module: 'hamcrest-core' + } } android { diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/helper/HtmlSanitizerTest.java b/k9mail/src/test/java/com/fsck/k9/helper/HtmlSanitizerTest.java similarity index 100% rename from tests-on-jvm/src/test/java/com/fsck/k9/helper/HtmlSanitizerTest.java rename to k9mail/src/test/java/com/fsck/k9/helper/HtmlSanitizerTest.java diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/AddressTest.java b/k9mail/src/test/java/com/fsck/k9/mail/AddressTest.java similarity index 88% rename from tests-on-jvm/src/test/java/com/fsck/k9/mail/AddressTest.java rename to k9mail/src/test/java/com/fsck/k9/mail/AddressTest.java index 7b9c2b891..d8080f063 100644 --- a/tests-on-jvm/src/test/java/com/fsck/k9/mail/AddressTest.java +++ b/k9mail/src/test/java/com/fsck/k9/mail/AddressTest.java @@ -2,10 +2,15 @@ package com.fsck.k9.mail; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import static org.junit.Assert.assertEquals; +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) public class AddressTest { /** * test the possibility to parse "From:" fields with no email. diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java b/k9mail/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java similarity index 87% rename from tests-on-jvm/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java rename to k9mail/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java index 6de516565..5a2fa88cb 100644 --- a/tests-on-jvm/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java +++ b/k9mail/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java @@ -2,10 +2,15 @@ package com.fsck.k9.mail; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import static org.junit.Assert.assertEquals; +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) public class Address_quoteAtoms { @Test public void testNoQuote() { diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java b/k9mail/src/test/java/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java similarity index 100% rename from tests-on-jvm/src/test/java/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java rename to k9mail/src/test/java/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java b/k9mail/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java similarity index 95% rename from tests-on-jvm/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java rename to k9mail/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java index d1918be58..3d5141884 100644 --- a/tests-on-jvm/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java +++ b/k9mail/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java @@ -2,10 +2,15 @@ package com.fsck.k9.mail.internet; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import static org.junit.Assert.assertEquals; +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) public class CharsetSupportTest { @Test diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java b/k9mail/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java similarity index 94% rename from tests-on-jvm/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java rename to k9mail/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java index 0f58ddf70..5a24544c5 100644 --- a/tests-on-jvm/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java +++ b/k9mail/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java @@ -2,10 +2,15 @@ package com.fsck.k9.mail.internet; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import static org.junit.Assert.assertEquals; +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) public class DecoderUtilTest { @Test diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java b/k9mail/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java similarity index 98% rename from tests-on-jvm/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java rename to k9mail/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java index 3fc7e4b4a..1dcc88f91 100644 --- a/tests-on-jvm/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java +++ b/k9mail/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java @@ -18,10 +18,15 @@ 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.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import static org.junit.Assert.assertEquals; +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) public class MimeMessageParseTest { @Before public void setup() { diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java b/k9mail/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java similarity index 100% rename from tests-on-jvm/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java rename to k9mail/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapListTest.java b/k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapListTest.java similarity index 100% rename from tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapListTest.java rename to k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapListTest.java diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java b/k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java similarity index 95% rename from tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java rename to k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java index d9ce8b445..31e867cc5 100644 --- a/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java +++ b/k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java @@ -3,6 +3,9 @@ package com.fsck.k9.mail.store.imap; import com.fsck.k9.mail.filter.PeekableInputStream; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -16,6 +19,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) public class ImapResponseParserTest { @Test public void testSimpleOkResponse() throws IOException { diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java b/k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java similarity index 100% rename from tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java rename to k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java b/k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java similarity index 96% rename from tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java rename to k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java index 283660fbb..f91ec80b1 100644 --- a/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java +++ b/k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java @@ -18,12 +18,17 @@ package com.fsck.k9.mail.store.imap; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import java.util.List; import static org.junit.Assert.assertArrayEquals; +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) public class ImapUtilityTest { @Test public void testGetImapSequenceValues() { diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/message/TextBodyBuilderTest.java b/k9mail/src/test/java/com/fsck/k9/message/TextBodyBuilderTest.java similarity index 99% rename from tests-on-jvm/src/test/java/com/fsck/k9/message/TextBodyBuilderTest.java rename to k9mail/src/test/java/com/fsck/k9/message/TextBodyBuilderTest.java index afb95eb2f..cf6b03fcb 100644 --- a/tests-on-jvm/src/test/java/com/fsck/k9/message/TextBodyBuilderTest.java +++ b/k9mail/src/test/java/com/fsck/k9/message/TextBodyBuilderTest.java @@ -3,6 +3,7 @@ package com.fsck.k9.message; import com.fsck.k9.Account.QuoteStyle; import com.fsck.k9.mail.internet.TextBody; +import org.junit.Ignore; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; @@ -12,6 +13,8 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; +//TODO: Get rid of 'Theories' and write simple tests +@Ignore @RunWith(Theories.class) public class TextBodyBuilderTest { diff --git a/settings.gradle b/settings.gradle index a39b9d813..febff8e7f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,4 +3,3 @@ include ':k9mail-library' include ':plugins:Android-PullToRefresh:library' include ':plugins:HoloColorPicker' include ':plugins:openpgp-api-library' -include ':tests-on-jvm' From 4b273c1749e4761a86b045a2b40e93d267e878cb Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 20 May 2015 20:57:21 +0200 Subject: [PATCH 4/8] Move some tests from 'androidTest' to 'test' folder --- .../com/fsck/k9/activity/MessageReferenceTest.java | 7 ++++--- .../com/fsck/k9/crypto/MessageDecryptVerifierTest.java | 7 ++++--- .../java/com/fsck/k9/helper/HtmlConverterTest.java | 8 +++++--- .../java/com/fsck/k9/helper/MessageHelperTest.java | 10 ++++++---- 4 files changed, 19 insertions(+), 13 deletions(-) rename k9mail/src/{androidTest => test}/java/com/fsck/k9/activity/MessageReferenceTest.java (97%) rename k9mail/src/{androidTest => test}/java/com/fsck/k9/crypto/MessageDecryptVerifierTest.java (94%) rename k9mail/src/{androidTest => test}/java/com/fsck/k9/helper/HtmlConverterTest.java (98%) rename k9mail/src/{androidTest => test}/java/com/fsck/k9/helper/MessageHelperTest.java (91%) diff --git a/k9mail/src/androidTest/java/com/fsck/k9/activity/MessageReferenceTest.java b/k9mail/src/test/java/com/fsck/k9/activity/MessageReferenceTest.java similarity index 97% rename from k9mail/src/androidTest/java/com/fsck/k9/activity/MessageReferenceTest.java rename to k9mail/src/test/java/com/fsck/k9/activity/MessageReferenceTest.java index 3ad1ba75b..85acf6b27 100644 --- a/k9mail/src/androidTest/java/com/fsck/k9/activity/MessageReferenceTest.java +++ b/k9mail/src/test/java/com/fsck/k9/activity/MessageReferenceTest.java @@ -1,12 +1,12 @@ package com.fsck.k9.activity; -import android.support.test.runner.AndroidJUnit4; - import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.MessagingException; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; @@ -14,7 +14,8 @@ import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; -@RunWith(AndroidJUnit4.class) +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) public class MessageReferenceTest { @Test diff --git a/k9mail/src/androidTest/java/com/fsck/k9/crypto/MessageDecryptVerifierTest.java b/k9mail/src/test/java/com/fsck/k9/crypto/MessageDecryptVerifierTest.java similarity index 94% rename from k9mail/src/androidTest/java/com/fsck/k9/crypto/MessageDecryptVerifierTest.java rename to k9mail/src/test/java/com/fsck/k9/crypto/MessageDecryptVerifierTest.java index e06bd7971..3764cd6d5 100644 --- a/k9mail/src/androidTest/java/com/fsck/k9/crypto/MessageDecryptVerifierTest.java +++ b/k9mail/src/test/java/com/fsck/k9/crypto/MessageDecryptVerifierTest.java @@ -3,8 +3,6 @@ package com.fsck.k9.crypto; import java.util.List; -import android.support.test.runner.AndroidJUnit4; - import com.fsck.k9.mail.Part; import com.fsck.k9.mail.internet.MimeBodyPart; import com.fsck.k9.mail.internet.MimeMessage; @@ -13,12 +11,15 @@ import com.fsck.k9.mail.internet.MimeMultipart; import com.fsck.k9.mail.internet.TextBody; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertSame; -@RunWith(AndroidJUnit4.class) +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) public class MessageDecryptVerifierTest { @Test diff --git a/k9mail/src/androidTest/java/com/fsck/k9/helper/HtmlConverterTest.java b/k9mail/src/test/java/com/fsck/k9/helper/HtmlConverterTest.java similarity index 98% rename from k9mail/src/androidTest/java/com/fsck/k9/helper/HtmlConverterTest.java rename to k9mail/src/test/java/com/fsck/k9/helper/HtmlConverterTest.java index c09244164..9292991b5 100644 --- a/k9mail/src/androidTest/java/com/fsck/k9/helper/HtmlConverterTest.java +++ b/k9mail/src/test/java/com/fsck/k9/helper/HtmlConverterTest.java @@ -1,18 +1,20 @@ package com.fsck.k9.helper; + import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; -import android.support.test.runner.AndroidJUnit4; - import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import static junit.framework.Assert.assertEquals; -@RunWith(AndroidJUnit4.class) +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) 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")); diff --git a/k9mail/src/androidTest/java/com/fsck/k9/helper/MessageHelperTest.java b/k9mail/src/test/java/com/fsck/k9/helper/MessageHelperTest.java similarity index 91% rename from k9mail/src/androidTest/java/com/fsck/k9/helper/MessageHelperTest.java rename to k9mail/src/test/java/com/fsck/k9/helper/MessageHelperTest.java index 485f11520..a2292a61c 100644 --- a/k9mail/src/androidTest/java/com/fsck/k9/helper/MessageHelperTest.java +++ b/k9mail/src/test/java/com/fsck/k9/helper/MessageHelperTest.java @@ -3,27 +3,29 @@ package com.fsck.k9.helper; import android.content.Context; import android.graphics.Color; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; import android.text.SpannableString; import com.fsck.k9.mail.Address; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; -@RunWith(AndroidJUnit4.class) +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) public class MessageHelperTest { private Contacts contacts; private Contacts mockContacts; @Before public void setUp() throws Exception { - Context context = InstrumentationRegistry.getTargetContext(); + Context context = RuntimeEnvironment.application; contacts = new Contacts(context); mockContacts = new Contacts(context) { @Override public String getNameForAddress(String address) { From a24d85d754dcdcd4499c67abc4ebeb5e335d14fe Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 20 May 2015 23:48:30 +0200 Subject: [PATCH 5/8] Move library tests to k9mail-library module --- k9mail-library/build.gradle | 14 ++++++++++++++ .../java/com/fsck/k9/mail/MessageTest.java | 0 .../java/com/fsck/k9/mail/PgpMimeMessageTest.java | 0 .../com/fsck/k9/mail/ReconstructMessageTest.java | 0 .../fsck/k9/mail/ssl/TrustManagerFactoryTest.java | 0 .../test/java/com/fsck/k9/mail/AddressTest.java | 0 .../java/com/fsck/k9/mail/Address_quoteAtoms.java | 0 .../mail/filter/EOLConvertingOutputStreamTest.java | 0 .../fsck/k9/mail/internet/CharsetSupportTest.java | 0 .../com/fsck/k9/mail/internet/DecoderUtilTest.java | 0 .../k9/mail/internet/MimeMessageParseTest.java | 0 .../com/fsck/k9/mail/internet/MimeUtilityTest.java | 0 .../com/fsck/k9/mail/store/imap/ImapListTest.java | 0 .../k9/mail/store/imap/ImapResponseParserTest.java | 0 .../fsck/k9/mail/store/imap/ImapStoreUriTest.java | 0 .../fsck/k9/mail/store/imap/ImapUtilityTest.java | 0 k9mail/build.gradle | 1 - 17 files changed, 14 insertions(+), 1 deletion(-) rename {k9mail => k9mail-library}/src/androidTest/java/com/fsck/k9/mail/MessageTest.java (100%) rename {k9mail => k9mail-library}/src/androidTest/java/com/fsck/k9/mail/PgpMimeMessageTest.java (100%) rename {k9mail => k9mail-library}/src/androidTest/java/com/fsck/k9/mail/ReconstructMessageTest.java (100%) rename {k9mail => k9mail-library}/src/androidTest/java/com/fsck/k9/mail/ssl/TrustManagerFactoryTest.java (100%) rename {k9mail => k9mail-library}/src/test/java/com/fsck/k9/mail/AddressTest.java (100%) rename {k9mail => k9mail-library}/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java (100%) rename {k9mail => k9mail-library}/src/test/java/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java (100%) rename {k9mail => k9mail-library}/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java (100%) rename {k9mail => k9mail-library}/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java (100%) rename {k9mail => k9mail-library}/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java (100%) rename {k9mail => k9mail-library}/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java (100%) rename {k9mail => k9mail-library}/src/test/java/com/fsck/k9/mail/store/imap/ImapListTest.java (100%) rename {k9mail => k9mail-library}/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java (100%) rename {k9mail => k9mail-library}/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java (100%) rename {k9mail => k9mail-library}/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java (100%) diff --git a/k9mail-library/build.gradle b/k9mail-library/build.gradle index b32294f08..f95a158f6 100644 --- a/k9mail-library/build.gradle +++ b/k9mail-library/build.gradle @@ -12,6 +12,17 @@ dependencies { compile 'commons-io:commons-io:2.4' compile 'com.jcraft:jzlib:1.0.7' compile 'com.beetstra.jutf7:jutf7:1.0.0' + + androidTestCompile 'com.android.support.test:testing-support-lib:0.1' + androidTestCompile 'com.madgag.spongycastle:pg:1.51.0.0' + + testCompile('org.robolectric:robolectric:3.0-rc3') { + exclude group: 'org.hamcrest', module: 'hamcrest-core' + } + testCompile 'org.hamcrest:hamcrest-core:1.3' + testCompile('junit:junit:4.10') { + exclude group: 'org.hamcrest', module: 'hamcrest-core' + } } android { @@ -21,6 +32,8 @@ android { defaultConfig { minSdkVersion 15 targetSdkVersion 21 + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } lintOptions { @@ -40,5 +53,6 @@ android { exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/NOTICE.txt' + exclude 'LICENSE.txt' } } diff --git a/k9mail/src/androidTest/java/com/fsck/k9/mail/MessageTest.java b/k9mail-library/src/androidTest/java/com/fsck/k9/mail/MessageTest.java similarity index 100% rename from k9mail/src/androidTest/java/com/fsck/k9/mail/MessageTest.java rename to k9mail-library/src/androidTest/java/com/fsck/k9/mail/MessageTest.java diff --git a/k9mail/src/androidTest/java/com/fsck/k9/mail/PgpMimeMessageTest.java b/k9mail-library/src/androidTest/java/com/fsck/k9/mail/PgpMimeMessageTest.java similarity index 100% rename from k9mail/src/androidTest/java/com/fsck/k9/mail/PgpMimeMessageTest.java rename to k9mail-library/src/androidTest/java/com/fsck/k9/mail/PgpMimeMessageTest.java diff --git a/k9mail/src/androidTest/java/com/fsck/k9/mail/ReconstructMessageTest.java b/k9mail-library/src/androidTest/java/com/fsck/k9/mail/ReconstructMessageTest.java similarity index 100% rename from k9mail/src/androidTest/java/com/fsck/k9/mail/ReconstructMessageTest.java rename to k9mail-library/src/androidTest/java/com/fsck/k9/mail/ReconstructMessageTest.java diff --git a/k9mail/src/androidTest/java/com/fsck/k9/mail/ssl/TrustManagerFactoryTest.java b/k9mail-library/src/androidTest/java/com/fsck/k9/mail/ssl/TrustManagerFactoryTest.java similarity index 100% rename from k9mail/src/androidTest/java/com/fsck/k9/mail/ssl/TrustManagerFactoryTest.java rename to k9mail-library/src/androidTest/java/com/fsck/k9/mail/ssl/TrustManagerFactoryTest.java diff --git a/k9mail/src/test/java/com/fsck/k9/mail/AddressTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/AddressTest.java similarity index 100% rename from k9mail/src/test/java/com/fsck/k9/mail/AddressTest.java rename to k9mail-library/src/test/java/com/fsck/k9/mail/AddressTest.java diff --git a/k9mail/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java b/k9mail-library/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java similarity index 100% rename from k9mail/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java rename to k9mail-library/src/test/java/com/fsck/k9/mail/Address_quoteAtoms.java diff --git a/k9mail/src/test/java/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java similarity index 100% rename from k9mail/src/test/java/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java rename to k9mail-library/src/test/java/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java diff --git a/k9mail/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java similarity index 100% rename from k9mail/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java rename to k9mail-library/src/test/java/com/fsck/k9/mail/internet/CharsetSupportTest.java diff --git a/k9mail/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java similarity index 100% rename from k9mail/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java rename to k9mail-library/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java diff --git a/k9mail/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java similarity index 100% rename from k9mail/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java rename to k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java diff --git a/k9mail/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java similarity index 100% rename from k9mail/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java rename to k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java diff --git a/k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapListTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/store/imap/ImapListTest.java similarity index 100% rename from k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapListTest.java rename to k9mail-library/src/test/java/com/fsck/k9/mail/store/imap/ImapListTest.java diff --git a/k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java similarity index 100% rename from k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java rename to k9mail-library/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.java diff --git a/k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java similarity index 100% rename from k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java rename to k9mail-library/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java diff --git a/k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java similarity index 100% rename from k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java rename to k9mail-library/src/test/java/com/fsck/k9/mail/store/imap/ImapUtilityTest.java diff --git a/k9mail/build.gradle b/k9mail/build.gradle index ff71994bd..c667e60a4 100644 --- a/k9mail/build.gradle +++ b/k9mail/build.gradle @@ -24,7 +24,6 @@ dependencies { androidTestCompile('com.icegreen:greenmail:1.4.1') { exclude group: 'junit' } - androidTestCompile 'com.madgag.spongycastle:pg:1.51.0.0' testCompile('org.robolectric:robolectric:3.0-rc3') { exclude group: 'org.hamcrest', module: 'hamcrest-core' From 9c258ee60ca38b48e62057ad3911c552dd2a53d4 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 21 May 2015 00:15:53 +0200 Subject: [PATCH 6/8] Ignore Lint warning for OldTargetApi --- config/lint/lint.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/lint/lint.xml b/config/lint/lint.xml index ad613c633..c38682ef5 100644 --- a/config/lint/lint.xml +++ b/config/lint/lint.xml @@ -1,6 +1,7 @@ + From 916929e5073398b343fb6d1435c66f44d260aad7 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 21 May 2015 14:52:50 +0200 Subject: [PATCH 7/8] Fix getting code coverage on CI builds --- k9mail-library/build.gradle | 7 +++++++ k9mail/build.gradle | 1 + 2 files changed, 8 insertions(+) diff --git a/k9mail-library/build.gradle b/k9mail-library/build.gradle index f95a158f6..317862f87 100644 --- a/k9mail-library/build.gradle +++ b/k9mail-library/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply from: '../gradle/plugins/checkstyle-android.gradle' apply from: '../gradle/plugins/findbugs-android.gradle' +apply plugin: 'jacoco' repositories { jcenter() @@ -36,6 +37,12 @@ android { testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } + buildTypes { + debug { + testCoverageEnabled rootProject.testCoverage + } + } + lintOptions { abortOnError true warningsAsErrors true diff --git a/k9mail/build.gradle b/k9mail/build.gradle index c667e60a4..e14789301 100644 --- a/k9mail/build.gradle +++ b/k9mail/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'android-sdk-manager' apply plugin: 'com.android.application' apply from: '../gradle/plugins/checkstyle-android.gradle' apply from: '../gradle/plugins/findbugs-android.gradle' +apply plugin: 'jacoco' repositories { jcenter() From 706fd85a0479666d7a01adcb10734634ec72eaaf Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 21 May 2015 14:53:34 +0200 Subject: [PATCH 8/8] Remove tests-on-jvm module --- tests-on-jvm/build.gradle | 39 ------------------- .../src/test/java/android/text/TextUtils.java | 7 ---- .../src/test/java/android/util/Log.java | 11 ------ .../src/test/java/com/fsck/k9/K9.java | 5 --- 4 files changed, 62 deletions(-) delete mode 100644 tests-on-jvm/build.gradle delete mode 100644 tests-on-jvm/src/test/java/android/text/TextUtils.java delete mode 100644 tests-on-jvm/src/test/java/android/util/Log.java delete mode 100644 tests-on-jvm/src/test/java/com/fsck/k9/K9.java diff --git a/tests-on-jvm/build.gradle b/tests-on-jvm/build.gradle deleted file mode 100644 index 831e87a39..000000000 --- a/tests-on-jvm/build.gradle +++ /dev/null @@ -1,39 +0,0 @@ -repositories { - mavenCentral() -} - -apply plugin: 'java' -apply plugin: 'findbugs' -apply plugin: 'checkstyle' -apply plugin: 'jacoco' - -dependencies { - testCompile project(':k9mail') - testCompile 'junit:junit:4.12' -} - -sourceSets { - test { - compileClasspath += files(project(':k9mail').compileDebugJava.destinationDir) - compileClasspath += project(':k9mail').compileDebugJava.classpath - runtimeClasspath += files(project(':k9mail').compileDebugJava.destinationDir) - runtimeClasspath += project(':k9mail').compileDebugJava.classpath - } -} - -checkstyle { - ignoreFailures = true - configFile file("$rootProject.projectDir/config/checkstyle/checkstyle.xml") -} - -findbugs { - ignoreFailures = true - effort = 'max' - includeFilter = file("$rootProject.projectDir/config/findbugs/include_filter.xml") - excludeFilter = file("$rootProject.projectDir/config/findbugs/exclude_filter.xml") -} - -check.dependsOn 'checkstyleTest' -check.dependsOn 'findbugsTest' - -compileTestJava.dependsOn ':k9mail:compileDebugJava' diff --git a/tests-on-jvm/src/test/java/android/text/TextUtils.java b/tests-on-jvm/src/test/java/android/text/TextUtils.java deleted file mode 100644 index cdc2ddc19..000000000 --- a/tests-on-jvm/src/test/java/android/text/TextUtils.java +++ /dev/null @@ -1,7 +0,0 @@ -package android.text; - -public class TextUtils { - public static boolean isEmpty(CharSequence str) { - return (str == null || str.length() == 0); - } -} diff --git a/tests-on-jvm/src/test/java/android/util/Log.java b/tests-on-jvm/src/test/java/android/util/Log.java deleted file mode 100644 index 4d952eb26..000000000 --- a/tests-on-jvm/src/test/java/android/util/Log.java +++ /dev/null @@ -1,11 +0,0 @@ -package android.util; - -public class Log { - public static int v(String tag, String message) { return 0; } - public static int d(String tag, String message) { return 0; } - public static int d(String tag, String message, Throwable throwable) { return 0; } - public static int i(String tag, String message) { return 0; } - public static int w(String tag, String message) { return 0; } - public static int e(String tag, String message) { return 0; } - public static int e(String tag, String message, Throwable th) { return 0; } -} diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/K9.java b/tests-on-jvm/src/test/java/com/fsck/k9/K9.java deleted file mode 100644 index 64c6b7c47..000000000 --- a/tests-on-jvm/src/test/java/com/fsck/k9/K9.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.fsck.k9; - -public class K9 { - public static boolean DEBUG = false; -}