From b62d4682fec7314796c65165de1850214944ba72 Mon Sep 17 00:00:00 2001 From: Esoteric Enderman Date: Sun, 3 Nov 2024 00:36:14 +0000 Subject: [PATCH] Add tests for resource saving method --- .../utility/resource/ResourceUtilityTest.kt | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/src/test/kotlin/foundation/esoteric/utility/resource/ResourceUtilityTest.kt b/lib/src/test/kotlin/foundation/esoteric/utility/resource/ResourceUtilityTest.kt index 368226a..4988712 100644 --- a/lib/src/test/kotlin/foundation/esoteric/utility/resource/ResourceUtilityTest.kt +++ b/lib/src/test/kotlin/foundation/esoteric/utility/resource/ResourceUtilityTest.kt @@ -1,12 +1,20 @@ package foundation.esoteric.utility.resource +import org.apache.commons.io.FileUtils import org.junit.jupiter.api.assertThrows +import java.io.File import java.nio.file.Path import kotlin.io.path.Path -import kotlin.test.Test -import kotlin.test.assertEquals +import kotlin.test.* class ResourceUtilityTest { + + private var run = File("run") + + @BeforeTest fun createRunDirectory() { + run.mkdir() + } + @Test fun resourcesListIsCorrect() { val resourcePaths = Path("resource").resourceFilePaths() @@ -18,4 +26,19 @@ class ResourceUtilityTest { Path("some random path that does not exist").resourceFilePaths() } } + + @Test fun savingResourcesWorks() { + val saveLocation = File(run, "Test File.txt") + val resourcePath = Path("resource/ResourceUtilityTest/Test File.txt") + resourcePath.saveResource(saveLocation.toPath()) + + assertTrue(saveLocation.exists()) + assertTrue(saveLocation.isFile) + assertFalse(saveLocation.isDirectory) + assertEquals("This file is used to test the resource utility.", saveLocation.readText().trimEnd('\n', '\r')) + } + + @AfterTest fun deleteRunDirectory() { + FileUtils.deleteDirectory(run) + } }