From 999f53c0fcfa392232d2e0104b412ef2b6ce95e7 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Wed, 5 Jun 2024 09:20:58 +0200 Subject: [PATCH] Add kotlin-test-junit5 to Kotlin projects Closes gh-1297 --- .../kotlin/KotlinDependenciesConfigurer.java | 4 ++++ .../KotlinDependenciesConfigurerTests.java | 16 ++++++++++++++-- .../gradle/kotlin-java11-build.gradle.gen | 1 + .../gradle/kotlin-java11-build.gradle.kts.gen | 1 + .../project/kotlin/standard/build.gradle.gen | 1 + .../project/kotlin/standard/build.gradle.kts.gen | 1 + .../project/kotlin/standard/pom.xml.gen | 5 +++++ .../project/kotlin/standard/war-build.gradle.gen | 1 + .../kotlin/standard/war-build.gradle.kts.gen | 1 + .../project/kotlin/standard/war-pom.xml.gen | 5 +++++ .../project/maven/kotlin-java11-pom.xml.gen | 5 +++++ ...jectGenerationControllerIntegrationTests.java | 2 +- 12 files changed, 40 insertions(+), 3 deletions(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurer.java index 3141c55459..3711ed48b1 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurer.java @@ -26,6 +26,7 @@ * Kotlin. * * @author Andy Wilkinson + * @author Moritz Halbritter */ class KotlinDependenciesConfigurer implements BuildCustomizer { @@ -34,6 +35,9 @@ public void customize(Build build) { build.dependencies() .add("kotlin-reflect", Dependency.withCoordinates("org.jetbrains.kotlin", "kotlin-reflect") .scope(DependencyScope.COMPILE)); + build.dependencies() + .add("kotlin-test-junit5", Dependency.withCoordinates("org.jetbrains.kotlin", "kotlin-test-junit5") + .scope(DependencyScope.TEST_COMPILE)); } } diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurerTests.java index 856687d3aa..3128ee88b3 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurerTests.java @@ -17,6 +17,7 @@ package io.spring.initializr.generator.spring.code.kotlin; import io.spring.initializr.generator.buildsystem.Dependency; +import io.spring.initializr.generator.buildsystem.DependencyScope; import io.spring.initializr.generator.buildsystem.gradle.GradleBuild; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import org.junit.jupiter.api.Test; @@ -27,6 +28,7 @@ * Tests for {@link KotlinDependenciesConfigurer}. * * @author Andy Wilkinson + * @author Moritz Halbritter */ class KotlinDependenciesConfigurerTests { @@ -34,22 +36,32 @@ class KotlinDependenciesConfigurerTests { void configuresDependenciesForGradleBuild() { GradleBuild build = new GradleBuild(); new KotlinDependenciesConfigurer().customize(build); - assertThat(build.dependencies().ids()).containsOnly("kotlin-reflect"); + assertThat(build.dependencies().ids()).containsOnly("kotlin-reflect", "kotlin-test-junit5"); Dependency kotlinReflect = build.dependencies().get("kotlin-reflect"); assertThat(kotlinReflect.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(kotlinReflect.getArtifactId()).isEqualTo("kotlin-reflect"); assertThat(kotlinReflect.getVersion()).isNull(); + Dependency kotlinTest = build.dependencies().get("kotlin-test-junit5"); + assertThat(kotlinTest.getGroupId()).isEqualTo("org.jetbrains.kotlin"); + assertThat(kotlinTest.getArtifactId()).isEqualTo("kotlin-test-junit5"); + assertThat(kotlinTest.getScope()).isEqualTo(DependencyScope.TEST_COMPILE); + assertThat(kotlinTest.getVersion()).isNull(); } @Test void configuresDependenciesForMavenBuild() { MavenBuild build = new MavenBuild(); new KotlinDependenciesConfigurer().customize(build); - assertThat(build.dependencies().ids()).containsOnly("kotlin-reflect"); + assertThat(build.dependencies().ids()).containsOnly("kotlin-reflect", "kotlin-test-junit5"); Dependency kotlinReflect = build.dependencies().get("kotlin-reflect"); assertThat(kotlinReflect.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(kotlinReflect.getArtifactId()).isEqualTo("kotlin-reflect"); assertThat(kotlinReflect.getVersion()).isNull(); + Dependency kotlinTest = build.dependencies().get("kotlin-test-junit5"); + assertThat(kotlinTest.getGroupId()).isEqualTo("org.jetbrains.kotlin"); + assertThat(kotlinTest.getArtifactId()).isEqualTo("kotlin-test-junit5"); + assertThat(kotlinTest.getScope()).isEqualTo(DependencyScope.TEST_COMPILE); + assertThat(kotlinTest.getVersion()).isNull(); } } diff --git a/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.gen b/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.gen index 5ddfe8944e..d79441cafa 100644 --- a/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.gen +++ b/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.gen @@ -22,6 +22,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.jetbrains.kotlin:kotlin-reflect' testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } diff --git a/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.kts.gen b/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.kts.gen index 2b8c563836..604074ebed 100644 --- a/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.kts.gen +++ b/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.kts.gen @@ -22,6 +22,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter") implementation("org.jetbrains.kotlin:kotlin-reflect") testImplementation("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.gen b/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.gen index c8d1ce01ea..fff4ec8a43 100644 --- a/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.gen +++ b/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.gen @@ -22,6 +22,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.jetbrains.kotlin:kotlin-reflect' testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } diff --git a/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.kts.gen b/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.kts.gen index b7fd422b48..27e33a9831 100644 --- a/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.kts.gen +++ b/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.kts.gen @@ -22,6 +22,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter") implementation("org.jetbrains.kotlin:kotlin-reflect") testImplementation("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/initializr-generator-spring/src/test/resources/project/kotlin/standard/pom.xml.gen b/initializr-generator-spring/src/test/resources/project/kotlin/standard/pom.xml.gen index 1d6f2182c6..5b355f4bb8 100644 --- a/initializr-generator-spring/src/test/resources/project/kotlin/standard/pom.xml.gen +++ b/initializr-generator-spring/src/test/resources/project/kotlin/standard/pom.xml.gen @@ -38,6 +38,11 @@ spring-boot-starter-test test + + org.jetbrains.kotlin + kotlin-test-junit5 + test + diff --git a/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.gen b/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.gen index b8c179e82c..2573efc78d 100644 --- a/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.gen +++ b/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.gen @@ -24,6 +24,7 @@ dependencies { implementation 'org.jetbrains.kotlin:kotlin-reflect' providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } diff --git a/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.kts.gen b/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.kts.gen index b34f4e883b..9c3d3ae95f 100644 --- a/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.kts.gen +++ b/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.kts.gen @@ -24,6 +24,7 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-reflect") providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") testImplementation("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-pom.xml.gen b/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-pom.xml.gen index 7419db3e6f..8c4f5b0abf 100644 --- a/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-pom.xml.gen +++ b/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-pom.xml.gen @@ -44,6 +44,11 @@ spring-boot-starter-test test + + org.jetbrains.kotlin + kotlin-test-junit5 + test + diff --git a/initializr-generator-spring/src/test/resources/project/maven/kotlin-java11-pom.xml.gen b/initializr-generator-spring/src/test/resources/project/maven/kotlin-java11-pom.xml.gen index 1fc668faf9..6c2f432cbf 100644 --- a/initializr-generator-spring/src/test/resources/project/maven/kotlin-java11-pom.xml.gen +++ b/initializr-generator-spring/src/test/resources/project/maven/kotlin-java11-pom.xml.gen @@ -38,6 +38,11 @@ spring-boot-starter-test test + + org.jetbrains.kotlin + kotlin-test-junit5 + test + diff --git a/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java b/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java index 8d74b5a31f..8786a9f165 100755 --- a/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java +++ b/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java @@ -147,7 +147,7 @@ void kotlinRange() { assertThat(project).containsFiles("src/main/kotlin/com/example/demo/DemoApplication.kt", "src/test/kotlin/com/example/demo/DemoApplicationTests.kt", "src/main/resources/application.properties"); - assertThat(project).mavenBuild().hasDependenciesSize(4).hasProperty("kotlin.version", "1.4.31"); + assertThat(project).mavenBuild().hasDependenciesSize(5).hasProperty("kotlin.version", "1.4.31"); } @Test