Skip to content

Commit

Permalink
Add tests for resource saving method
Browse files Browse the repository at this point in the history
  • Loading branch information
EsotericEnderman committed Nov 3, 2024
1 parent 2e10757 commit b62d468
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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()

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

0 comments on commit b62d468

Please sign in to comment.