mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-18 17:48:14 +08:00
Configure JUnit platform with Spring Boot 2.2+
Closes gh-904
This commit is contained in:
@@ -223,6 +223,13 @@ public class GradleProjectGenerationConfiguration {
|
||||
projectDescription.getPlatformVersion().toString());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnPlatformVersion("2.2.0.M3")
|
||||
public BuildCustomizer<GradleBuild> testTaskContributor() {
|
||||
return (build) -> build.customizeTask("test",
|
||||
(test) -> test.invoke("useJUnitPlatform"));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GradleAnnotationProcessorScopeBuildCustomizer gradleAnnotationProcessorScopeBuildCustomizer() {
|
||||
return new GradleAnnotationProcessorScopeBuildCustomizer();
|
||||
@@ -264,6 +271,13 @@ public class GradleProjectGenerationConfiguration {
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnPlatformVersion("2.2.0.M3")
|
||||
public BuildCustomizer<GradleBuild> testTaskContributor() {
|
||||
return (build) -> build.customizeTasksWithType("Test",
|
||||
(test) -> test.invoke("useJUnitPlatform"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -55,6 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Tests for {@link GradleProjectGenerationConfiguration} with Kotlin DSL build system.
|
||||
*
|
||||
* @author Jean-Baptiste Nizet
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class GradleKtsProjectGenerationConfigurationTests {
|
||||
|
||||
@@ -155,6 +156,32 @@ class GradleKtsProjectGenerationConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void junitPlatformIsConfiguredWithCompatibleVersion() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.2.4.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("build.gradle.kts");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle.kts");
|
||||
assertThat(lines).containsSequence("tasks.withType<Test> {",
|
||||
" useJUnitPlatform()", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void junitPlatformIsNotConfiguredWithIncompatibleVersion() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.4.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("build.gradle.kts");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle.kts");
|
||||
assertThat(lines).doesNotContainSequence("tasks.withType<Test> {",
|
||||
" useJUnitPlatform()", "}");
|
||||
}
|
||||
|
||||
private static String[] readAllLines(Path file) throws IOException {
|
||||
String content = StreamUtils.copyToString(
|
||||
new FileInputStream(new File(file.toString())), StandardCharsets.UTF_8);
|
||||
|
@@ -154,6 +154,30 @@ class GradleProjectGenerationConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void junitPlatformIsConfiguredWithCompatibleVersion() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.2.4.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("build.gradle");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle");
|
||||
assertThat(lines).containsSequence("test {", " useJUnitPlatform()", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void junitPlatformIsNotConfiguredWithIncompatibleVersion() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.4.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("build.gradle");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle");
|
||||
assertThat(lines).doesNotContainSequence("test {", " useJUnitPlatform()", "}");
|
||||
}
|
||||
|
||||
static Stream<Arguments> annotationProcessorScopeBuildParameters() {
|
||||
return Stream.of(Arguments.arguments("1.5.17.RELEASE", false),
|
||||
Arguments.arguments("2.0.6.RELEASE", true),
|
||||
|
Reference in New Issue
Block a user