diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2010-02-11 17:05:21 -0500 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2010-02-11 17:05:21 -0500 |
commit | 3093440f7191c4a307d600e14bb62b0d0619a54f (patch) | |
tree | 3715d4319b1c23f7b9909945cb3d6a57538a20f9 | |
parent | 65363bd4588d9e297e4e036ad2ab2f1083697ae4 (diff) |
Move tests from old test_java.clj to test_io.clj
-rw-r--r-- | src/test/clojure/clojure/contrib/test_io.clj | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/test/clojure/clojure/contrib/test_io.clj b/src/test/clojure/clojure/contrib/test_io.clj index 53347658..199cbfc5 100644 --- a/src/test/clojure/clojure/contrib/test_io.clj +++ b/src/test/clojure/clojure/contrib/test_io.clj @@ -1,5 +1,7 @@ (ns clojure.contrib.test-io - (:use clojure.test clojure.contrib.io)) + (:use clojure.test clojure.contrib.io) + (:import (java.io File) + (java.net URL URI))) (deftest file-str-backslash (is (= (java.io.File. @@ -7,3 +9,25 @@ "Documents" java.io.File/separator "file.txt")) (file-str "C:\\Documents\\file.txt")))) + +(deftest test-as-file + (testing "strings" + (is (= (File. "foo") (as-file "foo")))) + (testing "Files" + (is (= (File. "bar") (as-file (File. "bar")))))) + +(deftest test-as-url + (are [result expr] (= result expr) + (URL. "http://foo") (as-url (URL. "http://foo")) + (URL. "http://foo") (as-url "http://foo") + (URL. "http://foo") (as-url (URI. "http://foo")) + (URL. "file:/foo") (as-url (File. "/foo")))) + +(deftest test-delete-file + (let [file (File/createTempFile "test" "deletion") + not-file (File. (str (java.util.UUID/randomUUID)))] + (delete-file (.getAbsolutePath file)) + (is (not (.exists file))) + (is (thrown? ArithmeticException (/ 1 0))) + (is (thrown? java.io.IOException (delete-file not-file))) + (is (delete-file not-file :silently)))) |