Created
May 17, 2010 22:51
-
-
Save jkk/404336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; for minimal filesystem mocking (only listFiles and getName methods work) | |
| (defn mock-filesystem | |
| "Takes a tree of vectors and returns a minimal mock file/dir hierarchy" | |
| [file] | |
| (if (vector? file) | |
| (let [[dir & files] file | |
| children (into-array File (map mock-fs files))] | |
| (proxy [File] [dir] | |
| (listFiles [] children))) | |
| (File. file))) | |
| (deftest test-mock-filesystem | |
| (is (= (map #(.getName %) | |
| (.listFiles (mock-filesystem ["/" "foo" "bar" "baz"]))) | |
| ["foo" "bar" "baz"]))) | |
| ;; or, with some more proxy methods (listFiles, getName, isDirectory, isFile) | |
| (defn mock-filesystem | |
| "Takes a tree of vectors and returns a mock file/dir hierarchy of | |
| proxied java.io.File instances" | |
| [file] | |
| (if (vector? file) | |
| (let [[dir & files] file | |
| children (into-array java.io.File (map mock-fs files))] | |
| (proxy [java.io.File] [dir] | |
| (isDirectory [] true) | |
| (isFile [] false) | |
| (listFiles [] children))) | |
| (proxy [java.io.File] [file] | |
| (isDirectory [] false) | |
| (isFile [] true)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment