Add '@DisplayName's to tests, fix FileAccess scheduled deletion
This commit is contained in:
parent
d0dbdbeef8
commit
9d001032c2
2 changed files with 40 additions and 12 deletions
|
@ -202,13 +202,16 @@ class FileAccess {
|
||||||
|
|
||||||
// Delete all files recursively
|
// Delete all files recursively
|
||||||
// Only applies to directories
|
// Only applies to directories
|
||||||
it.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete)
|
Files.walkFileTree(path, DeleteDirectoryVisitor())
|
||||||
|
|
||||||
// Delete file or directory
|
// Delete file or directory
|
||||||
if (Files.exists(path))
|
if (Files.exists(path))
|
||||||
if (!path.toFile().delete())
|
try {
|
||||||
logger.sarn("Unable to delete file or directory '${unformatFromPath(path)}' scheduled for deletion manually")
|
Files.delete(path)
|
||||||
|
} catch (_: NoSuchFileException) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} catch (_: NoSuchFileException) {
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
logger.sarn("Unable to delete file or directory '${unformatFromPath(path)}' scheduled for deletion.\n${StackTraceUtils.stacktraceRecursive(exception)}")
|
logger.sarn("Unable to delete file or directory '${unformatFromPath(path)}' scheduled for deletion.\n${StackTraceUtils.stacktraceRecursive(exception)}")
|
||||||
}
|
}
|
||||||
|
@ -617,7 +620,6 @@ class FileAccess {
|
||||||
* @throws IOAccessException on IO error
|
* @throws IOAccessException on IO error
|
||||||
* @see verifyIsLink
|
* @see verifyIsLink
|
||||||
* @see verifyIsSymbolicLink
|
* @see verifyIsSymbolicLink
|
||||||
* @see verifyIsHardLink
|
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
@Throws(IOAccessException::class)
|
@Throws(IOAccessException::class)
|
||||||
|
@ -715,7 +717,7 @@ class FileAccess {
|
||||||
logger.diag("Deleting '${unformatFromPath(path)}'")
|
logger.diag("Deleting '${unformatFromPath(path)}'")
|
||||||
|
|
||||||
if (!isSymbolicLink() && file.isDirectory)
|
if (!isSymbolicLink() && file.isDirectory)
|
||||||
Files.walkFileTree(path, DeleteDirectoryVisitor(path))
|
Files.walkFileTree(path, DeleteDirectoryVisitor())
|
||||||
|
|
||||||
Files.delete(path)
|
Files.delete(path)
|
||||||
} catch (_: NoSuchFileException) {
|
} catch (_: NoSuchFileException) {
|
||||||
|
@ -1475,16 +1477,15 @@ class FileAccess {
|
||||||
* {@link FileVisitor} instance for
|
* {@link FileVisitor} instance for
|
||||||
* delete directories recursively.
|
* delete directories recursively.
|
||||||
*
|
*
|
||||||
* @param directory directory to delete
|
|
||||||
* @since v1-alpha9
|
* @since v1-alpha9
|
||||||
*/
|
*/
|
||||||
private class DeleteDirectoryVisitor(directory: Path) : FileVisitor<Path> {
|
private class DeleteDirectoryVisitor : FileVisitor<Path> {
|
||||||
override fun preVisitDirectory(path: Path, attributes: BasicFileAttributes): FileVisitResult {
|
override fun preVisitDirectory(path: Path, attributes: BasicFileAttributes): FileVisitResult {
|
||||||
return FileVisitResult.CONTINUE
|
return FileVisitResult.CONTINUE
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitFile(path: Path, attributes: BasicFileAttributes): FileVisitResult {
|
override fun visitFile(path: Path, attributes: BasicFileAttributes): FileVisitResult {
|
||||||
path.toFile().delete()
|
Files.delete(path)
|
||||||
return FileVisitResult.CONTINUE
|
return FileVisitResult.CONTINUE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import de.staropensource.engine.base.Engine
|
||||||
import de.staropensource.engine.base.TestBase
|
import de.staropensource.engine.base.TestBase
|
||||||
import de.staropensource.engine.base.utility.FileAccess.Type
|
import de.staropensource.engine.base.utility.FileAccess.Type
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.params.ParameterizedTest
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
import org.junit.jupiter.params.provider.CsvSource
|
import org.junit.jupiter.params.provider.CsvSource
|
||||||
|
@ -90,6 +91,7 @@ class FileAccessTest : TestBase() {
|
||||||
"/./did/somebody\\/say\\yoga" , "/did/somebody/say/yoga"
|
"/./did/somebody\\/say\\yoga" , "/did/somebody/say/yoga"
|
||||||
"test.txt", "+/test.txt""""
|
"test.txt", "+/test.txt""""
|
||||||
)
|
)
|
||||||
|
@DisplayName("toString")
|
||||||
fun toStringTest(supplyValue: String, compareValue: String) {
|
fun toStringTest(supplyValue: String, compareValue: String) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
transformToStringPath(compareValue),
|
transformToStringPath(compareValue),
|
||||||
|
@ -215,6 +217,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("exists (void)")
|
||||||
fun existsVoid() {
|
fun existsVoid() {
|
||||||
assertFalse(
|
assertFalse(
|
||||||
FileAccess
|
FileAccess
|
||||||
|
@ -227,6 +230,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("exists (file)")
|
||||||
fun existsFile() {
|
fun existsFile() {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
FileAccess
|
FileAccess
|
||||||
|
@ -240,6 +244,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("exists (directory)")
|
||||||
fun existsDirectory() {
|
fun existsDirectory() {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
FileAccess
|
FileAccess
|
||||||
|
@ -257,7 +262,8 @@ class FileAccessTest : TestBase() {
|
||||||
true,
|
true,
|
||||||
false
|
false
|
||||||
])
|
])
|
||||||
fun existsSymlinkReal(noFollowSymbolicLink: Boolean) {
|
@DisplayName("exists (symbolic link, real)")
|
||||||
|
fun existsSymbolicLinkReal(noFollowSymbolicLink: Boolean) {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
FileAccess
|
FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
|
@ -266,7 +272,7 @@ class FileAccessTest : TestBase() {
|
||||||
.verifyNotExists()
|
.verifyNotExists()
|
||||||
.createLink(
|
.createLink(
|
||||||
FileAccess.temporaryCacheDirectory!!
|
FileAccess.temporaryCacheDirectory!!
|
||||||
.traverse("existsSymlinkReal.target.txt")
|
.traverse("existsSymbolicLinkReal.target.txt")
|
||||||
.createFile()
|
.createFile()
|
||||||
.verifyIsFile(),
|
.verifyIsFile(),
|
||||||
false
|
false
|
||||||
|
@ -280,12 +286,13 @@ class FileAccessTest : TestBase() {
|
||||||
true,
|
true,
|
||||||
false
|
false
|
||||||
])
|
])
|
||||||
fun existsSymlinkFake(noFollowSymbolicLink: Boolean) {
|
@DisplayName("exists (symbolic link, fake)")
|
||||||
|
fun existsSymbolicLinkFake(noFollowSymbolicLink: Boolean) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
noFollowSymbolicLink,
|
noFollowSymbolicLink,
|
||||||
FileAccess
|
FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
.traverse("existsSymlinkFake.link.txt")
|
.traverse("existsSymbolicLinkFake.link.txt")
|
||||||
.delete()
|
.delete()
|
||||||
.verifyNotExists()
|
.verifyNotExists()
|
||||||
.createLink(
|
.createLink(
|
||||||
|
@ -305,6 +312,7 @@ class FileAccessTest : TestBase() {
|
||||||
true,
|
true,
|
||||||
false
|
false
|
||||||
])
|
])
|
||||||
|
@DisplayName("exists (hard link, real)")
|
||||||
fun existsHardlinkReal(noFollowSymbolicLink: Boolean) {
|
fun existsHardlinkReal(noFollowSymbolicLink: Boolean) {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
FileAccess
|
FileAccess
|
||||||
|
@ -328,6 +336,7 @@ class FileAccessTest : TestBase() {
|
||||||
true,
|
true,
|
||||||
false
|
false
|
||||||
])
|
])
|
||||||
|
@DisplayName("exists (hard link, fake)")
|
||||||
fun existsHardlinkFake(noFollowSymbolicLink: Boolean) {
|
fun existsHardlinkFake(noFollowSymbolicLink: Boolean) {
|
||||||
val target: FileAccess = FileAccess
|
val target: FileAccess = FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
|
@ -351,6 +360,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("getType (void)")
|
||||||
fun getTypeVoid() {
|
fun getTypeVoid() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Type.VOID,
|
Type.VOID,
|
||||||
|
@ -364,6 +374,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("getType (file)")
|
||||||
fun getTypeFile() {
|
fun getTypeFile() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Type.FILE,
|
Type.FILE,
|
||||||
|
@ -379,6 +390,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("getType (directory)")
|
||||||
fun getTypeDirectory() {
|
fun getTypeDirectory() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Type.DIRECTORY,
|
Type.DIRECTORY,
|
||||||
|
@ -394,6 +406,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("isSymbolicLink (real)")
|
||||||
fun isSymbolicLinkReal() {
|
fun isSymbolicLinkReal() {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
FileAccess
|
FileAccess
|
||||||
|
@ -413,6 +426,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("isSymbolicLink (fake)")
|
||||||
fun isSymbolicLinkFake() {
|
fun isSymbolicLinkFake() {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
FileAccess
|
FileAccess
|
||||||
|
@ -440,6 +454,7 @@ class FileAccessTest : TestBase() {
|
||||||
"very\\\cool\\/directory/structure", "+%very/cool/directory/structure"
|
"very\\\cool\\/directory/structure", "+%very/cool/directory/structure"
|
||||||
"some.spot", "+%some.spot""""
|
"some.spot", "+%some.spot""""
|
||||||
)
|
)
|
||||||
|
@DisplayName("getLinkDestination (real)")
|
||||||
fun getLinkDestinationReal(supplyValue: String, compareValue: String) {
|
fun getLinkDestinationReal(supplyValue: String, compareValue: String) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
transformToStringPath(compareValue),
|
transformToStringPath(compareValue),
|
||||||
|
@ -469,6 +484,7 @@ class FileAccessTest : TestBase() {
|
||||||
"getLinkDestinationSymlinkFake.d/very\\\cool\\/directory/structure", "+%getLinkDestinationSymlinkFake.d/very/cool/directory/structure"
|
"getLinkDestinationSymlinkFake.d/very\\\cool\\/directory/structure", "+%getLinkDestinationSymlinkFake.d/very/cool/directory/structure"
|
||||||
"getLinkDestinationSymlinkFake.d/some.spot", "+%getLinkDestinationSymlinkFake.d/some.spot""""
|
"getLinkDestinationSymlinkFake.d/some.spot", "+%getLinkDestinationSymlinkFake.d/some.spot""""
|
||||||
)
|
)
|
||||||
|
@DisplayName("getLinkDestination (fake)")
|
||||||
fun getLinkDestinationFake(supplyValue: String, compareValue: String) {
|
fun getLinkDestinationFake(supplyValue: String, compareValue: String) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
transformToStringPath(compareValue),
|
transformToStringPath(compareValue),
|
||||||
|
@ -559,6 +575,7 @@ class FileAccessTest : TestBase() {
|
||||||
// already covered by the exists* link tests
|
// already covered by the exists* link tests
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("move (file)")
|
||||||
fun moveFile() {
|
fun moveFile() {
|
||||||
val target: FileAccess = FileAccess
|
val target: FileAccess = FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
|
@ -577,6 +594,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("move (directory)")
|
||||||
fun moveDirectory() {
|
fun moveDirectory() {
|
||||||
val target: FileAccess = FileAccess
|
val target: FileAccess = FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
|
@ -611,6 +629,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("copy (file)")
|
||||||
fun copyFile() {
|
fun copyFile() {
|
||||||
val target: FileAccess = FileAccess
|
val target: FileAccess = FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
|
@ -629,6 +648,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("copy (directory)")
|
||||||
fun copyDirectory() {
|
fun copyDirectory() {
|
||||||
val target: FileAccess = FileAccess
|
val target: FileAccess = FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
|
@ -670,6 +690,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("delete (file)")
|
||||||
fun deleteFile() {
|
fun deleteFile() {
|
||||||
val file: FileAccess = FileAccess
|
val file: FileAccess = FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
|
@ -684,6 +705,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("delete (directory)")
|
||||||
fun deleteDirectory() {
|
fun deleteDirectory() {
|
||||||
val file: FileAccess = FileAccess
|
val file: FileAccess = FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
|
@ -714,6 +736,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("deleteOnShutdown (file)")
|
||||||
fun deleteOnShutdownFile() {
|
fun deleteOnShutdownFile() {
|
||||||
val file: FileAccess = FileAccess
|
val file: FileAccess = FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
|
@ -730,6 +753,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("deleteOnShutdown (directory)")
|
||||||
fun deleteOnShutdownDirectory() {
|
fun deleteOnShutdownDirectory() {
|
||||||
val file: FileAccess = FileAccess
|
val file: FileAccess = FileAccess
|
||||||
.temporaryCacheDirectory!!
|
.temporaryCacheDirectory!!
|
||||||
|
@ -762,6 +786,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("readBytes & writeBytes")
|
||||||
fun readWriteBytes() {
|
fun readWriteBytes() {
|
||||||
val bytes: ByteArray = byteArrayOf(
|
val bytes: ByteArray = byteArrayOf(
|
||||||
0x62, 0x75, 0x73, 0x68,
|
0x62, 0x75, 0x73, 0x68,
|
||||||
|
@ -786,6 +811,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("readLines & writeLines")
|
||||||
fun readWriteLines() {
|
fun readWriteLines() {
|
||||||
val lines: List<String> = listOf(
|
val lines: List<String> = listOf(
|
||||||
"This is an example file",
|
"This is an example file",
|
||||||
|
@ -810,6 +836,7 @@ class FileAccessTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("readString & writeString")
|
||||||
fun readWriteString() {
|
fun readWriteString() {
|
||||||
val string: String = """
|
val string: String = """
|
||||||
This is an example file
|
This is an example file
|
||||||
|
|
Loading…
Reference in a new issue