Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
Adding validation tests (#1)
Browse files Browse the repository at this point in the history
* Adding validation tests
* Fixing central build
  • Loading branch information
Sergej Shafarenka committed Jul 15, 2018
1 parent 8966474 commit 7ae9a9f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 11 deletions.
15 changes: 13 additions & 2 deletions .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/
Expand All @@ -14,4 +25,4 @@ cache:
- $HOME/.gradle/wrapper/

script:
- ./gradlew clean build
- ./gradlew clean build --stacktrace
25 changes: 23 additions & 2 deletions autoplay/build.gradle.kts
Expand Up @@ -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")
}
}
}
Expand Down Expand Up @@ -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<Test> {
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()
}
}
})
}
@@ -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" {
Expand All @@ -35,6 +49,8 @@ class PlayPublisherPluginTest {
"userFraction"(0.5)
"secretJsonBase64"("c2VjcmV0")
}

"evaluate"()
}

val tasks = project.getTasksByName("publishApkRelease", false)
Expand Down Expand Up @@ -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"()
}
}

}

0 comments on commit 7ae9a9f

Please sign in to comment.