forked from StarOpenSource/Engine
Finalize FileAccess tests
This commit is contained in:
parent
c13eaead94
commit
bf449971e9
2 changed files with 421 additions and 36 deletions
|
@ -21,15 +21,15 @@
|
||||||
package de.staropensource.engine.base
|
package de.staropensource.engine.base
|
||||||
|
|
||||||
import de.staropensource.engine.base.exception.EngineInitializationFailureException
|
import de.staropensource.engine.base.exception.EngineInitializationFailureException
|
||||||
import de.staropensource.engine.base.implementable.ShutdownHandler
|
import org.junit.jupiter.api.Assertions.fail
|
||||||
import de.staropensource.engine.testing.TestBase
|
|
||||||
import org.junit.jupiter.api.Assertions.*
|
|
||||||
import org.junit.jupiter.api.MethodOrderer
|
import org.junit.jupiter.api.MethodOrderer
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.TestMethodOrder
|
import org.junit.jupiter.api.TestMethodOrder
|
||||||
|
|
||||||
@TestMethodOrder(MethodOrderer.MethodName::class)
|
@TestMethodOrder(MethodOrderer.MethodName::class)
|
||||||
class EngineTest : TestBase(autoManage = false) {
|
class EngineTest : TestBase(
|
||||||
|
autoManage = false
|
||||||
|
) {
|
||||||
@Test
|
@Test
|
||||||
fun initialize() {
|
fun initialize() {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -20,8 +20,9 @@
|
||||||
|
|
||||||
package de.staropensource.engine.base.utility
|
package de.staropensource.engine.base.utility
|
||||||
|
|
||||||
|
import de.staropensource.engine.base.Engine
|
||||||
|
import de.staropensource.engine.base.TestBase
|
||||||
import de.staropensource.engine.base.utility.FileAccess.Type
|
import de.staropensource.engine.base.utility.FileAccess.Type
|
||||||
import de.staropensource.engine.testing.TestBase
|
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.params.ParameterizedTest
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
|
@ -32,7 +33,7 @@ import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@Suppress("EmptyFunctionBlock")
|
@Suppress("LargeClass")
|
||||||
class FileAccessTest : TestBase() {
|
class FileAccessTest : TestBase() {
|
||||||
// -----> Tests on non-existent files
|
// -----> Tests on non-existent files
|
||||||
// These tests are executed on paths which likely do not exist
|
// These tests are executed on paths which likely do not exist
|
||||||
|
@ -181,7 +182,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("existsVoid.exist")
|
.traverse("existsVoid.exist")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.exists()
|
.exists()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -193,7 +194,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("existsFile.txt")
|
.traverse("existsFile.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createFile()
|
.createFile()
|
||||||
.exists()
|
.exists()
|
||||||
)
|
)
|
||||||
|
@ -206,7 +207,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("existsDirectory.d")
|
.traverse("existsDirectory.d")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createDirectory()
|
.createDirectory()
|
||||||
.exists()
|
.exists()
|
||||||
)
|
)
|
||||||
|
@ -223,7 +224,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("existsSymlinkReal.link.txt")
|
.traverse("existsSymlinkReal.link.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createLink(
|
.createLink(
|
||||||
FileAccess.temporaryCacheDirectory!!
|
FileAccess.temporaryCacheDirectory!!
|
||||||
.traverse("existsSymlinkReal.target.txt")
|
.traverse("existsSymlinkReal.target.txt")
|
||||||
|
@ -247,13 +248,13 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("existsSymlinkFake.link.txt")
|
.traverse("existsSymlinkFake.link.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createLink(
|
.createLink(
|
||||||
FileAccess
|
FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("existsSymlinkFake.target.txt")
|
.traverse("existsSymlinkFake.target.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true),
|
.verifyNotExists(),
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
.exists(noFollowSymbolicLink = noFollowSymbolicLink)
|
.exists(noFollowSymbolicLink = noFollowSymbolicLink)
|
||||||
|
@ -271,7 +272,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("existsHardlinkReal.link.txt")
|
.traverse("existsHardlinkReal.link.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createLink(
|
.createLink(
|
||||||
FileAccess.temporaryCacheDirectory!!
|
FileAccess.temporaryCacheDirectory!!
|
||||||
.traverse("existsHardlinkReal.target.txt")
|
.traverse("existsHardlinkReal.target.txt")
|
||||||
|
@ -298,7 +299,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("existsHardlinkFake.link.txt")
|
.traverse("existsHardlinkFake.link.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createLink(
|
.createLink(
|
||||||
target,
|
target,
|
||||||
true
|
true
|
||||||
|
@ -318,7 +319,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("getTypeVoid.txt")
|
.traverse("getTypeVoid.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.getType()
|
.getType()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -331,7 +332,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("getTypeFile.txt")
|
.traverse("getTypeFile.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createFile()
|
.createFile()
|
||||||
.verifyIsFile()
|
.verifyIsFile()
|
||||||
.getType()
|
.getType()
|
||||||
|
@ -346,7 +347,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("getTypeDirectory.d")
|
.traverse("getTypeDirectory.d")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createDirectory()
|
.createDirectory()
|
||||||
.verifyIsDirectory()
|
.verifyIsDirectory()
|
||||||
.getType()
|
.getType()
|
||||||
|
@ -360,7 +361,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("isSymbolicLinkReal.link.txt")
|
.traverse("isSymbolicLinkReal.link.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createLink(
|
.createLink(
|
||||||
FileAccess.temporaryCacheDirectory!!
|
FileAccess.temporaryCacheDirectory!!
|
||||||
.traverse("existsSymlinkReal.target.txt")
|
.traverse("existsSymlinkReal.target.txt")
|
||||||
|
@ -379,13 +380,13 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("isSymbolicLinkFake.test.txt")
|
.traverse("isSymbolicLinkFake.test.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createLink(
|
.createLink(
|
||||||
FileAccess
|
FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("existsSymlinkFake.target.txt")
|
.traverse("existsSymlinkFake.target.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true),
|
.verifyNotExists(),
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
.isSymbolicLink()
|
.isSymbolicLink()
|
||||||
|
@ -409,7 +410,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("getLinkDestinationSymlinkReal.link.txt")
|
.traverse("getLinkDestinationSymlinkReal.link.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createLink(
|
.createLink(
|
||||||
FileAccess
|
FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
|
@ -440,13 +441,13 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("getLinkDestinationSymlinkFake.link.txt")
|
.traverse("getLinkDestinationSymlinkFake.link.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createLink(
|
.createLink(
|
||||||
FileAccess
|
FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse(supplyValue)
|
.traverse(supplyValue)
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true),
|
.verifyNotExists(),
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
.getLinkDestination()
|
.getLinkDestination()
|
||||||
|
@ -461,7 +462,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("justSomeTestFile")
|
.traverse("justSomeTestFile")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.getFileSystem()
|
.getFileSystem()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -494,7 +495,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse(path)
|
.traverse(path)
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createFile()
|
.createFile()
|
||||||
.getType()
|
.getType()
|
||||||
)
|
)
|
||||||
|
@ -513,7 +514,7 @@ class FileAccessTest : TestBase() {
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse(path)
|
.traverse(path)
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists(noFollowSymbolicLink = true)
|
.verifyNotExists()
|
||||||
.createDirectory()
|
.createDirectory()
|
||||||
.getType()
|
.getType()
|
||||||
)
|
)
|
||||||
|
@ -523,66 +524,450 @@ class FileAccessTest : TestBase() {
|
||||||
// already covered by the exists* link tests
|
// already covered by the exists* link tests
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun move() {
|
fun moveFile() {
|
||||||
|
val target: FileAccess = FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("moveFile.moved.txt")
|
||||||
|
|
||||||
|
FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("moveFile.txt")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.move(target)
|
||||||
|
|
||||||
|
assertEquals(Type.FILE, target.getType())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun copy() {
|
fun moveDirectory() {
|
||||||
|
val target: FileAccess = FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("moveDirectory.moved.d")
|
||||||
|
|
||||||
|
FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("moveDirectory.d")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.createDirectory()
|
||||||
|
.verifyIsDirectory()
|
||||||
|
.traverse("sometest.file")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent()
|
||||||
|
.traverse("test/directory/tree")
|
||||||
|
.createDirectory()
|
||||||
|
.verifyIsDirectory()
|
||||||
|
.traverse("some-file.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent().parent().parent().parent()
|
||||||
|
.move(target)
|
||||||
|
|
||||||
|
assertEquals(Type.DIRECTORY, target.getType())
|
||||||
|
assertEquals(Type.FILE, target.traverse("sometest.file").getType())
|
||||||
|
assertEquals(Type.DIRECTORY, target.traverse("test").getType())
|
||||||
|
assertEquals(Type.DIRECTORY, target.traverse("test/directory").getType())
|
||||||
|
assertEquals(Type.DIRECTORY, target.traverse("test/directory/tree").getType())
|
||||||
|
assertEquals(Type.FILE, target.traverse("test/directory/tree/some-file.txt").getType())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun delete() {
|
fun copyFile() {
|
||||||
|
val target: FileAccess = FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("copyFile.copied.txt")
|
||||||
|
val file: FileAccess = FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("copyFile.txt")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.copy(target)
|
||||||
|
|
||||||
|
assertEquals(Type.FILE, file.getType())
|
||||||
|
assertEquals(Type.FILE, target.getType())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun deleteOnShutdown() {
|
fun copyDirectory() {
|
||||||
|
val target: FileAccess = FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("copyDirectory.copied.d")
|
||||||
|
val file: FileAccess = FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("copyDirectory.d")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.createDirectory()
|
||||||
|
.verifyIsDirectory()
|
||||||
|
.traverse("sometest.file")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent()
|
||||||
|
.traverse("test/directory/tree")
|
||||||
|
.createDirectory()
|
||||||
|
.verifyIsDirectory()
|
||||||
|
.traverse("some-file.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent().parent().parent().parent()
|
||||||
|
.copy(target)
|
||||||
|
|
||||||
|
// -> 'target'
|
||||||
|
assertEquals(Type.DIRECTORY, target.getType())
|
||||||
|
assertEquals(Type.FILE, target.traverse("sometest.file").getType())
|
||||||
|
assertEquals(Type.DIRECTORY, target.traverse("test").getType())
|
||||||
|
assertEquals(Type.DIRECTORY, target.traverse("test/directory").getType())
|
||||||
|
assertEquals(Type.DIRECTORY, target.traverse("test/directory/tree").getType())
|
||||||
|
assertEquals(Type.FILE, target.traverse("test/directory/tree/some-file.txt").getType())
|
||||||
|
// -> 'file'
|
||||||
|
assertEquals(Type.DIRECTORY, file.getType())
|
||||||
|
assertEquals(Type.FILE, file.traverse("sometest.file").getType())
|
||||||
|
assertEquals(Type.DIRECTORY, file.traverse("test").getType())
|
||||||
|
assertEquals(Type.DIRECTORY, file.traverse("test/directory").getType())
|
||||||
|
assertEquals(Type.DIRECTORY, file.traverse("test/directory/tree").getType())
|
||||||
|
assertEquals(Type.FILE, file.traverse("test/directory/tree/some-file.txt").getType())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun readBytes() {
|
fun deleteFile() {
|
||||||
|
val file: FileAccess = FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("deleteFile.txt")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.delete()
|
||||||
|
|
||||||
|
assertEquals(Type.VOID, file.getType())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun readLines() {
|
fun deleteDirectory() {
|
||||||
|
val file: FileAccess = FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("moveDirectory.d")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.createDirectory()
|
||||||
|
.verifyIsDirectory()
|
||||||
|
.traverse("sometest.file")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent()
|
||||||
|
.traverse("test/directory/tree")
|
||||||
|
.createDirectory()
|
||||||
|
.verifyIsDirectory()
|
||||||
|
.traverse("some-file.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent().parent().parent().parent()
|
||||||
|
.delete()
|
||||||
|
|
||||||
|
assertEquals(Type.VOID, file.getType())
|
||||||
|
assertEquals(Type.VOID, file.traverse("sometest.file").getType())
|
||||||
|
assertEquals(Type.VOID, file.traverse("test").getType())
|
||||||
|
assertEquals(Type.VOID, file.traverse("test/directory").getType())
|
||||||
|
assertEquals(Type.VOID, file.traverse("test/directory/tree").getType())
|
||||||
|
assertEquals(Type.VOID, file.traverse("test/directory/tree/some-file.txt").getType())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun readString() {
|
fun deleteOnShutdownFile() {
|
||||||
|
val file: FileAccess = FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("deleteFile.txt")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.deleteOnShutdown()
|
||||||
|
|
||||||
|
Engine.shutdown()
|
||||||
|
|
||||||
|
assertEquals(Type.VOID, file.getType())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun writeBytes() {
|
fun deleteOnShutdownDirectory() {
|
||||||
|
val file: FileAccess = FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("moveDirectory.d")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.createDirectory()
|
||||||
|
.verifyIsDirectory()
|
||||||
|
.traverse("sometest.file")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent()
|
||||||
|
.traverse("test/directory/tree")
|
||||||
|
.createDirectory()
|
||||||
|
.verifyIsDirectory()
|
||||||
|
.traverse("some-file.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent().parent().parent().parent()
|
||||||
|
.deleteOnShutdown()
|
||||||
|
|
||||||
|
Engine.shutdown()
|
||||||
|
|
||||||
|
assertEquals(Type.VOID, file.getType())
|
||||||
|
assertEquals(Type.VOID, file.traverse("sometest.file").getType())
|
||||||
|
assertEquals(Type.VOID, file.traverse("test").getType())
|
||||||
|
assertEquals(Type.VOID, file.traverse("test/directory").getType())
|
||||||
|
assertEquals(Type.VOID, file.traverse("test/directory/tree").getType())
|
||||||
|
assertEquals(Type.VOID, file.traverse("test/directory/tree/some-file.txt").getType())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun writeLines() {
|
fun readWriteBytes() {
|
||||||
|
val bytes: ByteArray = byteArrayOf(
|
||||||
|
0x62, 0x75, 0x73, 0x68,
|
||||||
|
0x20, 0x68, 0x69, 0x64,
|
||||||
|
0x20, 0x74, 0x68, 0x65,
|
||||||
|
0x20, 0x66, 0x61, 0x63,
|
||||||
|
0x74, 0x73
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
bytes.toList().toString(),
|
||||||
|
FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("readWriteBytes.txt")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.writeBytes(bytes, async = false)
|
||||||
|
.verifyIsFile()
|
||||||
|
.readBytes()
|
||||||
|
?.toList().toString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun writeString() {
|
fun readWriteLines() {
|
||||||
|
val lines: List<String> = listOf(
|
||||||
|
"This is an example file",
|
||||||
|
"It contains much text",
|
||||||
|
"It is used for testing the writeLines and readLines methods of the FileAccess class.",
|
||||||
|
"",
|
||||||
|
":3"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
lines.toString(),
|
||||||
|
FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("readWriteLines.txt")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.writeLines(lines, async = false)
|
||||||
|
.verifyIsFile()
|
||||||
|
.readLines()
|
||||||
|
?.toString()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun readWriteString() {
|
||||||
|
val string: String = """
|
||||||
|
This is an example file
|
||||||
|
It contains much text.
|
||||||
|
It is used for testing the writeLines and readLines methods of the FileAccess class.
|
||||||
|
|
||||||
|
:3"""
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
string,
|
||||||
|
FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("readWriteString.txt")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.writeString(string, async = false)
|
||||||
|
.verifyIsFile()
|
||||||
|
.readString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun appendBytes() {
|
fun appendBytes() {
|
||||||
|
val bytes: ByteArray = byteArrayOf(
|
||||||
|
0x62, 0x75, 0x73, 0x68,
|
||||||
|
0x20, 0x68, 0x69, 0x64,
|
||||||
|
0x20, 0x74, 0x68, 0x65,
|
||||||
|
0x20
|
||||||
|
)
|
||||||
|
val facts: ByteArray = byteArrayOf(
|
||||||
|
0x66, 0x61, 0x63, 0x74,
|
||||||
|
0x73
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
bytes.toList().plus(facts.toList()).toString(),
|
||||||
|
FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("appendBytes.txt")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.writeBytes(bytes, async = false)
|
||||||
|
.verifyIsFile()
|
||||||
|
.appendBytes(facts, async = false)
|
||||||
|
.readBytes()
|
||||||
|
?.toList().toString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun appendLines() {
|
fun appendLines() {
|
||||||
|
val lines: List<String> = listOf(
|
||||||
|
"This is an example file",
|
||||||
|
"It contains much text",
|
||||||
|
"It is used for testing the writeLines and readLines methods of the FileAccess class."
|
||||||
|
)
|
||||||
|
val cute: List<String> = listOf(
|
||||||
|
"",
|
||||||
|
":3"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
lines.plus(cute).toString(),
|
||||||
|
FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("appendLines.txt")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.writeLines(lines, async = false)
|
||||||
|
.verifyIsFile()
|
||||||
|
.appendLines(cute, async = false)
|
||||||
|
.readLines()
|
||||||
|
?.toString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun appendString() {
|
fun appendString() {
|
||||||
|
val string: String = """
|
||||||
|
This is an example file
|
||||||
|
It contains much text.
|
||||||
|
It is used for testing the writeLines and readLines methods of the FileAccess class."""
|
||||||
|
val cute: String = "\n\n:3"
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
string.plus(cute),
|
||||||
|
FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("appendString.txt")
|
||||||
|
.delete()
|
||||||
|
.verifyNotExists()
|
||||||
|
.writeString(string, async = false)
|
||||||
|
.verifyIsFile()
|
||||||
|
.appendString(cute, async = false)
|
||||||
|
.readString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun list() {
|
fun list() {
|
||||||
|
assertEquals(
|
||||||
|
listOf(
|
||||||
|
"testfile.txt",
|
||||||
|
"another-test-file.txt",
|
||||||
|
"some",
|
||||||
|
"a-directory.d",
|
||||||
|
).sorted().toString(),
|
||||||
|
FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("list.d")
|
||||||
|
.createDirectory()
|
||||||
|
.verifyIsDirectory()
|
||||||
|
.traverse("testfile.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent()
|
||||||
|
.traverse("another-test-file.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent()
|
||||||
|
.traverse("some/cool/dir/struct/verynice.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent().parent().parent().parent().parent()
|
||||||
|
.traverse("a-directory.d")
|
||||||
|
.createDirectory()
|
||||||
|
.parent()
|
||||||
|
.list()
|
||||||
|
?.toList()?.sorted().toString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun listFiles() {
|
fun listFiles() {
|
||||||
|
assertEquals(
|
||||||
|
listOf(
|
||||||
|
"testfile.txt",
|
||||||
|
"another-test-file.txt",
|
||||||
|
).sorted().toString(),
|
||||||
|
FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("list.d")
|
||||||
|
.createDirectory()
|
||||||
|
.verifyIsDirectory()
|
||||||
|
.traverse("testfile.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent()
|
||||||
|
.traverse("another-test-file.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent()
|
||||||
|
.traverse("some/cool/dir/struct/verynice.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent().parent().parent().parent().parent()
|
||||||
|
.traverse("a-directory.d")
|
||||||
|
.createDirectory()
|
||||||
|
.parent()
|
||||||
|
.listFiles()
|
||||||
|
?.toList()?.sorted().toString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun listDirectories() {
|
fun listDirectories() {
|
||||||
|
assertEquals(
|
||||||
|
listOf(
|
||||||
|
"some",
|
||||||
|
"a-directory.d",
|
||||||
|
).sorted().toString(),
|
||||||
|
FileAccess
|
||||||
|
.temporaryCacheDirectory!!
|
||||||
|
.traverse("list.d")
|
||||||
|
.createDirectory()
|
||||||
|
.verifyIsDirectory()
|
||||||
|
.traverse("testfile.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent()
|
||||||
|
.traverse("another-test-file.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent()
|
||||||
|
.traverse("some/cool/dir/struct/verynice.txt")
|
||||||
|
.createFile()
|
||||||
|
.verifyIsFile()
|
||||||
|
.parent().parent().parent().parent().parent()
|
||||||
|
.traverse("a-directory.d")
|
||||||
|
.createDirectory()
|
||||||
|
.parent()
|
||||||
|
.listDirectories()
|
||||||
|
?.toList()?.sorted().toString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue