diff --git a/.travis.yml b/.travis.yml index 15ffbfd..0173bc1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,20 @@ -language: java +language: android install: true jdk: - oraclejdk8 +android: + components: + - tools + - platform-tools + - build-tools-27.0.3 + - android-27 + - extra-android-m2repository + +before_install: + - yes | sdkmanager "platforms;android-27" + before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ @@ -14,4 +25,4 @@ cache: - $HOME/.gradle/wrapper/ script: - - ./gradlew clean build + - ./gradlew clean build --stacktrace diff --git a/autoplay/build.gradle.kts b/autoplay/build.gradle.kts index 35b007a..6d36a78 100644 --- a/autoplay/build.gradle.kts +++ b/autoplay/build.gradle.kts @@ -46,8 +46,8 @@ publishing { name = "central" url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2") credentials { - username = project.property("NEXUS_USERNAME") as String? ?: "" - password = project.property("NEXUS_PASSWORD") as String? ?: "" + username = project.getPropertyOrEmptyString("NEXUS_USERNAME") + password = project.getPropertyOrEmptyString("NEXUS_PASSWORD") } } } @@ -103,3 +103,24 @@ publishing { signing { sign(publishing.publications["Autoplay"]) } + +fun Project.getPropertyOrEmptyString(name: String): String { + return if (hasProperty(name)) { + property(name) as String? ?: "" + } else { + "" + } +} + +tasks.withType { + addTestListener(object : TestListener { + override fun beforeSuite(suite: TestDescriptor) {} + override fun beforeTest(testDescriptor: TestDescriptor) {} + override fun afterSuite(suite: TestDescriptor, result: TestResult) {} + override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) { + if (result.resultType == TestResult.ResultType.FAILURE) { + result.exception?.printStackTrace() + } + } + }) +} \ No newline at end of file diff --git a/autoplay/src/test/kotlin/de/halfbit/tools/autoplay/PlayPublisherPluginTest.kt b/autoplay/src/test/kotlin/de/halfbit/tools/autoplay/PlayPublisherPluginTest.kt index 748b17d..13fb09d 100644 --- a/autoplay/src/test/kotlin/de/halfbit/tools/autoplay/PlayPublisherPluginTest.kt +++ b/autoplay/src/test/kotlin/de/halfbit/tools/autoplay/PlayPublisherPluginTest.kt @@ -1,32 +1,46 @@ package de.halfbit.tools.autoplay import com.google.common.truth.Truth.assertThat -import de.halfbit.tools.autoplay.PlayPublisherPlugin -import de.halfbit.tools.autoplay.PublishApkTask import de.halfbit.tools.autoplay.publisher.ReleaseStatus import de.halfbit.tools.autoplay.publisher.ReleaseTrack +import org.gradle.api.Project +import org.gradle.api.ProjectConfigurationException import org.gradle.kotlin.dsl.withGroovyBuilder import org.gradle.testfixtures.ProjectBuilder +import org.hamcrest.core.IsEqual.equalTo +import org.junit.Before +import org.junit.Rule import org.junit.Test +import org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage +import org.junit.rules.ExpectedException import java.io.File -class PlayPublisherPluginTest { +internal class PlayPublisherPluginTest { - @Test - fun `Test PublishApkTask with proper configuration`() { + @Rule + @JvmField + var thrown: ExpectedException = ExpectedException.none() + + private lateinit var project: Project - val project = ProjectBuilder.builder() + @Before + fun before() { + project = ProjectBuilder.builder() .withName("sample-application") .withProjectDir(File("src/test/resources/sample-application/app")) .build() project.pluginManager.apply("com.android.application") project.pluginManager.apply(PlayPublisherPlugin::class.java) + } + + @Test + fun `PlayPublisherPlugin, valid configuration`() { project.withGroovyBuilder { "android" { - "compileSdkVersion"(28) + "compileSdkVersion"(27) } "autoplay" { @@ -35,6 +49,8 @@ class PlayPublisherPluginTest { "userFraction"(0.5) "secretJsonBase64"("c2VjcmV0") } + + "evaluate"() } val tasks = project.getTasksByName("publishApkRelease", false) @@ -69,4 +85,20 @@ class PlayPublisherPluginTest { } + @Test + fun `PublishApkTask, missing 'track'`() { + + thrown.expect(ProjectConfigurationException::class.java) + thrown.expectCause(hasMessage(equalTo("autoplay { track } property is required."))) + + project.withGroovyBuilder { + "android" { + "compileSdkVersion"(27) + } + "autoplay" { + } + "evaluate"() + } + } + } \ No newline at end of file