Skip to content

Commit 0e11049

Browse files
committed
update to Junit 5
1 parent 82ec542 commit 0e11049

File tree

7 files changed

+66
-64
lines changed

7 files changed

+66
-64
lines changed

build.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,14 @@ subprojects {
146146
sign publishing.publications.mavenJava
147147
}
148148

149+
test {
150+
useJUnitPlatform()
151+
}
152+
149153
dependencies {
150154
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
151155

152-
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
156+
testImplementation "org.junit.jupiter:junit-jupiter:5.9.3"
153157
testImplementation "org.mockito:mockito-core:4.7.0"
154158
testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0"
155159
testImplementation "org.assertj:assertj-core:3.24.2"

core/src/test/kotlin/com/tschuchort/compiletesting/CompilerPluginsTest.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ package com.tschuchort.compiletesting
22

33
import org.assertj.core.api.Assertions
44
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
5-
import org.junit.Assert
6-
import org.junit.Test
5+
import org.junit.jupiter.api.Test
76
import org.mockito.Mockito
87
import javax.annotation.processing.AbstractProcessor
98
import javax.annotation.processing.RoundEnvironment
@@ -53,7 +52,7 @@ class CompilerPluginsTest {
5352

5453
override fun process(p0: MutableSet<out TypeElement>?, p1: RoundEnvironment?): Boolean {
5554
p1?.getElementsAnnotatedWith(ProcessElem::class.java)?.forEach {
56-
Assert.assertEquals("JSource", it?.simpleName.toString())
55+
Assertions.assertThat("JSource").isEqualTo(it?.simpleName.toString())
5756
}
5857
return false
5958
}

core/src/test/kotlin/com/tschuchort/compiletesting/JavacUtilsTest.kt

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
package com.tschuchort.compiletesting
22

3-
import org.junit.Assert.*
4-
import org.junit.Test
3+
import org.junit.jupiter.api.Assertions
4+
import org.junit.jupiter.api.Test
55

66
class JavacUtilsTest {
77

88
@Test
99
fun `Old version scheme less than 9 is parsed correctly`() {
10-
assertFalse(isJavac9OrLater("1.8.0"))
10+
Assertions.assertFalse(isJavac9OrLater("1.8.0"))
1111
}
1212

1313
@Test
1414
fun `Old version scheme greater equal 9 is parsed correctly`() {
15-
assertTrue(isJavac9OrLater("1.9.1"))
16-
assertTrue(isJavac9OrLater("1.11.0"))
15+
Assertions.assertTrue(isJavac9OrLater("1.9.1"))
16+
Assertions.assertTrue(isJavac9OrLater("1.11.0"))
1717
}
1818

1919
@Test
2020
fun `New version scheme less than 9 is parsed correctly`() {
21-
assertFalse(isJavac9OrLater("8.1.0.1"))
22-
assertFalse(isJavac9OrLater("8.1.0"))
23-
assertFalse(isJavac9OrLater("8.1"))
24-
assertFalse(isJavac9OrLater("8"))
21+
Assertions.assertFalse(isJavac9OrLater("8.1.0.1"))
22+
Assertions.assertFalse(isJavac9OrLater("8.1.0"))
23+
Assertions.assertFalse(isJavac9OrLater("8.1"))
24+
Assertions.assertFalse(isJavac9OrLater("8"))
2525
}
2626

2727
@Test
2828
fun `New version scheme greater equal 9 is parsed correctly`() {
29-
assertTrue(isJavac9OrLater("9.0.0.1"))
30-
assertTrue(isJavac9OrLater("9.0.0"))
31-
assertTrue(isJavac9OrLater("9.1.0"))
32-
assertTrue(isJavac9OrLater("9.1"))
33-
assertTrue(isJavac9OrLater("9"))
34-
assertTrue(isJavac9OrLater("12"))
29+
Assertions.assertTrue(isJavac9OrLater("9.0.0.1"))
30+
Assertions.assertTrue(isJavac9OrLater("9.0.0"))
31+
Assertions.assertTrue(isJavac9OrLater("9.1.0"))
32+
Assertions.assertTrue(isJavac9OrLater("9.1"))
33+
Assertions.assertTrue(isJavac9OrLater("9"))
34+
Assertions.assertTrue(isJavac9OrLater("12"))
3535
}
3636

3737
@Test
3838
fun `Old version scheme with extra info is parsed correctly`() {
39-
assertTrue(isJavac9OrLater("1.11.0-bla"))
39+
Assertions.assertTrue(isJavac9OrLater("1.11.0-bla"))
4040
}
4141

4242
@Test
4343
fun `Standard javac -version output is parsed correctly`() {
44-
assertEquals("1.8.0_252", parseVersionString("javac 1.8.0_252"))
44+
Assertions.assertEquals("1.8.0_252", parseVersionString("javac 1.8.0_252"))
4545
}
4646

4747
@Test
4848
fun `javac -version output with JAVA OPTIONS is parsed correctly`() {
49-
assertEquals(
49+
Assertions.assertEquals(
5050
"1.8.0_222",
5151
parseVersionString(
5252
"Picked up _JAVA_OPTIONS: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap javac 1.8.0_222"
@@ -56,7 +56,7 @@ class JavacUtilsTest {
5656

5757
@Test
5858
fun `Wrong javac -version output is returning null`() {
59-
assertNull(
59+
Assertions.assertNull(
6060
parseVersionString(
6161
"wrong javac"
6262
)

core/src/test/kotlin/com/tschuchort/compiletesting/KotlinCompilationTests.kt

+22-22
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ import org.assertj.core.api.Assertions.assertThat
66
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
77
import org.jetbrains.kotlin.compiler.plugin.CliOption
88
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
9-
import org.junit.Ignore
10-
import org.junit.Rule
11-
import org.junit.Test
12-
import org.junit.rules.TemporaryFolder
9+
import org.junit.jupiter.api.Disabled
10+
import org.junit.jupiter.api.Test
11+
import org.junit.jupiter.api.io.TempDir
1312
import java.io.ByteArrayOutputStream
1413
import java.io.File
1514
import java.nio.file.Files
1615
import javax.annotation.processing.AbstractProcessor
1716
import javax.annotation.processing.RoundEnvironment
1817
import javax.lang.model.element.TypeElement
1918
import org.mockito.kotlin.*
19+
import java.nio.file.Path
20+
import kotlin.io.path.createDirectory
21+
import kotlin.io.path.createFile
22+
import kotlin.io.path.writeText
2023

2124
@Suppress("MemberVisibilityCanBePrivate", "RemoveEmptyClassBody", "RedundantSemicolon", "RemoveEmptyPrimaryConstructor")
2225
class KotlinCompilationTests {
23-
@Rule @JvmField val temporaryFolder = TemporaryFolder()
2426

2527
val kotlinTestProc = KotlinTestProcessor()
2628
val javaTestProc = JavaTestProcessor()
@@ -78,35 +80,35 @@ class KotlinCompilationTests {
7880
}
7981

8082
@Test
81-
fun `runs with SourceFile from path`() {
82-
val sourceFile = temporaryFolder.newFile("KSource.kt").apply {
83+
fun `runs with SourceFile from path`(@TempDir tempDir: Path) {
84+
val sourceFile = tempDir.resolve("KSource.kt").createFile().apply {
8385
writeText("class KSource")
8486
}
8587

8688
val result = defaultCompilerConfig().apply {
87-
sources = listOf(SourceFile.fromPath(sourceFile))
89+
sources = listOf(SourceFile.fromPath(sourceFile.toFile()))
8890
}.compile()
8991

9092
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
9193
assertClassLoadable(result, "KSource")
9294
}
9395

9496
@Test
95-
fun `runs with SourceFile from paths with filename conflicts`() {
96-
temporaryFolder.newFolder("a")
97-
val sourceFileA = temporaryFolder.newFile("a/KSource.kt").apply {
97+
fun `runs with SourceFile from paths with filename conflicts`(@TempDir tempDir: Path) {
98+
tempDir.resolve("a").createDirectory()
99+
val sourceFileA = tempDir.resolve("a/KSource.kt").createFile().apply {
98100
writeText("package a\n\nclass KSource")
99101
}
100102

101-
temporaryFolder.newFolder("b")
102-
val sourceFileB = temporaryFolder.newFile("b/KSource.kt").apply {
103+
tempDir.resolve("b").createDirectory()
104+
val sourceFileB = tempDir.resolve("b/KSource.kt").createFile().apply {
103105
writeText("package b\n\nclass KSource")
104106
}
105107

106108
val result = defaultCompilerConfig().apply {
107109
sources = listOf(
108-
SourceFile.fromPath(sourceFileA),
109-
SourceFile.fromPath(sourceFileB))
110+
SourceFile.fromPath(sourceFileA.toFile()),
111+
SourceFile.fromPath(sourceFileB.toFile()))
110112
}.compile()
111113

112114
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
@@ -867,20 +869,19 @@ class KotlinCompilationTests {
867869
)
868870
}
869871

870-
@Ignore // Ignored because symlinks can't be created on Windows 7 without admin rights
872+
@Disabled // Ignored because symlinks can't be created on Windows 7 without admin rights
871873
@Test
872-
fun `java compilation runs in a sub-process when jdk is specified`() {
874+
fun `java compilation runs in a sub-process when jdk is specified`(@TempDir tempDir: Path) {
873875
val source = SourceFile.java("JSource.java",
874876
"""
875877
class JSource {}
876878
""".trimIndent())
877-
val fakeJdkHome = temporaryFolder.newFolder("jdk-copy")
878-
fakeJdkHome.mkdirs()
879-
Files.createLink(fakeJdkHome.resolve("bin").toPath(), processJdkHome.toPath())
879+
val fakeJdkHome = tempDir.resolve("jdk-copy").createDirectory()
880+
Files.createLink(fakeJdkHome.resolve("bin"), processJdkHome.toPath())
880881
val logsStream = ByteArrayOutputStream()
881882
val compiler = defaultCompilerConfig().apply {
882883
sources = listOf(source)
883-
jdkHome = fakeJdkHome
884+
jdkHome = fakeJdkHome.toFile()
884885
messageOutputStream = logsStream
885886
}
886887
val result = compiler.compile()
@@ -892,7 +893,6 @@ class KotlinCompilationTests {
892893
assertThat(logs).doesNotContain(
893894
"jdkHome is set to null, removing boot classpath from java compilation"
894895
)
895-
fakeJdkHome.delete()
896896
}
897897

898898
@Test

core/src/test/kotlin/com/tschuchort/compiletesting/KotlinJsCompilationTests.kt

+16-14
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ import org.assertj.core.api.Assertions.assertThat
66
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
77
import org.jetbrains.kotlin.compiler.plugin.CliOption
88
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
9-
import org.junit.Rule
10-
import org.junit.Test
11-
import org.junit.rules.TemporaryFolder
9+
import org.junit.jupiter.api.Test
10+
import org.junit.jupiter.api.io.TempDir
1211
import java.io.File
1312
import org.mockito.kotlin.*
13+
import java.nio.file.Path
14+
import kotlin.io.path.createDirectory
15+
import kotlin.io.path.createFile
16+
import kotlin.io.path.writeText
1417

1518
@Suppress("MemberVisibilityCanBePrivate")
1619
class KotlinJsCompilationTests {
17-
@Rule @JvmField val temporaryFolder = TemporaryFolder()
1820

1921
@Test
2022
fun `runs with only kotlin sources`() {
@@ -38,13 +40,13 @@ class KotlinJsCompilationTests {
3840
}
3941

4042
@Test
41-
fun `runs with SourceFile from path`() {
42-
val sourceFile = temporaryFolder.newFile("KSource.kt").apply {
43+
fun `runs with SourceFile from path`(@TempDir tempDir: Path) {
44+
val sourceFile = tempDir.resolve("KSource.kt").createFile().apply {
4345
writeText("class KSource")
4446
}
4547

4648
val result = defaultJsCompilerConfig().apply {
47-
sources = listOf(SourceFile.fromPath(sourceFile))
49+
sources = listOf(SourceFile.fromPath(sourceFile.toFile()))
4850
}.compile()
4951

5052
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
@@ -54,21 +56,21 @@ class KotlinJsCompilationTests {
5456
}
5557

5658
@Test
57-
fun `runs with SourceFile from paths with filename conflicts`() {
58-
temporaryFolder.newFolder("a")
59-
val sourceFileA = temporaryFolder.newFile("a/KSource.kt").apply {
59+
fun `runs with SourceFile from paths with filename conflicts`(@TempDir tempDir: Path) {
60+
tempDir.resolve("a").createDirectory()
61+
val sourceFileA = tempDir.resolve("a/KSource.kt").createFile().apply {
6062
writeText("package a\n\nclass KSource")
6163
}
6264

63-
temporaryFolder.newFolder("b")
64-
val sourceFileB = temporaryFolder.newFile("b/KSource.kt").apply {
65+
tempDir.resolve("b").createDirectory()
66+
val sourceFileB = tempDir.resolve("b/KSource.kt").createFile().apply {
6567
writeText("package b\n\nclass KSource")
6668
}
6769

6870
val result = defaultJsCompilerConfig().apply {
6971
sources = listOf(
70-
SourceFile.fromPath(sourceFileA),
71-
SourceFile.fromPath(sourceFileB))
72+
SourceFile.fromPath(sourceFileA.toFile()),
73+
SourceFile.fromPath(sourceFileB.toFile()))
7274
}.compile()
7375

7476
assertThat(result.exitCode).isEqualTo(ExitCode.OK)

core/src/test/kotlin/com/tschuchort/compiletesting/StreamUtilTests.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.tschuchort.compiletesting
22

33
import okio.Buffer
44
import org.assertj.core.api.Assertions
5-
import org.junit.Test
5+
import org.junit.jupiter.api.Test
66
import java.io.OutputStream
77
import java.io.PrintStream
88
import org.mockito.kotlin.mock

ksp/src/test/kotlin/com/tschuchort/compiletesting/KspTest.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration
66
import com.tschuchort.compiletesting.KotlinCompilation.ExitCode
77
import org.assertj.core.api.Assertions.assertThat
88
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
9-
import org.junit.Test
10-
import org.junit.runner.RunWith
11-
import org.junit.runners.JUnit4
9+
import org.junit.jupiter.api.Test
1210
import org.mockito.Mockito.`when`
1311
import java.util.concurrent.atomic.AtomicInteger
1412
import org.mockito.kotlin.any
1513
import org.mockito.kotlin.inOrder
1614
import org.mockito.kotlin.mock
1715

18-
@RunWith(JUnit4::class)
1916
@ExperimentalCompilerApi
2017
class KspTest {
2118
@Test

0 commit comments

Comments
 (0)