Skip to content

Commit

Permalink
BugFix File.listFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
bastie committed Sep 7, 2024
1 parent 5647965 commit 970a054
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/JavApi/io/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ extension java.io {
if let directoryContents = try? FileManager.default.contentsOfDirectory(atPath: self.getAbsoluteFile().toString()) {
var result : [java.io.File] = [java.io.File]()
for nextFile in directoryContents {
result.append(java.io.File(nextFile))
result.append(java.io.File("\(self.file)\(java.io.File.separator)\(nextFile)"))
}
return result
}
Expand Down
28 changes: 28 additions & 0 deletions Tests/JavApiTests/JavApi_io_File_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,32 @@ final class JavApi_io_File_Tests: XCTestCase {
// TODO: Test missing for java.io.File on other platforms
#endif
}

/// Test agains JavApi 0.12.0 bug.
func testListFiles () {
let absoluteDir = "/Applications"
let appDir = java.io.File(absoluteDir)
if let apps = appDir.listFiles() {
for app in apps {
XCTAssert(app.getAbsolutePath().startsWith(absoluteDir))
}
}
}
class AppFilter : java.io.FileFilter {
func accept(_ file: JavApi.java.io.File) -> Bool {
return file.getName().endsWith(".app") && file.isDirectory()
}
typealias FileFilter = AppFilter
}
/// Test agains JavApi 0.12.0 bug.
func testListFilesWithFileFilter () {
let absoluteDir = "/Applications"
let appDir = java.io.File(absoluteDir)
if let apps = appDir.listFiles (AppFilter()) {
for app in apps {
XCTAssert(app.getAbsolutePath().startsWith(absoluteDir))
XCTAssert(app.getAbsolutePath().hasSuffix(".app"))
}
}
}
}

0 comments on commit 970a054

Please sign in to comment.