@@ -2,59 +2,51 @@ package io.fuchs.gradle.collisiondetector.testkit
2
2
3
3
import org.gradle.testkit.runner.GradleRunner
4
4
import org.gradle.testkit.runner.TaskOutcome
5
- import org.junit.Assert .assertEquals
6
- import org.junit.Rule
7
- import org.junit.Test
8
- import org.junit.rules.TemporaryFolder
5
+ import org.junit.jupiter.api.Assertions .assertEquals
6
+ import org.junit.jupiter.api.Test
7
+ import org.junit.jupiter.api.io.TempDir
8
+ import java.nio.file.Path
9
9
10
10
class CollisionDetectorPluginTest {
11
11
12
- @get:Rule
13
- val temporaryFolder = TemporaryFolder ()
14
-
15
-
16
12
@Test
17
- fun `plugin applies without error` () {
18
- copyBuildFileToTempDir(" apply_plugin_only.gradle" )
13
+ fun `plugin applies without error` (@TempDir tempDir : Path ) {
14
+ copyBuildFileToTempDir(" apply_plugin_only.gradle" , tempDir )
19
15
20
16
GradleRunner .create()
21
- .withProjectDir(temporaryFolder.root)
22
- .withTestKitDir(temporaryFolder.newFolder())
17
+ .withProjectDir(tempDir.toFile())
23
18
.withPluginClasspath()
24
19
.build()
25
20
}
26
21
27
22
@Test
28
- fun `plugin applies without error on minimal supported Gradle version` () {
29
- copyBuildFileToTempDir(" apply_plugin_only.gradle" )
23
+ fun `plugin applies without error on minimal supported Gradle version` (@TempDir tempDir : Path ) {
24
+ copyBuildFileToTempDir(" apply_plugin_only.gradle" , tempDir )
30
25
31
26
GradleRunner .create()
32
- .withProjectDir(temporaryFolder.root)
33
- .withTestKitDir(temporaryFolder.newFolder())
27
+ .withProjectDir(tempDir.toFile())
34
28
.withPluginClasspath()
35
29
.withGradleVersion(" 6.6.1" )
36
30
.build()
37
31
}
38
32
39
33
@Test
40
- fun `task is compatible with configuration cache` () {
41
- copyBuildFileToTempDir(" apply_plugin_only.gradle" )
34
+ fun `task is compatible with configuration cache` (@TempDir tempDir : Path ) {
35
+ copyBuildFileToTempDir(" apply_plugin_only.gradle" , tempDir )
42
36
43
37
GradleRunner .create()
44
- .withProjectDir(temporaryFolder.root)
45
- .withTestKitDir(temporaryFolder.newFolder())
38
+ .withProjectDir(tempDir.toFile())
46
39
.withPluginClasspath()
47
40
.withArguments(" :detectCollisions" , " --configuration-cache" )
48
41
.build()
49
42
}
50
43
51
44
@Test
52
- fun `task detects no collision` () {
53
- copyBuildFileToTempDir(" apply_plugin_only.gradle" )
45
+ fun `task detects no collision` (@TempDir tempDir : Path ) {
46
+ copyBuildFileToTempDir(" apply_plugin_only.gradle" , tempDir )
54
47
55
48
val buildResult = GradleRunner .create()
56
- .withProjectDir(temporaryFolder.root)
57
- .withTestKitDir(temporaryFolder.newFolder())
49
+ .withProjectDir(tempDir.toFile())
58
50
.withPluginClasspath()
59
51
.withArguments(" :detectCollisions" )
60
52
.build()
@@ -64,12 +56,11 @@ class CollisionDetectorPluginTest {
64
56
}
65
57
66
58
@Test
67
- fun `detects collisions and fails` () {
68
- copyBuildFileToTempDir(" found_collisions.gradle" )
59
+ fun `detects collisions and fails` (@TempDir tempDir : Path ) {
60
+ copyBuildFileToTempDir(" found_collisions.gradle" , tempDir )
69
61
70
62
val buildResult = GradleRunner .create()
71
- .withProjectDir(temporaryFolder.root)
72
- .withTestKitDir(temporaryFolder.newFolder())
63
+ .withProjectDir(tempDir.toFile())
73
64
.withPluginClasspath()
74
65
.withArguments(" :detectCollisions" )
75
66
.buildAndFail()
@@ -79,12 +70,11 @@ class CollisionDetectorPluginTest {
79
70
}
80
71
81
72
@Test
82
- fun `all collisions are ignored` () {
83
- copyBuildFileToTempDir(" ignored_collisions.gradle" )
73
+ fun `all collisions are ignored` (@TempDir tempDir : Path ) {
74
+ copyBuildFileToTempDir(" ignored_collisions.gradle" , tempDir )
84
75
85
76
val buildResult = GradleRunner .create()
86
- .withProjectDir(temporaryFolder.root)
87
- .withTestKitDir(temporaryFolder.newFolder())
77
+ .withProjectDir(tempDir.toFile())
88
78
.withPluginClasspath()
89
79
.withArguments(" :detectCollisions" )
90
80
.build()
@@ -93,11 +83,11 @@ class CollisionDetectorPluginTest {
93
83
assertEquals(TaskOutcome .SUCCESS , detectCollisionsTask?.outcome)
94
84
}
95
85
96
- private fun copyBuildFileToTempDir (buildFile : String ) {
97
- val file = temporaryFolder.newFile (" build.gradle" )
86
+ private fun copyBuildFileToTempDir (buildFile : String , tempDir : Path ) {
87
+ val file = tempDir.resolve (" build.gradle" ).toFile( )
98
88
ClassLoader .getSystemResourceAsStream(buildFile).use { inputStream ->
99
89
file.outputStream().use { inputStream.copyTo(it) }
100
90
}
101
91
}
102
92
103
- }
93
+ }
0 commit comments