Skip to content

Commit

Permalink
Test new wordings
Browse files Browse the repository at this point in the history
This wasn't test-first, my bad.
  • Loading branch information
dagguh committed Jun 14, 2024
1 parent ec8bc9a commit e4aeb8c
Showing 1 changed file with 47 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,69 @@ package com.atlassian.performance.tools.license
import org.assertj.core.api.Assertions.assertThat
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File

class VerifyLicensingTaskTest {

@JvmField
@Rule
val temp = TemporaryFolder()

@Test
fun shouldFailAMissingLicense() {
val result = GradleRunner.create()
.withProjectDir(configureBuildGradle())
.withArguments(":check")
.withPluginClasspath()
.withGradleVersion("6.7")
.withDebug(true)
.buildAndFail()
val illegalLicenses = """
plugins {
id("com.atlassian.performance.tools.gradle-release")
id("java-library")
}
dependencies {
api("net.jcip:jcip-annotations:1.0")
}
""".trimIndent()
val result = check(illegalLicenses).buildAndFail()

assertThat(result.task(":verifyLicensing")?.outcome).isEqualTo(TaskOutcome.FAILED)
assertThat(result.output).contains("'No license found' in 'net.jcip:jcip-annotations:1.0'")
}

private fun configureBuildGradle(): File {
val buildFolder = TemporaryFolder()
buildFolder.create()
val buildGradle = buildFolder.newFile("build.gradle")
buildGradle.writeText("""
private fun check(build: String): GradleRunner {
temp.newFile("build.gradle.kts").writeText(build)
return GradleRunner.create()
.withProjectDir(temp.root)
.withArguments(":check")
.withPluginClasspath()
.withGradleVersion("6.7")
.withDebug(true)
}

@Test
fun shouldPassWhenLegal() {
val legalLicenses = """
plugins {
id 'com.atlassian.performance.tools.gradle-release'
id 'java-library'
id("com.atlassian.performance.tools.gradle-release")
id("java-library")
}
dependencies {
api 'net.jcip:jcip-annotations:1.0'
compile 'com.amazonaws:aws-java-sdk-iam:1.11.298'
compile 'org.codehaus.mojo:animal-sniffer-annotations:1.14'
compile 'org.jsoup:jsoup:1.10.2'
compile 'org.eclipse.jgit:org.eclipse.jgit:4.11.0.201803080745-r'
compile 'org.hamcrest:hamcrest-core:1.3'
compile 'joda-time:joda-time:2.8.1'
compile 'com.squareup.okio:okio:1.13.0'
compile 'io.github.bonigarcia:webdrivermanager:1.7.1'
api("com.github.stephenc.jcip:jcip-annotations:1.0-1")
compile("com.amazonaws:aws-java-sdk-iam:1.11.298")
compile("org.codehaus.mojo:animal-sniffer-annotations:1.14")
compile("org.jsoup:jsoup:1.10.2")
compile("org.eclipse.jgit:org.eclipse.jgit:4.11.0.201803080745-r")
compile("org.hamcrest:hamcrest-core:1.3")
compile("joda-time:joda-time:2.8.1")
compile("com.squareup.okio:okio:1.13.0")
compile("io.github.bonigarcia:webdrivermanager:1.7.1")
implementation("com.atlassian.data:random-data:1.4.3")
implementation("org.apache.logging.log4j:log4j-api:2.23.1")
}
""".trimIndent())
return buildFolder.root
""".trimIndent()

val result = check(legalLicenses).build()

assertThat(result.task(":verifyLicensing")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}
}

0 comments on commit e4aeb8c

Please sign in to comment.