@@ -7,55 +7,61 @@ import org.gradle.api.Project
77import org.gradle.api.internal.project.DefaultProject
88import org.gradle.api.tasks.TaskExecutionException
99import org.gradle.testfixtures.ProjectBuilder
10- import org.junit.jupiter.api.Assertions.assertThrows
11- import org.junit.jupiter.api.Assertions.assertTrue
12- import org.junit.jupiter.api.BeforeEach
13- import org.junit.jupiter.api.Test
14- import org.junit.jupiter.api.io.TempDir
10+ import kotlin.io.path.createTempDirectory
11+ import kotlin.test.BeforeTest
12+ import kotlin.test.AfterTest
13+ import kotlin.test.Test
14+ import kotlin.test.assertTrue
15+ import kotlin.test.assertFailsWith
1516import java.io.File
1617
1718class ZipModuleTests : BaseTest () {
1819
19- @TempDir
20- lateinit var testProjectDir: File
20+ private lateinit var tempDir: File
2121 private lateinit var project: Project
2222 private lateinit var task: ZipModule
2323
24- @BeforeEach
24+ @BeforeTest
2525 fun setup () {
26- project = ProjectBuilder .builder().withProjectDir(testProjectDir).build() as DefaultProject
26+ tempDir = createTempDirectory().toFile()
27+ project = ProjectBuilder .builder().withProjectDir(tempDir).build() as DefaultProject
2728 task = project.tasks.create(" testTask" , ZipModule ::class .java)
2829
29- // Set up the task properties with the test directory
30- task.content.set(project.objects.directoryProperty().fileValue(File (testProjectDir, " content" )))
31- task.unsignedModule.set(project.objects.fileProperty().fileValue(File (testProjectDir, " output.modl" )))
30+ // Set up the task properties with the temp directory
31+ task.content.set(project.objects.directoryProperty().fileValue(File (tempDir, " content" )))
32+ task.unsignedModule.set(project.objects.fileProperty().fileValue(File (tempDir, " output.modl" )))
33+ }
34+
35+ @AfterTest
36+ fun cleanup () {
37+ tempDir.deleteRecursively()
3238 }
3339
3440 @Test
3541 fun `task succeeds when no duplicate jars exist` () {
3642 // Arrange
37- val contentDir = File (testProjectDir, " content" ).apply { mkdirs() }
43+ val contentDir = task. content.asFile.get( ).apply { mkdirs() }
3844 File (contentDir, " my-lib-1.0.jar" ).createNewFile()
3945 File (contentDir, " another-lib-2.0.jar" ).createNewFile()
4046
41- // Act & Assert : The task should not throw an exception
47+ // Act: The task should not throw an exception
4248 task.execute()
4349 }
4450
4551 @Test
4652 fun `task fails when duplicate jars with different versions exist` () {
4753 // Arrange
48- val contentDir = File (testProjectDir, " content" ).apply { mkdirs() }
54+ val contentDir = task. content.asFile.get( ).apply { mkdirs() }
4955 File (contentDir, " my-lib-1.0.jar" ).createNewFile()
5056 File (contentDir, " my-lib-2.0.jar" ).createNewFile() // This is the duplicate
5157
52- // Act & Assert: The task should throw a TaskExecutionException
53- val exception = assertThrows( TaskExecutionException :: class .java) {
58+ // Act & Assert: The task should throw a IllegalArgumentException
59+ val exception = assertFailsWith< IllegalArgumentException > {
5460 task.execute()
5561 }
5662
5763 // Verify the exception message
58- val expectedMessage = " Jar with 'my-lib' has multiple versions presented "
64+ val expectedMessage = " Library 'my-lib' exists in multiple versions"
5965 assertTrue(exception.message!! .contains(expectedMessage))
6066 }
6167
0 commit comments