Permalink
Browse files

Move tests from old test_java.clj to test_io.clj

  • Loading branch information...
1 parent 65363bd commit 3093440f7191c4a307d600e14bb62b0d0619a54f @stuartsierra stuartsierra committed Feb 11, 2010
Showing with 25 additions and 1 deletion.
  1. +25 −1 src/test/clojure/clojure/contrib/test_io.clj
@@ -1,9 +1,33 @@
(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.
(str "C:" java.io.File/separator
"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))))

0 comments on commit 3093440

Please sign in to comment.