diff --git a/base/src/test/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt b/base/src/test/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt index f51d39c..351af19 100644 --- a/base/src/test/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt +++ b/base/src/test/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt @@ -35,6 +35,40 @@ import kotlin.test.assertTrue @Suppress("LargeClass") class FileAccessTest : TestBase() { + // -----> Utility methods + // These help in tests + /** + * Transforms file paths returned by + * [FileAccess.toString] for proper comparison. + * + * This method takes platform-specific restrictions and + * quirks into consideration to transform the supplied + * path. It also applies various formatting rules used + * extensively in the tests provided by this class. + * + * @param path path string to transform + * @return transformed path string + * @throws NullPointerException if [FileAccess.temporaryCacheDirectory] is `null` + * @since v1-alpha10 + */ + @Throws(NullPointerException::class) + private fun transformToStringPath(path: String): String { + var string: String = path + + // Replace formatting rules of this test class + string = string + .replace("+", FileAccess.temporaryCacheDirectory!!.toString()) + .replace("%", File.separator) + + // Apply operating system-specific updates + when (Environment.operatingSystem) { + Environment.OperatingSystem.WINDOWS -> string = "C:${string}" + else -> {} + } + + return string + } + // -----> Tests on non-existent files // These tests are executed on paths which likely do not exist @ParameterizedTest @@ -49,8 +83,7 @@ class FileAccessTest : TestBase() { ) fun toStringTest(supplyValue: String, compareValue: String) { assertEquals( - compareValue - .replace("+", FileAccess.temporaryCacheDirectory!!.toString()), + transformToStringPath(compareValue), FileAccess .temporaryCacheDirectory!! .traverse(supplyValue) @@ -70,9 +103,7 @@ class FileAccessTest : TestBase() { ) fun toStringRaw(supplyValue: String, compareValue: String) { assertEquals( - compareValue - .replace("+", FileAccess.temporaryCacheDirectory!!.toString()) - .replace("%", File.separator), + transformToStringPath(compareValue), FileAccess .temporaryCacheDirectory!! .traverse(supplyValue) @@ -92,7 +123,7 @@ class FileAccessTest : TestBase() { ) fun getBaseName(supplyValue: String, compareValue: String) { assertEquals( - compareValue, + transformToStringPath(compareValue), FileAccess .temporaryCacheDirectory!! .traverse(supplyValue) @@ -112,8 +143,7 @@ class FileAccessTest : TestBase() { ) fun parent(supplyValue: String, compareValue: String) { assertEquals( - compareValue - .replace("+", FileAccess.temporaryCacheDirectory!!.toString()), + transformToStringPath(compareValue), FileAccess .temporaryCacheDirectory!! .traverse(supplyValue) @@ -403,9 +433,7 @@ class FileAccessTest : TestBase() { ) fun getLinkDestinationReal(supplyValue: String, compareValue: String) { assertEquals( - compareValue - .replace("+", FileAccess.temporaryCacheDirectory!!.toString()) - .replace("%", File.separator), + transformToStringPath(compareValue), FileAccess .temporaryCacheDirectory!! .traverse("getLinkDestinationSymlinkReal.link.txt") @@ -434,9 +462,7 @@ class FileAccessTest : TestBase() { ) fun getLinkDestinationFake(supplyValue: String, compareValue: String) { assertEquals( - compareValue - .replace("+", FileAccess.temporaryCacheDirectory!!.toString()) - .replace("%", File.separator), + transformToStringPath(compareValue), FileAccess .temporaryCacheDirectory!! .traverse("getLinkDestinationSymlinkFake.link.txt")