Skip to content

Commit

Permalink
Add kotlin-test-junit5 to Kotlin projects
Browse files Browse the repository at this point in the history
Closes gh-1297
  • Loading branch information
mhalbritter committed Jun 5, 2024
1 parent be6fb64 commit 999f53c
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* Kotlin.
*
* @author Andy Wilkinson
* @author Moritz Halbritter
*/
class KotlinDependenciesConfigurer implements BuildCustomizer<Build> {

Expand All @@ -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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,29 +28,40 @@
* Tests for {@link KotlinDependenciesConfigurer}.
*
* @author Andy Wilkinson
* @author Moritz Halbritter
*/
class KotlinDependenciesConfigurerTests {

@Test
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 999f53c

Please sign in to comment.