Browse Source

Convert buildSrc to JUnit 5

Closes gh-9467
Rob Winch 4 years ago
parent
commit
c173e801c5
27 changed files with 465 additions and 604 deletions
  1. 10 4
      buildSrc/build.gradle
  2. 0 37
      buildSrc/src/test/groovy/io/spring/gradle/convention/DependencySetPluginITest.groovy
  3. 0 95
      buildSrc/src/test/groovy/io/spring/gradle/convention/DocsPluginITest.groovy
  4. 0 63
      buildSrc/src/test/groovy/io/spring/gradle/convention/IntegrationTestPluginITest.groovy
  5. 0 39
      buildSrc/src/test/groovy/io/spring/gradle/convention/JacocoPluginITest.groovy
  6. 0 48
      buildSrc/src/test/groovy/io/spring/gradle/convention/JavadocApiPluginITest.groovy
  7. 0 126
      buildSrc/src/test/groovy/io/spring/gradle/convention/ShowcaseITest.groovy
  8. 0 91
      buildSrc/src/test/groovy/io/spring/gradle/convention/SpringMavenPluginITest.groovy
  9. 0 36
      buildSrc/src/test/groovy/io/spring/gradle/convention/TestsConfigurationPluginITest.groovy
  10. 10 27
      buildSrc/src/test/java/io/spring/gradle/TestKit.java
  11. 31 0
      buildSrc/src/test/java/io/spring/gradle/convention/DependencySetPluginITest.java
  12. 85 0
      buildSrc/src/test/java/io/spring/gradle/convention/DocsPluginITest.java
  13. 3 4
      buildSrc/src/test/java/io/spring/gradle/convention/IntegrationPluginTest.java
  14. 52 0
      buildSrc/src/test/java/io/spring/gradle/convention/IntegrationTestPluginITest.java
  15. 31 0
      buildSrc/src/test/java/io/spring/gradle/convention/JacocoPluginITest.java
  16. 38 0
      buildSrc/src/test/java/io/spring/gradle/convention/JavadocApiPluginITest.java
  17. 3 3
      buildSrc/src/test/java/io/spring/gradle/convention/JavadocApiPluginTest.java
  18. 3 3
      buildSrc/src/test/java/io/spring/gradle/convention/RepositoryConventionPluginTests.java
  19. 71 0
      buildSrc/src/test/java/io/spring/gradle/convention/ShowcaseITest.java
  20. 74 0
      buildSrc/src/test/java/io/spring/gradle/convention/SpringMavenPluginITest.java
  21. 31 0
      buildSrc/src/test/java/io/spring/gradle/convention/TestsConfigurationPluginITest.java
  22. 6 10
      buildSrc/src/test/java/io/spring/gradle/convention/UtilsTest.java
  23. 5 5
      buildSrc/src/test/java/io/spring/gradle/convention/sagan/SaganApiTests.java
  24. 5 5
      buildSrc/src/test/java/io/spring/gradle/github/milestones/GitHubMilestoneApiTests.java
  25. 5 5
      buildSrc/src/test/java/org/springframework/gradle/github/milestones/GitHubMilestoneApiTests.java
  26. 1 2
      buildSrc/src/test/java/org/springframework/security/convention/versions/DependencyExcludesTests.java
  27. 1 1
      buildSrc/src/test/java/org/springframework/security/convention/versions/TransitiveDependencyLookupUtilsTest.java

+ 10 - 4
buildSrc/build.gradle

@@ -87,13 +87,19 @@ dependencies {
 	implementation 'org.jfrog.buildinfo:build-info-extractor-gradle:4.9.10'
 	implementation 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1'
 
-	testImplementation 'junit:junit:4.12'
+	testImplementation platform('org.junit:junit-bom:5.7.2')
+	testImplementation "org.junit.jupiter:junit-jupiter-api"
+	testImplementation "org.junit.jupiter:junit-jupiter-params"
+	testImplementation "org.junit.jupiter:junit-jupiter-engine"
 	testImplementation 'org.apache.commons:commons-io:1.3.2'
 	testImplementation 'org.assertj:assertj-core:3.13.2'
-	testImplementation 'org.mockito:mockito-core:3.0.0'
-	testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
+	testImplementation 'org.mockito:mockito-core:3.11.2'
+	testImplementation 'org.mockito:mockito-junit-jupiter:3.11.2'
 	testImplementation "com.squareup.okhttp3:mockwebserver:3.14.9"
 }
 
 
-test.onlyIf { !project.hasProperty("buildSrc.skipTests") }
+test {
+	onlyIf { !project.hasProperty("buildSrc.skipTests") }
+	useJUnitPlatform()
+}

+ 0 - 37
buildSrc/src/test/groovy/io/spring/gradle/convention/DependencySetPluginITest.groovy

@@ -1,37 +0,0 @@
-/*
- * Copyright 2002-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package io.spring.gradle.convention
-
-import io.spring.gradle.testkit.junit.rules.TestKit
-import org.gradle.testkit.runner.BuildResult
-import org.junit.Rule
-import spock.lang.Specification
-
-import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
-
-class DependencySetPluginITest extends Specification {
-	@Rule final TestKit testKit = new TestKit()
-
-	def "dependencies"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/dependencyset")
-			.withArguments('dependencies')
-			.build();
-		then:
-		result.task(":dependencies").outcome == SUCCESS
-		!result.output.contains("FAILED")
-	}
-}

+ 0 - 95
buildSrc/src/test/groovy/io/spring/gradle/convention/DocsPluginITest.groovy

@@ -1,95 +0,0 @@
-/*
- * Copyright 2002-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package io.spring.gradle.convention
-
-import io.spring.gradle.testkit.junit.rules.TestKit
-import org.gradle.testkit.runner.BuildResult
-import org.junit.Rule
-import spock.lang.Specification
-
-import java.util.zip.ZipFile
-
-import static org.gradle.testkit.runner.TaskOutcome.FAILED
-import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
-
-class DocsPluginITest extends Specification {
-	@Rule final TestKit testKit = new TestKit()
-
-	def "build triggers docs"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/docs/simple/")
-			.withArguments('build')
-			.build();
-		then:
-		result.task(":build").outcome == SUCCESS
-		and:
-		result.task(":docs").outcome == SUCCESS
-		and:
-		result.task(":docsZip").outcome == SUCCESS
-		and:
-		def zip = new File(testKit.getRootDir(), 'build/distributions/simple-1.0.0.BUILD-SNAPSHOT-docs.zip')
-		def names = new ZipFile(zip).entries()*.name
-		names.contains("docs/reference/html5/index.html")
-		names.contains("docs/reference/pdf/simple-reference.pdf")
-	}
-
-	def "asciidoc copies images"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/docs/simple/")
-				.withArguments('asciidoctor')
-				.build();
-		then:
-		result.task(":asciidoctor").outcome == SUCCESS
-		new File(testKit.getRootDir(), "build/docs/asciidoc/images").exists()
-	}
-
-	def "asciidoc docinfo from resources used"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/docs/simple/")
-				.withArguments('asciidoctor')
-				.build();
-		then:
-		result.task(":asciidoctor").outcome == SUCCESS
-		new File(testKit.getRootDir(), "build/docs/asciidoc/index.html").getText().contains("""<script type="text/javascript" src="js/tocbot/tocbot.min.js"></script>""")
-	}
-
-	def "missing attribute fails"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/docs/missing-attribute/")
-				.withArguments(':asciidoctor')
-				.buildAndFail();
-		then:
-		result.task(":asciidoctor").outcome == FAILED
-	}
-
-	def "missing include"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/docs/missing-include/")
-				.withArguments(':asciidoctor')
-				.buildAndFail();
-		then:
-		result.task(":asciidoctor").outcome == FAILED
-	}
-
-	def "missing cross reference"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/docs/missing-cross-reference/")
-				.withArguments(':asciidoctor')
-				.buildAndFail();
-		then:
-		result.task(":asciidoctor").outcome == FAILED
-	}
-}

+ 0 - 63
buildSrc/src/test/groovy/io/spring/gradle/convention/IntegrationTestPluginITest.groovy

@@ -1,63 +0,0 @@
-/*
- * Copyright 2016-2018 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package io.spring.gradle.convention
-
-import io.spring.gradle.testkit.junit.rules.TestKit
-import org.gradle.testkit.runner.BuildResult
-import org.junit.Rule
-import spock.lang.Specification
-
-import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
-
-class IntegrationTestPluginITest extends Specification {
-	@Rule final TestKit testKit = new TestKit()
-
-	def "check with java plugin"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/integrationtest/withjava/")
-				.withArguments('check')
-				.build();
-		then:
-		result.task(":check").outcome == SUCCESS
-		and:
-		new File(testKit.getRootDir(), 'build/test-results/integrationTest/').exists()
-		new File(testKit.getRootDir(), 'build/reports/tests/integrationTest/').exists()
-	}
-
-	def "check with propdeps"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/integrationtest/withpropdeps/")
-				.withArguments('check')
-				.build();
-		then:
-		result.task(":check").outcome == SUCCESS
-		and:
-		new File(testKit.getRootDir(), 'build/test-results/integrationTest/').exists()
-		new File(testKit.getRootDir(), 'build/reports/tests/integrationTest/').exists()
-	}
-
-	def "check with groovy plugin"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/integrationtest/withgroovy/")
-			.withArguments('check')
-			.build();
-		then:
-		result.task(":check").outcome == SUCCESS
-		and:
-		new File(testKit.getRootDir(), 'build/test-results/integrationTest/').exists()
-		new File(testKit.getRootDir(), 'build/reports/tests/integrationTest/').exists()
-	}
-}

+ 0 - 39
buildSrc/src/test/groovy/io/spring/gradle/convention/JacocoPluginITest.groovy

@@ -1,39 +0,0 @@
-/*
- * Copyright 2002-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package io.spring.gradle.convention
-
-import io.spring.gradle.testkit.junit.rules.TestKit
-import org.gradle.testkit.runner.BuildResult
-import org.junit.Rule
-import spock.lang.Specification
-
-import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
-
-class JacocoPluginITest extends Specification {
-	@Rule final TestKit testKit = new TestKit()
-
-	def "check with java plugin"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/jacoco/java/")
-				.withArguments('check')
-				.build();
-		then:
-		result.task(":check").outcome == SUCCESS
-		and:
-		new File(testKit.getRootDir(), 'build/jacoco').exists()
-		new File(testKit.getRootDir(), 'build/reports/jacoco/test/html/').exists()
-	}
-}

+ 0 - 48
buildSrc/src/test/groovy/io/spring/gradle/convention/JavadocApiPluginITest.groovy

@@ -1,48 +0,0 @@
-/*
- * Copyright 2002-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package io.spring.gradle.convention
-
-import org.gradle.testkit.runner.BuildResult
-import org.gradle.testkit.runner.GradleRunner
-import org.junit.Rule
-import org.junit.rules.TemporaryFolder
-import spock.lang.Specification
-
-import static org.gradle.testkit.runner.TaskOutcome.*;
-
-import io.spring.gradle.testkit.junit.rules.TestKit
-import org.apache.commons.io.FileUtils
-
-class JavadocApiPluginITest extends Specification {
-	@Rule final TestKit testKit = new TestKit()
-
-	def "multimodule api"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/javadocapi/multimodule/")
-			.withArguments('api')
-			.build();
-		then:
-		result.task(":api").outcome == SUCCESS
-		and:
-		File allClasses = new File(testKit.getRootDir(), 'build/api/allclasses-noframe.html');
-		File index = new File(testKit.getRootDir(), 'build/api/allclasses.html');
-        new File(testKit.getRootDir(), "build/api/").listFiles().each { println it }
-		File listing = allClasses.exists() ? allClasses : index
-		listing.text.contains('sample/Api.html')
-        listing.text.contains('sample/Impl.html')
-		!listing.text.contains('sample/Sample.html')
-	}
-}

+ 0 - 126
buildSrc/src/test/groovy/io/spring/gradle/convention/ShowcaseITest.groovy

@@ -1,126 +0,0 @@
-/*
- * Copyright 2016-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package io.spring.gradle.convention
-
-import io.spring.gradle.testkit.junit.rules.TestKit
-import org.gradle.testkit.runner.BuildResult
-import org.gradle.testkit.runner.TaskOutcome
-import org.junit.Rule
-import spock.lang.Ignore
-import spock.lang.Specification
-
-class ShowcaseITest extends Specification {
-
-	@Rule final TestKit testKit = new TestKit()
-
-	def "build"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/showcase/")
-				.withArguments('build','--stacktrace')
-				.forwardOutput()
-				.build();
-		then: 'entire build passes'
-		result.output.contains("BUILD SUCCESSFUL")
-	}
-
-	@Ignore
-	def "install"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/showcase/")
-				.withArguments('install','--stacktrace')
-				.build();
-		then:
-		result.output.contains("SUCCESS")
-
-		and: 'pom exists'
-		File pom = new File(testKit.getRootDir(), 'sgbcs-core/build/poms/pom-default.xml')
-		pom.exists()
-		String pomText = pom.getText()
-
-		and: 'pom does not contain <dependencyManagement>'
-		!pomText.contains('<dependencyManagement>')
-
-		and: 'creates optional dependencies correctly'
-		pomText.replaceAll('\\s','').contains("""<dependency>
-			<groupId>org.springframework</groupId>
-			<artifactId>spring-test</artifactId>
-			<scope>test</scope>
-			<version>4.3.6.RELEASE</version>
-		</dependency>""".replaceAll('\\s',''))
-
-		and: 'adds author'
-		pomText.replaceAll('\\s','').contains("""<developers>
-			<developer>
-				<id>rwinch</id>
-				<name>Rob Winch</name>
-				<email>rwinch@pivotal.io</email>
-			</developer>
-			<developer>
-				<id>jgrandja</id>
-				<name>Joe Grandja</name>
-				<email>jgrandja@pivotal.io</email>
-			</developer>
-		</developers>""".replaceAll('\\s',''))
-
-		and: 'adds repositories'
-		pomText.replaceAll('\\s','').contains("""<scm>
-			<connection>scm:git:git://github.com/spring-projects/spring-security</connection>
-			<developerConnection>scm:git:git://github.com/spring-projects/spring-security</developerConnection>
-			<url>https://github.com/spring-projects/spring-security</url>
-		</scm>""".replaceAll('\\s',''))
-
-		and: 'adds description & url'
-		pomText.contains('<description>sgbcs-core</description>')
-		pomText.contains('<url>https://spring.io/spring-security</url>')
-
-		and: 'adds organization'
-		pomText.replaceAll('\\s','').contains('''<organization>
-			<name>spring.io</name>
-			<url>https://spring.io/</url>
-		</organization>'''.replaceAll('\\s',''))
-
-		and: 'adds licenses'
-		pomText.replaceAll('\\s','').contains('''	<licenses>
-			<license>
-				<name>The Apache Software License, Version 2.0</name>
-				<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
-				<distribution>repo</distribution>
-			</license>
-		</licenses>'''.replaceAll('\\s',''))
-
-		and: 'adds scm'
-		pomText.replaceAll('\\s','').replaceAll('\\s','').contains("""<scm>
-			<connection>scm:git:git://github.com/spring-projects/spring-security</connection>
-			<developerConnection>scm:git:git://github.com/spring-projects/spring-security</developerConnection>
-			<url>https://github.com/spring-projects/spring-security</url>
-		</scm>""".replaceAll('\\s',''))
-
-		and: 'bom created'
-		File bom = new File(testKit.getRootDir(), 'bom/build/poms/pom-default.xml')
-		bom.exists()
-		String bomText = bom.getText()
-		bomText.contains("""<artifactId>sgbcs-core</artifactId>""")
-
-		when: 'mavenBom ran again'
-		result = testKit.withProjectResource("samples/showcase/")
-				.withArguments('mavenBom','--stacktrace')
-				.build();
-		then: 'mavenBom is not up to date since install is never up to date'
-		result.task(':bom:mavenBom').getOutcome() == TaskOutcome.SUCCESS
-	}
-
-}

+ 0 - 91
buildSrc/src/test/groovy/io/spring/gradle/convention/SpringMavenPluginITest.groovy

@@ -1,91 +0,0 @@
-/*
- * Copyright 2016-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package io.spring.gradle.convention
-
-import io.spring.gradle.testkit.junit.rules.TestKit
-import org.gradle.testkit.runner.BuildResult
-import org.junit.Rule
-import spock.lang.Ignore
-import spock.lang.Specification
-
-import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
-
-class SpringMavenPluginITest extends Specification {
-
-	@Rule final TestKit testKit = new TestKit()
-
-	@Ignore
-	def "install"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/maven/install")
-			.withArguments('install')
-			.build();
-		then: 'pom contains optional'
-		result.output.contains("SUCCESS")
-		File pom = new File(testKit.getRootDir(), 'build/poms/pom-default.xml')
-		pom.exists()
-		String pomText = pom.getText()
-		pomText.replaceAll('\\s','').contains("""<dependency>
-			<groupId>aopalliance</groupId>
-			<artifactId>aopalliance</artifactId>
-			<version>1.0</version>
-			<scope>compile</scope>
-			<optional>true</optional>
-		</dependency>""".replaceAll('\\s',''))
-	}
-
-	@Ignore
-	def "signArchives when in memory"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/maven/signing")
-				.withArguments('signArchives')
-				.withEnvironment(["ORG_GRADLE_PROJECT_signingKey" : signingKey,
-								  "ORG_GRADLE_PROJECT_signingPassword" : "password"])
-				.forwardOutput()
-				.build();
-		then:
-		result.output.contains("SUCCESS")
-		File jar = new File(testKit.getRootDir(), 'build/libs/signing-1.0.0.RELEASE.jar')
-		jar.exists()
-		File signature = new File("${jar.absolutePath}.asc")
-		signature.exists()
-	}
-
-	def "upload"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/maven/upload")
-				.withArguments('uploadArchives')
-				.forwardOutput()
-				.build();
-		then: 'pom contains optional'
-		result.output.contains("SUCCESS")
-		File pom = new File(testKit.getRootDir(), 'build/poms/pom-default.xml')
-		pom.exists()
-		String pomText = pom.getText()
-		pomText.replaceAll('\\s','').contains("""<dependency>
-			<groupId>aopalliance</groupId>
-			<artifactId>aopalliance</artifactId>
-			<version>1.0</version>
-			<scope>compile</scope>
-			<optional>true</optional>
-			</dependency>""".replaceAll('\\s',''))
-	}
-
-	def getSigningKey() {
-		getClass().getResource("/test-private.pgp").text
-	}
-}

+ 0 - 36
buildSrc/src/test/groovy/io/spring/gradle/convention/TestsConfigurationPluginITest.groovy

@@ -1,36 +0,0 @@
-/*
- * Copyright 2002-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package io.spring.gradle.convention
-
-import io.spring.gradle.testkit.junit.rules.TestKit
-import org.gradle.testkit.runner.BuildResult
-import org.junit.Rule
-import spock.lang.Specification
-
-import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
-
-class TestsConfigurationPluginITest extends Specification {
-	@Rule final TestKit testKit = new TestKit()
-
-	def "can find dependency"() {
-		when:
-		BuildResult result = testKit.withProjectResource("samples/testsconfiguration")
-				.withArguments('check')
-				.build();
-		then:
-		result.task(":web:check").outcome == SUCCESS
-	}
-}

+ 10 - 27
buildSrc/src/test/groovy/io/spring/gradle/testkit/junit/rules/TestKit.java → buildSrc/src/test/java/io/spring/gradle/TestKit.java

@@ -13,42 +13,25 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package io.spring.gradle.testkit.junit.rules;
+package io.spring.gradle;
+
+import org.apache.commons.io.FileUtils;
+import org.gradle.testkit.runner.GradleRunner;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
 
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.file.Paths;
 import java.util.Enumeration;
 
-import org.apache.commons.io.FileUtils;
-import org.gradle.testkit.runner.GradleRunner;
-import org.junit.rules.TemporaryFolder;
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-public class TestKit implements TestRule {
-	final TemporaryFolder testProjectDir = new TemporaryFolder();
-	File buildDir;
-
-	@Override
-	public Statement apply(Statement base, Description description) {
-		Statement wrapped = new Statement() {
+public class TestKit {
+	final File buildDir;
 
-			@Override
-			public void evaluate() throws Throwable {
-				try {
-					buildDir = testProjectDir.newFolder();
-				} catch(IOException e) {
-					throw new RuntimeException(e);
-				}
-				base.evaluate();
-			}
-		};
-		return testProjectDir.apply(wrapped, description);
+	public TestKit(File buildDir) {
+		this.buildDir = buildDir;
 	}
 
 	public File getRootDir() {

+ 31 - 0
buildSrc/src/test/java/io/spring/gradle/convention/DependencySetPluginITest.java

@@ -0,0 +1,31 @@
+package io.spring.gradle.convention;
+
+import io.spring.gradle.TestKit;
+import org.gradle.testkit.runner.BuildResult;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS;
+
+public class DependencySetPluginITest {
+	private TestKit testKit;
+
+	@BeforeEach
+	void setup(@TempDir Path tempDir) {
+		this.testKit = new TestKit(tempDir.toFile());
+	}
+
+	@Test
+	public void dependencies() throws Exception {
+		BuildResult result = testKit.withProjectResource("samples/dependencyset")
+				.withArguments("dependencies")
+				.build();
+
+		assertThat(result.task(":dependencies").getOutcome()).isEqualTo(SUCCESS);
+		assertThat(result.getOutput()).doesNotContain("FAILED");
+	}
+}

+ 85 - 0
buildSrc/src/test/java/io/spring/gradle/convention/DocsPluginITest.java

@@ -0,0 +1,85 @@
+package io.spring.gradle.convention;
+
+import io.spring.gradle.TestKit;
+import org.codehaus.groovy.runtime.ResourceGroovyMethods;
+import org.gradle.testkit.runner.BuildResult;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.gradle.testkit.runner.TaskOutcome.FAILED;
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS;
+
+public class DocsPluginITest {
+	private TestKit testKit;
+
+	@BeforeEach
+	void setup(@TempDir Path tempDir) {
+		this.testKit = new TestKit(tempDir.toFile());
+	}
+
+	@Test
+	public void buildTriggersDocs() throws Exception {
+		BuildResult result = testKit.withProjectResource("samples/docs/simple/")
+				.withArguments("build")
+				.build();
+		assertThat(result.task(":build").getOutcome()).isEqualTo(SUCCESS);
+		assertThat(result.task(":docs").getOutcome()).isEqualTo(SUCCESS);
+		assertThat(result.task(":docsZip").getOutcome()).isEqualTo(SUCCESS);
+		File zip = new File(testKit.getRootDir(), "build/distributions/simple-1.0.0.BUILD-SNAPSHOT-docs.zip");
+		List<? extends ZipEntry> entries = Collections.list(new ZipFile(zip).entries());
+		assertThat(entries)
+				.extracting(ZipEntry::getName)
+				.contains("docs/reference/html5/index.html")
+				.contains("docs/reference/pdf/simple-reference.pdf");
+	}
+
+	@Test
+	public void asciidocCopiesImages() throws Exception {
+		BuildResult result = testKit.withProjectResource("samples/docs/simple/").withArguments("asciidoctor").build();
+		assertThat(result.task(":asciidoctor").getOutcome()).isEqualTo(SUCCESS);
+		assertThat(new File(testKit.getRootDir(), "build/docs/asciidoc/images")).exists();
+	}
+
+	@Test
+	public void asciidocDocInfoFromResourcesUsed() throws Exception {
+		BuildResult result = this.testKit.withProjectResource("samples/docs/simple/")
+				.withArguments("asciidoctor")
+				.build();
+		assertThat(result.task(":asciidoctor").getOutcome()).isEqualTo(SUCCESS);
+		assertThat(ResourceGroovyMethods.getText(new File(testKit.getRootDir(), "build/docs/asciidoc/index.html")))
+				.contains("<script type=\"text/javascript\" src=\"js/tocbot/tocbot.min.js\"></script>");
+	}
+
+	@Test
+	public void missingAttributeFails() throws Exception {
+		BuildResult result = this.testKit.withProjectResource("samples/docs/missing-attribute/")
+				.withArguments(":asciidoctor")
+				.buildAndFail();
+		assertThat(result.task(":asciidoctor").getOutcome()).isEqualTo(FAILED);
+	}
+
+	@Test
+	public void missingInclude() throws Exception {
+		BuildResult result = this.testKit.withProjectResource("samples/docs/missing-include/")
+				.withArguments(":asciidoctor")
+				.buildAndFail();
+		assertThat(result.task(":asciidoctor").getOutcome()).isEqualTo(FAILED);
+	}
+
+	@Test
+	public void missingCrossReference() throws Exception {
+		BuildResult result = this.testKit.withProjectResource("samples/docs/missing-cross-reference/")
+				.withArguments(":asciidoctor")
+				.buildAndFail();
+		assertThat(result.task(":asciidoctor").getOutcome()).isEqualTo(FAILED);
+	}
+}

+ 3 - 4
buildSrc/src/test/java/io/spring/gradle/convention/IntegrationPluginTest.java

@@ -19,10 +19,9 @@ package io.spring.gradle.convention;
 import org.apache.commons.io.FileUtils;
 import org.gradle.api.Project;
 import org.gradle.api.plugins.JavaPlugin;
-import org.gradle.api.tasks.javadoc.Javadoc;
 import org.gradle.testfixtures.ProjectBuilder;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
 
 import java.io.File;
 
@@ -34,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class IntegrationPluginTest {
 	Project rootProject;
 
-	@After
+	@AfterEach
 	public void cleanup() throws Exception {
 		if (rootProject != null) {
 			FileUtils.deleteDirectory(rootProject.getProjectDir());

+ 52 - 0
buildSrc/src/test/java/io/spring/gradle/convention/IntegrationTestPluginITest.java

@@ -0,0 +1,52 @@
+package io.spring.gradle.convention;
+
+import io.spring.gradle.TestKit;
+import org.gradle.testkit.runner.BuildResult;
+import org.gradle.testkit.runner.TaskOutcome;
+import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class IntegrationTestPluginITest {
+	private io.spring.gradle.TestKit testKit;
+
+	@BeforeEach
+	void setup(@TempDir Path tempDir) {
+		this.testKit = new TestKit(tempDir.toFile());
+	}
+
+    @Test
+	public void checkWithJavaPlugin() throws Exception {
+        BuildResult result = this.testKit.withProjectResource("samples/integrationtest/withjava/")
+				.withArguments("check")
+				.build();
+		assertThat(result.task(":check").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
+		assertThat(new File(testKit.getRootDir(), "build/test-results/integrationTest/")).exists();
+		assertThat(new File(testKit.getRootDir(), "build/reports/tests/integrationTest/")).exists();
+	}
+
+	@Test
+    public void checkWithPropdeps() throws Exception {
+        BuildResult result = this.testKit.withProjectResource("samples/integrationtest/withpropdeps/")
+				.withArguments("check")
+				.build();
+		assertThat(result.task(":check").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
+		assertThat(new File(testKit.getRootDir(), "build/test-results/integrationTest/")).exists();
+		assertThat(new File(testKit.getRootDir(), "build/reports/tests/integrationTest/")).exists();
+	}
+
+	@Test
+    public void checkWithGroovy() throws Exception {
+		BuildResult result = this.testKit.withProjectResource("samples/integrationtest/withgroovy/")
+				.withArguments("check")
+				.build();
+		assertThat(result.task(":check").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
+		assertThat(new File(testKit.getRootDir(), "build/test-results/integrationTest/")).exists();
+		assertThat(new File(testKit.getRootDir(), "build/reports/tests/integrationTest/")).exists();
+	}
+}

+ 31 - 0
buildSrc/src/test/java/io/spring/gradle/convention/JacocoPluginITest.java

@@ -0,0 +1,31 @@
+package io.spring.gradle.convention;
+
+import org.gradle.testkit.runner.BuildResult;
+import org.gradle.testkit.runner.TaskOutcome;
+import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class JacocoPluginITest{
+	private io.spring.gradle.TestKit testKit;
+
+	@BeforeEach
+	void setup(@TempDir Path tempDir) {
+		this.testKit = new io.spring.gradle.TestKit(tempDir.toFile());
+	}
+
+    @Test
+	public void checkWithJavaPlugin() throws Exception {
+        BuildResult result = this.testKit.withProjectResource("samples/jacoco/java/")
+				.withArguments("check")
+				.build();
+		assertThat(result.task(":check").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
+		assertThat(new File(testKit.getRootDir(), "build/jacoco")).exists();
+		assertThat(new File(testKit.getRootDir(), "build/reports/jacoco/test/html/")).exists();
+	}
+}

+ 38 - 0
buildSrc/src/test/java/io/spring/gradle/convention/JavadocApiPluginITest.java

@@ -0,0 +1,38 @@
+package io.spring.gradle.convention;
+
+import io.spring.gradle.TestKit;
+import org.apache.commons.io.FileUtils;
+import org.gradle.testkit.runner.BuildResult;
+import org.gradle.testkit.runner.TaskOutcome;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class JavadocApiPluginITest {
+	private TestKit testKit;
+
+	@BeforeEach
+	void setup(@TempDir Path tempDir) {
+		this.testKit = new TestKit(tempDir.toFile());
+	}
+
+	@Test
+    public void multiModuleApi() throws Exception {
+        BuildResult result = this.testKit.withProjectResource("samples/javadocapi/multimodule/")
+				.withArguments("api")
+				.build();
+		assertThat(result.task(":api").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
+        File allClasses = new File(testKit.getRootDir(), "build/api/allclasses-noframe.html");
+		File index = new File(testKit.getRootDir(), "build/api/allclasses.html");
+		File listing = allClasses.exists() ? allClasses : index;
+		String listingText = FileUtils.readFileToString(listing);
+		assertThat(listingText).contains("sample/Api.html");
+        assertThat(listingText).contains("sample/Impl.html");
+		assertThat(listingText).doesNotContain("sample/Sample.html");
+	}
+}

+ 3 - 3
buildSrc/src/test/java/io/spring/gradle/convention/JavadocApiPluginTest.java

@@ -23,8 +23,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 import org.gradle.api.Project;
 import org.gradle.api.tasks.javadoc.Javadoc;
 import org.gradle.testfixtures.ProjectBuilder;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
 
 /**
  * @author Rob Winch
@@ -32,7 +32,7 @@ import org.junit.Test;
 public class JavadocApiPluginTest {
 	Project rootProject;
 
-	@After
+	@AfterEach
 	public void cleanup() throws Exception {
 		if (rootProject != null) {
 			FileUtils.deleteDirectory(rootProject.getProjectDir());

+ 3 - 3
buildSrc/src/test/java/io/spring/gradle/convention/RepositoryConventionPluginTests.java

@@ -22,8 +22,8 @@ import org.gradle.api.artifacts.repositories.ArtifactRepository;
 import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
 import org.gradle.api.plugins.ExtraPropertiesExtension;
 import org.gradle.testfixtures.ProjectBuilder;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -34,7 +34,7 @@ public class RepositoryConventionPluginTests {
 
 	private Project project = ProjectBuilder.builder().build();
 
-	@Before
+	@BeforeEach
 	public void setUp() {
 		this.project.getProperties().clear();
 	}

+ 71 - 0
buildSrc/src/test/java/io/spring/gradle/convention/ShowcaseITest.java

@@ -0,0 +1,71 @@
+package io.spring.gradle.convention;
+
+import io.spring.gradle.TestKit;
+import org.codehaus.groovy.runtime.ResourceGroovyMethods;
+import org.gradle.testkit.runner.BuildResult;
+import org.gradle.testkit.runner.TaskOutcome;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ShowcaseITest {
+	private TestKit testKit;
+
+	@BeforeEach
+	void setup(@TempDir Path tempDir) {
+		this.testKit = new TestKit(tempDir.toFile());
+	}
+
+    @Test
+	public void build() throws Exception {
+        BuildResult result = this.testKit.withProjectResource("samples/showcase/")
+				.withArguments("build", "--stacktrace")
+				.forwardOutput()
+				.build();
+		assertThat(result.getOutput()).contains("BUILD SUCCESSFUL");
+	}
+
+	@Test
+	@Disabled
+    public void install() throws Exception {
+		BuildResult result = this.testKit
+			.withProjectResource("samples/showcase/")
+			.withArguments("install", "--stacktrace")
+			.build();
+
+        assertThat(result.getOutput()).contains("SUCCESS");
+
+		File pom = new File(testKit.getRootDir(), "sgbcs-core/build/poms/pom-default.xml");
+		assertThat(pom).exists();
+
+		String pomText = new String(Files.readAllBytes(pom.toPath()));
+		String pomTextNoSpace = pomText.replaceAll("\\s", "");
+
+		assertThat(pomText).doesNotContain("<dependencyManagement>");
+
+		assertThat(pomTextNoSpace).contains("<dependency>\n			<groupId>org.springframework</groupId>\n			<artifactId>spring-test</artifactId>\n			<scope>test</scope>\n			<version>4.3.6.RELEASE</version>\n		</dependency>".replaceAll("\\s", ""));
+		assertThat(pomTextNoSpace).contains("<developers>\n			<developer>\n				<id>rwinch</id>\n				<name>Rob Winch</name>\n				<email>rwinch@pivotal.io</email>\n			</developer>\n			<developer>\n				<id>jgrandja</id>\n				<name>Joe Grandja</name>\n				<email>jgrandja@pivotal.io</email>\n			</developer>\n		</developers>".replaceAll("\\s", ""));
+		assertThat(pomTextNoSpace).contains("<scm>\n			<connection>scm:git:git://github.com/spring-projects/spring-security</connection>\n			<developerConnection>scm:git:git://github.com/spring-projects/spring-security</developerConnection>\n			<url>https://github.com/spring-projects/spring-security</url>\n		</scm>".replaceAll("\\s", ""));
+		assertThat(pomTextNoSpace).contains("<description>sgbcs-core</description>");
+		assertThat(pomTextNoSpace).contains("<url>https://spring.io/spring-security</url>");
+		assertThat(pomTextNoSpace).contains("<organization>\n			<name>spring.io</name>\n			<url>https://spring.io/</url>\n		</organization>".replaceAll("\\s", ""));
+		assertThat(pomTextNoSpace).contains("	<licenses>\n			<license>\n				<name>The Apache Software License, Version 2.0</name>\n				<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>\n				<distribution>repo</distribution>\n			</license>\n		</licenses>".replaceAll("\\s", ""));
+		assertThat(pomTextNoSpace).contains("<scm>\n			<connection>scm:git:git://github.com/spring-projects/spring-security</connection>\n			<developerConnection>scm:git:git://github.com/spring-projects/spring-security</developerConnection>\n			<url>https://github.com/spring-projects/spring-security</url>\n		</scm>".replaceAll("\\s", ""));
+
+		File bom = new File(testKit.getRootDir(), "bom/build/poms/pom-default.xml");
+		assertThat(bom).exists();
+		assertThat(bom).hasContent("<artifactId>sgbcs-core</artifactId>");
+
+		BuildResult secondBuild = this.testKit.withProjectResource("samples/showcase/").withArguments("mavenBom", "--stacktrace").build();
+		// mavenBom is not up to date since install is never up to date
+		assertThat(result.task(":bom:mavenBom").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
+	}
+
+}

+ 74 - 0
buildSrc/src/test/java/io/spring/gradle/convention/SpringMavenPluginITest.java

@@ -0,0 +1,74 @@
+package io.spring.gradle.convention;
+
+import io.spring.gradle.TestKit;
+import org.apache.commons.io.IOUtils;
+import org.gradle.testkit.runner.BuildResult;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.LinkedHashMap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SpringMavenPluginITest {
+
+	private TestKit testKit;
+
+	@BeforeEach
+	void setup(@TempDir Path tempDir) {
+		this.testKit = new TestKit(tempDir.toFile());
+	}
+
+    @Disabled
+	@Test
+    public void install()  throws Exception {
+        BuildResult result = this.testKit.withProjectResource("samples/maven/install")
+				.withArguments("install")
+				.build();
+		assertThat(result.getOutput()).contains("SUCCESS");
+		File pom = new File(testKit.getRootDir(), "build/poms/pom-default.xml");
+		assertThat(pom).exists();
+		String pomText = new String(Files.readAllBytes(pom.toPath()));
+		assertThat(pomText.replaceAll("\\s", "")).contains("<dependency>\n			<groupId>aopalliance</groupId>\n			<artifactId>aopalliance</artifactId>\n			<version>1.0</version>\n			<scope>compile</scope>\n			<optional>true</optional>\n		</dependency>".replaceAll("\\s", ""));
+	}
+
+    @Disabled
+	@Test
+    public void signArchivesWhenInMemory() throws Exception {
+        LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(2);
+        map.put("ORG_GRADLE_PROJECT_signingKey", getSigningKey());
+        map.put("ORG_GRADLE_PROJECT_signingPassword", "password");
+        BuildResult result = this.testKit.withProjectResource("samples/maven/signing")
+				.withArguments("signArchives")
+				.withEnvironment(map)
+				.forwardOutput()
+				.build();
+		assertThat(result.getOutput()).contains("SUCCESS");
+		final File jar = new File(testKit.getRootDir(), "build/libs/signing-1.0.0.RELEASE.jar");
+		assertThat(jar).exists();
+		File signature = new File(jar.getAbsolutePath() + ".asc");
+		assertThat(signature).exists();
+	}
+
+	@Test
+    public void upload() throws Exception {
+        BuildResult result = this.testKit.withProjectResource("samples/maven/upload")
+				.withArguments("uploadArchives")
+				.forwardOutput()
+				.build();
+		assertThat(result.getOutput()).contains("SUCCESS");
+		File pom = new File(testKit.getRootDir(), "build/poms/pom-default.xml");
+		assertThat(pom).exists();
+		String pomText = new String(Files.readAllBytes(pom.toPath()));
+		assertThat(pomText.replaceAll("\\s", "")).contains("<dependency>\n			<groupId>aopalliance</groupId>\n			<artifactId>aopalliance</artifactId>\n			<version>1.0</version>\n			<scope>compile</scope>\n			<optional>true</optional>\n			</dependency>".replaceAll("\\s", ""));
+	}
+
+    public String getSigningKey() throws Exception {
+		return IOUtils.toString(getClass().getResource("/test-private.pgp"));
+	}
+}

+ 31 - 0
buildSrc/src/test/java/io/spring/gradle/convention/TestsConfigurationPluginITest.java

@@ -0,0 +1,31 @@
+package io.spring.gradle.convention;
+
+import io.spring.gradle.TestKit;
+import org.gradle.testkit.runner.BuildResult;
+import org.gradle.testkit.runner.TaskOutcome;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class TestsConfigurationPluginITest {
+
+	private TestKit testKit;
+
+	@BeforeEach
+	void setup(@TempDir Path tempDir) {
+		this.testKit = new TestKit(tempDir.toFile());
+	}
+
+	@Test
+    public void canFindDepencency() throws Exception {
+        BuildResult result = this.testKit.withProjectResource("samples/testsconfiguration")
+				.withArguments("check")
+				.build();
+		assertThat(result.task(":web:check").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
+	}
+
+}

+ 6 - 10
buildSrc/src/test/java/io/spring/gradle/convention/UtilsTest.java

@@ -5,26 +5,21 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.when;
 
 import org.gradle.api.Project;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
 public class UtilsTest {
 	@Mock
 	Project project;
 	@Mock
 	Project rootProject;
 
-	@Before
-	public void setup() {
-		when(project.getRootProject()).thenReturn(rootProject);
-	}
-
 	@Test
 	public void getProjectName() {
+		when(project.getRootProject()).thenReturn(rootProject);
 		when(rootProject.getName()).thenReturn("spring-security");
 
 		assertThat(Utils.getProjectName(project)).isEqualTo("spring-security");
@@ -32,6 +27,7 @@ public class UtilsTest {
 
 	@Test
 	public void getProjectNameWhenEndsWithBuildThenStrippedOut() {
+		when(project.getRootProject()).thenReturn(rootProject);
 		when(rootProject.getName()).thenReturn("spring-security-build");
 
 		assertThat(Utils.getProjectName(project)).isEqualTo("spring-security");

+ 5 - 5
buildSrc/src/test/java/io/spring/gradle/convention/sagan/SaganApiTests.java

@@ -19,9 +19,9 @@ package io.spring.gradle.convention.sagan;
 import okhttp3.mockwebserver.MockResponse;
 import okhttp3.mockwebserver.MockWebServer;
 import okhttp3.mockwebserver.RecordedRequest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.springframework.gradle.sagan.Release;
 import org.springframework.gradle.sagan.SaganApi;
 
@@ -38,7 +38,7 @@ public class SaganApiTests {
 
 	private String baseUrl;
 
-	@Before
+	@BeforeEach
 	public void setup() throws Exception {
 		this.server = new MockWebServer();
 		this.server.start();
@@ -47,7 +47,7 @@ public class SaganApiTests {
 		this.sagan.setBaseUrl(this.baseUrl);
 	}
 
-	@After
+	@AfterEach
 	public void cleanup() throws Exception {
 		this.server.shutdown();
 	}

+ 5 - 5
buildSrc/src/test/java/io/spring/gradle/github/milestones/GitHubMilestoneApiTests.java

@@ -3,9 +3,9 @@ package io.spring.gradle.github.milestones;
 import okhttp3.mockwebserver.MockResponse;
 import okhttp3.mockwebserver.MockWebServer;
 import okhttp3.mockwebserver.RecordedRequest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.springframework.gradle.github.milestones.GitHubMilestoneApi;
 import org.springframework.gradle.github.milestones.RepositoryRef;
 
@@ -24,7 +24,7 @@ public class GitHubMilestoneApiTests {
 
 	private String baseUrl;
 
-	@Before
+	@BeforeEach
 	public void setup() throws Exception {
 		this.server = new MockWebServer();
 		this.server.start();
@@ -33,7 +33,7 @@ public class GitHubMilestoneApiTests {
 		this.github.setBaseUrl(this.baseUrl);
 	}
 
-	@After
+	@AfterEach
 	public void cleanup() throws Exception {
 		this.server.shutdown();
 	}

+ 5 - 5
buildSrc/src/test/java/org/springframework/gradle/github/milestones/GitHubMilestoneApiTests.java

@@ -3,9 +3,9 @@ package org.springframework.gradle.github.milestones;
 import okhttp3.mockwebserver.MockResponse;
 import okhttp3.mockwebserver.MockWebServer;
 import okhttp3.mockwebserver.RecordedRequest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.util.concurrent.TimeUnit;
 
@@ -22,7 +22,7 @@ public class GitHubMilestoneApiTests {
 
 	private String baseUrl;
 
-	@Before
+	@BeforeEach
 	public void setup() throws Exception {
 		this.server = new MockWebServer();
 		this.server.start();
@@ -31,7 +31,7 @@ public class GitHubMilestoneApiTests {
 		this.github.setBaseUrl(this.baseUrl);
 	}
 
-	@After
+	@AfterEach
 	public void cleanup() throws Exception {
 		this.server.shutdown();
 	}

+ 1 - 2
buildSrc/src/test/java/org/springframework/security/convention/versions/DependencyExcludesTests.java

@@ -20,10 +20,9 @@ import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentS
 import org.gradle.api.Action;
 import org.gradle.api.artifacts.ComponentSelection;
 import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.util.Collections;
-import java.util.List;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.BDDMockito.given;

+ 1 - 1
buildSrc/src/test/java/org/springframework/security/convention/versions/TransitiveDependencyLookupUtilsTest.java

@@ -17,7 +17,7 @@
 package org.springframework.security.convention.versions;
 
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;