Drop deprecations: FileTreeWalk deprecated API elements.
This commit is contained in:
@@ -53,7 +53,6 @@ class FileTreeWalkTest {
|
||||
try {
|
||||
for (walk in listOf(File::walkTopDown, File::walkBottomUp)) {
|
||||
assertEquals(testFile, walk(testFile).single(), "${walk.name}")
|
||||
assertTrue(walk(testFile).treeFilter { false }.none(), "${walk.name}")
|
||||
assertEquals(testFile, testFile.walk().onEnter { false }.single(), "${walk.name} - enter should not be called for single file")
|
||||
|
||||
assertTrue(walk(nonExistantFile).none(), "${walk.name} - enter should not be called for single file")
|
||||
@@ -151,7 +150,7 @@ class FileTreeWalkTest {
|
||||
child.delete()
|
||||
}
|
||||
}
|
||||
for (file in basedir.walkTopDown().enter(::enter)) {
|
||||
for (file in basedir.walkTopDown().onEnter { enter(it); true }) {
|
||||
val name = file.relativeToOrSelf(basedir).invariantSeparatorsPath
|
||||
assertFalse(namesTopDown.contains(name), "$name is visited twice")
|
||||
namesTopDown.add(name)
|
||||
@@ -174,7 +173,7 @@ class FileTreeWalkTest {
|
||||
child.delete()
|
||||
}
|
||||
}
|
||||
for (file in basedir.walkBottomUp().enter(::enter)) {
|
||||
for (file in basedir.walkBottomUp().onEnter { enter(it); true }) {
|
||||
val name = file.relativeToOrSelf(basedir).invariantSeparatorsPath
|
||||
assertFalse(namesTopDown.contains(name), "$name is visited twice")
|
||||
namesTopDown.add(name)
|
||||
@@ -187,14 +186,14 @@ class FileTreeWalkTest {
|
||||
|
||||
private fun compareWalkResults(expected: Set<String>, basedir: File, filter: (File) -> Boolean) {
|
||||
val namesTopDown = HashSet<String>()
|
||||
for (file in basedir.walkTopDown().treeFilter { filter(it) }) {
|
||||
for (file in basedir.walkTopDown().onEnter { filter(it) }) {
|
||||
val name = file.toRelativeString(basedir)
|
||||
assertFalse(namesTopDown.contains(name), "$name is visited twice")
|
||||
namesTopDown.add(name)
|
||||
}
|
||||
assertEquals(expected, namesTopDown, "Top-down walk results differ")
|
||||
val namesBottomUp = HashSet<String>()
|
||||
for (file in basedir.walkBottomUp().treeFilter { filter(it) }) {
|
||||
for (file in basedir.walkBottomUp().onEnter { filter(it) }) {
|
||||
val name = file.toRelativeString(basedir)
|
||||
assertFalse(namesBottomUp.contains(name), "$name is visited twice")
|
||||
namesBottomUp.add(name)
|
||||
@@ -202,7 +201,7 @@ class FileTreeWalkTest {
|
||||
assertEquals(expected, namesBottomUp, "Bottom-up walk results differ")
|
||||
}
|
||||
|
||||
@Test fun withFilter() {
|
||||
@Test fun withDirectoryFilter() {
|
||||
val basedir = createTestFiles()
|
||||
try {
|
||||
// Every directory ended with 3 and its content is filtered out
|
||||
@@ -215,7 +214,7 @@ class FileTreeWalkTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun withTotalFilter() {
|
||||
@Test fun withTotalDirectoryFilter() {
|
||||
val basedir = createTestFiles()
|
||||
try {
|
||||
val referenceNames = emptySet<String>()
|
||||
@@ -266,9 +265,10 @@ class FileTreeWalkTest {
|
||||
val dirs = HashSet<File>()
|
||||
val failed = HashSet<String>()
|
||||
val stack = ArrayList<File>()
|
||||
fun beforeVisitDirectory(dir: File) {
|
||||
fun beforeVisitDirectory(dir: File): Boolean {
|
||||
stack.add(dir)
|
||||
dirs.add(dir.relativeToOrSelf(basedir))
|
||||
return true
|
||||
}
|
||||
|
||||
fun afterVisitDirectory(dir: File) {
|
||||
@@ -286,8 +286,8 @@ class FileTreeWalkTest {
|
||||
//stack.removeAt(stack.lastIndex)
|
||||
failed.add(dir.name)
|
||||
}
|
||||
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).
|
||||
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory) visitFile(it) }
|
||||
basedir.walkTopDown().onEnter(::beforeVisitDirectory).onLeave(::afterVisitDirectory).
|
||||
onFail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory) visitFile(it) }
|
||||
assertTrue(stack.isEmpty())
|
||||
for (fileName in arrayOf("", "1", "1/2", "1/3", "6", "8")) {
|
||||
assertTrue(dirs.contains(File(fileName)), fileName)
|
||||
@@ -299,7 +299,7 @@ class FileTreeWalkTest {
|
||||
//limit maxDepth
|
||||
files.clear()
|
||||
dirs.clear()
|
||||
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).maxDepth(1).
|
||||
basedir.walkTopDown().onEnter(::beforeVisitDirectory).onLeave(::afterVisitDirectory).maxDepth(1).
|
||||
forEach { it -> if (it != basedir) visitFile(it) }
|
||||
assertTrue(stack.isEmpty())
|
||||
assertEquals(setOf(File("")), dirs)
|
||||
@@ -312,8 +312,8 @@ class FileTreeWalkTest {
|
||||
try {
|
||||
files.clear()
|
||||
dirs.clear()
|
||||
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).
|
||||
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory) visitFile(it) }
|
||||
basedir.walkTopDown().onEnter(::beforeVisitDirectory).onLeave(::afterVisitDirectory).
|
||||
onFail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory) visitFile(it) }
|
||||
assertTrue(stack.isEmpty())
|
||||
assertEquals(setOf("1"), failed)
|
||||
assertEquals(listOf("", "1", "6", "8").map { File(it) }.toSet(), dirs)
|
||||
|
||||
Reference in New Issue
Block a user