Skip to content

Commit babb94c

Browse files
committed
Migrate spring-boot-gradle-plugin's tests to JUnit 5
Closes gh-16959
1 parent 5e62faf commit babb94c

35 files changed

+571
-542
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jar {
3636
}
3737

3838
test {
39+
useJUnitPlatform()
3940
testLogging {
4041
events "passed", "skipped", "failed"
4142
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public void apply(Project project) {
8484
}
8585

8686
private void verifyGradleVersion() {
87-
if (GradleVersion.current().compareTo(GradleVersion.version("4.4")) < 0) {
88-
throw new GradleException("Spring Boot plugin requires Gradle 4.4 or later."
87+
if (GradleVersion.current().compareTo(GradleVersion.version("4.10")) < 0) {
88+
throw new GradleException("Spring Boot plugin requires Gradle 4.10 or later."
8989
+ " The current version is " + GradleVersion.current());
9090
}
9191
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/GettingStartedDocumentationTests.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,11 +16,10 @@
1616

1717
package org.springframework.boot.gradle.docs;
1818

19-
import org.junit.Rule;
20-
import org.junit.Test;
21-
import org.junit.runner.RunWith;
19+
import org.junit.jupiter.api.TestTemplate;
20+
import org.junit.jupiter.api.extension.ExtendWith;
2221

23-
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
22+
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
2423
import org.springframework.boot.gradle.testkit.GradleBuild;
2524

2625
/**
@@ -29,16 +28,15 @@
2928
* @author Andy Wilkinson
3029
* @author Jean-Baptiste Nizet
3130
*/
32-
@RunWith(GradleMultiDslSuite.class)
31+
@ExtendWith(GradleMultiDslExtension.class)
3332
public class GettingStartedDocumentationTests {
3433

35-
@Rule
36-
public GradleBuild gradleBuild;
34+
GradleBuild gradleBuild;
3735

3836
// NOTE: We can't run any `apply-plugin` tests because during a release the
3937
// jar won't be there
4038

41-
@Test
39+
@TestTemplate
4240
public void typicalPluginsAppliesExceptedPlugins() {
4341
this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins")
4442
.build("verify");

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/IntegratingWithActuatorDocumentationTests.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,11 +21,10 @@
2121
import java.io.IOException;
2222
import java.util.Properties;
2323

24-
import org.junit.Rule;
25-
import org.junit.Test;
26-
import org.junit.runner.RunWith;
24+
import org.junit.jupiter.api.TestTemplate;
25+
import org.junit.jupiter.api.extension.ExtendWith;
2726

28-
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
27+
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
2928
import org.springframework.boot.gradle.testkit.GradleBuild;
3029

3130
import static org.assertj.core.api.Assertions.assertThat;
@@ -36,13 +35,12 @@
3635
* @author Andy Wilkinson
3736
* @author Jean-Baptiste Nizet
3837
*/
39-
@RunWith(GradleMultiDslSuite.class)
38+
@ExtendWith(GradleMultiDslExtension.class)
4039
public class IntegratingWithActuatorDocumentationTests {
4140

42-
@Rule
43-
public GradleBuild gradleBuild;
41+
GradleBuild gradleBuild;
4442

45-
@Test
43+
@TestTemplate
4644
public void basicBuildInfo() throws IOException {
4745
this.gradleBuild
4846
.script("src/main/gradle/integrating-with-actuator/build-info-basic")
@@ -51,7 +49,7 @@ public void basicBuildInfo() throws IOException {
5149
"build/resources/main/META-INF/build-info.properties")).isFile();
5250
}
5351

54-
@Test
52+
@TestTemplate
5553
public void buildInfoCustomValues() throws IOException {
5654
this.gradleBuild.script(
5755
"src/main/gradle/integrating-with-actuator/build-info-custom-values")
@@ -66,7 +64,7 @@ public void buildInfoCustomValues() throws IOException {
6664
assertThat(properties).containsEntry("build.name", "Example application");
6765
}
6866

69-
@Test
67+
@TestTemplate
7068
public void buildInfoAdditional() throws IOException {
7169
this.gradleBuild
7270
.script("src/main/gradle/integrating-with-actuator/build-info-additional")

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,11 +17,10 @@
1717
package org.springframework.boot.gradle.docs;
1818

1919
import org.junit.Assume;
20-
import org.junit.Rule;
21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
20+
import org.junit.jupiter.api.TestTemplate;
21+
import org.junit.jupiter.api.extension.ExtendWith;
2322

24-
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
23+
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
2524
import org.springframework.boot.gradle.testkit.Dsl;
2625
import org.springframework.boot.gradle.testkit.GradleBuild;
2726

@@ -33,34 +32,33 @@
3332
* @author Andy Wilkinson
3433
* @author Jean-Baptiste Nizet
3534
*/
36-
@RunWith(GradleMultiDslSuite.class)
35+
@ExtendWith(GradleMultiDslExtension.class)
3736
public class ManagingDependenciesDocumentationTests {
3837

39-
@Rule
40-
public GradleBuild gradleBuild;
38+
GradleBuild gradleBuild;
4139

42-
@Test
40+
@TestTemplate
4341
public void dependenciesExampleEvaluatesSuccessfully() {
4442
this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies")
4543
.build();
4644
}
4745

48-
@Test
46+
@TestTemplate
4947
public void customManagedVersions() {
5048
assertThat(this.gradleBuild
5149
.script("src/main/gradle/managing-dependencies/custom-version")
5250
.build("slf4jVersion").getOutput()).contains("1.7.20");
5351
}
5452

55-
@Test
53+
@TestTemplate
5654
public void dependencyManagementInIsolation() {
5755
assertThat(this.gradleBuild
5856
.script("src/main/gradle/managing-dependencies/configure-bom")
5957
.build("dependencyManagement").getOutput())
6058
.contains("org.springframework.boot:spring-boot-starter ");
6159
}
6260

63-
@Test
61+
@TestTemplate
6462
public void dependencyManagementInIsolationWithPluginsBlock() {
6563
Assume.assumeTrue(this.gradleBuild.getDsl() == Dsl.KOTLIN);
6664
assertThat(this.gradleBuild.script(

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@
2727
import java.util.jar.Manifest;
2828
import java.util.zip.ZipEntry;
2929

30-
import org.junit.Rule;
31-
import org.junit.Test;
32-
import org.junit.runner.RunWith;
30+
import org.junit.jupiter.api.TestTemplate;
31+
import org.junit.jupiter.api.extension.ExtendWith;
3332

34-
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
35-
import org.springframework.boot.gradle.testkit.Dsl;
33+
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
3634
import org.springframework.boot.gradle.testkit.GradleBuild;
3735
import org.springframework.util.FileCopyUtils;
3836

@@ -44,21 +42,18 @@
4442
* @author Andy Wilkinson
4543
* @author Jean-Baptiste Nizet
4644
*/
47-
@RunWith(GradleMultiDslSuite.class)
45+
@ExtendWith(GradleMultiDslExtension.class)
4846
public class PackagingDocumentationTests {
4947

50-
@Rule
51-
public GradleBuild gradleBuild;
48+
GradleBuild gradleBuild;
5249

53-
public Dsl dsl;
54-
55-
@Test
50+
@TestTemplate
5651
public void warContainerDependencyEvaluatesSuccessfully() {
5752
this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency")
5853
.build();
5954
}
6055

61-
@Test
56+
@TestTemplate
6257
public void bootJarMainClass() throws IOException {
6358
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-main-class")
6459
.build("bootJar");
@@ -71,7 +66,7 @@ public void bootJarMainClass() throws IOException {
7166
}
7267
}
7368

74-
@Test
69+
@TestTemplate
7570
public void bootJarManifestMainClass() throws IOException {
7671
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class")
7772
.build("bootJar");
@@ -84,7 +79,7 @@ public void bootJarManifestMainClass() throws IOException {
8479
}
8580
}
8681

87-
@Test
82+
@TestTemplate
8883
public void applicationPluginMainClass() throws IOException {
8984
this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class")
9085
.build("bootJar");
@@ -97,7 +92,7 @@ public void applicationPluginMainClass() throws IOException {
9792
}
9893
}
9994

100-
@Test
95+
@TestTemplate
10196
public void springBootDslMainClass() throws IOException {
10297
this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class")
10398
.build("bootJar");
@@ -110,7 +105,7 @@ public void springBootDslMainClass() throws IOException {
110105
}
111106
}
112107

113-
@Test
108+
@TestTemplate
114109
public void bootWarIncludeDevtools() throws IOException {
115110
jarFile(new File(this.gradleBuild.getProjectDir(),
116111
"spring-boot-devtools-1.2.3.RELEASE.jar"));
@@ -125,7 +120,7 @@ public void bootWarIncludeDevtools() throws IOException {
125120
}
126121
}
127122

128-
@Test
123+
@TestTemplate
129124
public void bootJarRequiresUnpack() throws IOException {
130125
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack")
131126
.build("bootJar");
@@ -139,7 +134,7 @@ public void bootJarRequiresUnpack() throws IOException {
139134
}
140135
}
141136

142-
@Test
137+
@TestTemplate
143138
public void bootJarIncludeLaunchScript() throws IOException {
144139
this.gradleBuild
145140
.script("src/main/gradle/packaging/boot-jar-include-launch-script")
@@ -151,7 +146,7 @@ public void bootJarIncludeLaunchScript() throws IOException {
151146
.startsWith("#!/bin/bash");
152147
}
153148

154-
@Test
149+
@TestTemplate
155150
public void bootJarLaunchScriptProperties() throws IOException {
156151
this.gradleBuild
157152
.script("src/main/gradle/packaging/boot-jar-launch-script-properties")
@@ -163,7 +158,7 @@ public void bootJarLaunchScriptProperties() throws IOException {
163158
.contains("example-app.log");
164159
}
165160

166-
@Test
161+
@TestTemplate
167162
public void bootJarCustomLaunchScript() throws IOException {
168163
File customScriptFile = new File(this.gradleBuild.getProjectDir(),
169164
"src/custom.script");
@@ -177,7 +172,7 @@ public void bootJarCustomLaunchScript() throws IOException {
177172
assertThat(FileCopyUtils.copyToString(new FileReader(file))).startsWith("custom");
178173
}
179174

180-
@Test
175+
@TestTemplate
181176
public void bootWarPropertiesLauncher() throws IOException {
182177
this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher")
183178
.build("bootWar");
@@ -190,7 +185,7 @@ public void bootWarPropertiesLauncher() throws IOException {
190185
}
191186
}
192187

193-
@Test
188+
@TestTemplate
194189
public void bootJarAndJar() {
195190
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-and-jar")
196191
.build("assemble");

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PublishingDocumentationTests.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,11 +18,10 @@
1818

1919
import java.io.IOException;
2020

21-
import org.junit.Rule;
22-
import org.junit.Test;
23-
import org.junit.runner.RunWith;
21+
import org.junit.jupiter.api.TestTemplate;
22+
import org.junit.jupiter.api.extension.ExtendWith;
2423

25-
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
24+
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
2625
import org.springframework.boot.gradle.testkit.GradleBuild;
2726

2827
import static org.assertj.core.api.Assertions.assertThat;
@@ -33,20 +32,19 @@
3332
* @author Andy Wilkinson
3433
* @author Jean-Baptiste Nizet
3534
*/
36-
@RunWith(GradleMultiDslSuite.class)
35+
@ExtendWith(GradleMultiDslExtension.class)
3736
public class PublishingDocumentationTests {
3837

39-
@Rule
40-
public GradleBuild gradleBuild;
38+
GradleBuild gradleBuild;
4139

42-
@Test
40+
@TestTemplate
4341
public void mavenUpload() throws IOException {
4442
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven")
4543
.build("deployerRepository").getOutput())
4644
.contains("https://repo.example.com");
4745
}
4846

49-
@Test
47+
@TestTemplate
5048
public void mavenPublish() throws IOException {
5149
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven-publish")
5250
.build("publishingConfiguration").getOutput())

0 commit comments

Comments
 (0)