Skip to content

Commit

Permalink
Add abstract test with default nio FileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
oldergod committed Jun 19, 2023
1 parent 1525ec2 commit 60439b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ abstract class AbstractFileSystemTest(
val windowsLimitations: Boolean,
val allowClobberingEmptyDirectories: Boolean,
val allowAtomicMoveFromFileToDirectory: Boolean,
val allowRenameWhenTargetIsOpen: Boolean = !windowsLimitations,
temporaryDirectory: Path,
) {
val base: Path = temporaryDirectory / "${this::class.simpleName}-${randomToken(16)}"
Expand Down Expand Up @@ -1501,10 +1502,15 @@ abstract class AbstractFileSystemTest(
val to = base / "to.txt"
from.writeUtf8("source file")
to.writeUtf8("target file")
expectIOExceptionOnWindows {

val expectCrash = !allowRenameWhenTargetIsOpen
try {
fileSystem.source(to).use {
fileSystem.atomicMove(from, to)
}
assertFalse(expectCrash)
} catch (_: IOException) {
assertTrue(expectCrash)
}
}

Expand Down
12 changes: 11 additions & 1 deletion okio/src/jvmTest/kotlin/okio/FileHandleFileSystemTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package okio

import com.google.common.jimfs.Configuration
import com.google.common.jimfs.Jimfs
import java.nio.file.FileSystems
import kotlinx.datetime.Clock
import okio.FileHandleFileSystemTest.FileHandleTestingFileSystem
import okio.FileSystem.Companion.asOkioFileSystem

/**
Expand Down Expand Up @@ -73,3 +73,13 @@ class FileHandleNioFileSystemWrapperFileSystemTest : AbstractFileSystemTest(
allowAtomicMoveFromFileToDirectory = true,
temporaryDirectory = FileSystem.SYSTEM_TEMPORARY_DIRECTORY,
)

class FileHandleNioDefaultFileSystemWrapperFileSystemTest : AbstractFileSystemTest(
clock = Clock.System,
fileSystem = FileSystems.getDefault().asOkioFileSystem(),
windowsLimitations = false,
allowClobberingEmptyDirectories = Path.DIRECTORY_SEPARATOR == "\\",
allowAtomicMoveFromFileToDirectory = false,
allowRenameWhenTargetIsOpen = Path.DIRECTORY_SEPARATOR != "\\",
temporaryDirectory = FileSystem.SYSTEM_TEMPORARY_DIRECTORY,
)

0 comments on commit 60439b7

Please sign in to comment.