Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Remove test_java.clj

  • Loading branch information...
commit 65363bd4588d9e297e4e036ad2ab2f1083697ae4 1 parent b79b246
Stuart Sierra authored February 11, 2010
123  src/test/clojure/clojure/contrib/test_java.clj
... ...
@@ -1,123 +0,0 @@
1  
-(ns clojure.contrib.test-java
2  
-  (:use clojure.test
3  
-	[clojure.contrib.io :only (spit)]
4  
-	clojure.contrib.java)
5  
-  (:import [java.io File]
6  
-           [java.net URL URI]
7  
-	   [java.util Properties]))
8  
-
9  
-(deftest test-relative-path-string
10  
-  (testing "strings"
11  
-    (is (= "foo" (relative-path-string "foo"))))
12  
-  (testing "absolute path strings are forbidden"
13  
-    (is (thrown? IllegalArgumentException (relative-path-string "/baz"))))
14  
-  (testing "relative File paths"
15  
-    (is (= "bar" (relative-path-string (File. "bar")))))
16  
-  (testing "absolute File paths are forbidden"
17  
-    (is (thrown? IllegalArgumentException (relative-path-string (File. "/quux")))))
18  
-)
19  
-
20  
-(deftest test-as-file
21  
-  (testing "strings"
22  
-    (is (= (File. "foo") (as-file "foo"))))
23  
-  (testing "Files"
24  
-    (is (= (File. "bar") (as-file (File. "bar")))))
25  
-)
26  
-
27  
-(deftest test-as-url
28  
-  (are [result expr] (= result expr)
29  
-       (URL. "http://foo") (as-url (URL. "http://foo"))
30  
-       (URL. "http://foo") (as-url "http://foo")
31  
-       (URL. "http://foo") (as-url (URI. "http://foo"))
32  
-       (URL. "file:/foo") (as-url (File. "/foo"))))
33  
-
34  
-(deftest test-file
35  
-  (testing "single argument"
36  
-    (is (= (File. "foo") (file "foo"))))
37  
-  (testing "two arguments"
38  
-    (is (= (File. "foo/bar") (file "foo" "bar"))))
39  
-  (testing "N arguments"
40  
-    (is (= (File. "foo/bar/baz/quux") (file "foo" "bar" "baz" "quux"))))
41  
-  (testing "no sneaking in absolute paths!"
42  
-    (is (thrown? IllegalArgumentException (file "foo" "bar" "/boom" "baz" "quux"))))
43  
-)
44  
-
45  
-(deftest test-as-str
46  
-  (testing "keyword to string"
47  
-    (is (= "foo") (as-str :foo)))
48  
-  (testing "symbol to string"
49  
-    (is (= "foo") (as-str 'foo)))
50  
-  (testing "string to string"
51  
-    (is (= "foo") (as-str "foo")))
52  
-  (testing "stringifying non-namish things"
53  
-    (is (= "42") (as-str 42)))
54  
-)
55  
-
56  
-(deftest test-get-system-property
57  
-  (testing "works the same with keywords, symbols, and strings"
58  
-    (is (= (get-system-property "java.home") (get-system-property 'java.home)))
59  
-    (is (= (get-system-property "java.home") (get-system-property :java.home))))
60  
-  (testing "treats second arg as default"
61  
-    (is (= "default" (get-system-property "testing.test-system-property" "default"))))
62  
-  (testing "returns nil for missing properties"
63  
-    (is (nil? (get-system-property "testing.test-system-property"))))
64  
-)
65  
-    
66  
-(deftest test-set-system-properties 
67  
-  (testing "set and then unset a property using keywords"
68  
-    (let [propname :clojure.contrib.java.test-set-system-properties]
69  
-      (is (nil? (get-system-property propname)))
70  
-      (set-system-properties {propname :foo})
71  
-      (is (= "foo") (get-system-property propname))
72  
-      (set-system-properties {propname nil})
73  
-      (is (nil? (get-system-property propname)))))
74  
-)
75  
-
76  
-(deftest test-with-system-properties
77  
-  (let [propname :clojure.contrib.java.test-with-system-properties]
78  
-    (testing "sets a property only for the duration of a block"
79  
-      (is (= "foo" 
80  
-	     (with-system-properties {propname "foo"}
81  
-	       (get-system-property propname))))
82  
-      (is (nil? (get-system-property propname)))))
83  
-  (testing "leaves other properties alone"
84  
-    ; TODO: write this test better, using a properties -> map function
85  
-    (let [propname :clojure.contrib.java.test-with-system-properties
86  
-          propcount (count (System/getProperties))]
87  
-      (with-system-properties {propname "foo"}
88  
-        (is (= (inc propcount) (count (System/getProperties)))))
89  
-      (is (= propcount (count (System/getProperties))))))
90  
-)
91  
-
92  
-(deftest test-as-properties
93  
-  (let [expected (doto (Properties.)
94  
-		   (.setProperty "a" "b")
95  
-		   (.setProperty "c" "d"))]
96  
-    (testing "with a map"
97  
-      (is (= expected
98  
-	     (as-properties {:a "b" :c "d"}))))
99  
-    (testing "with a sequence of pairs"
100  
-      (is (= expected
101  
-	     (as-properties [[:a :b] [:c :d]]))))))
102  
-
103  
-(deftest test-read-properties
104  
-  (let [f (File/createTempFile "test" "properties")]
105  
-    (spit f "a=b\nc=d")
106  
-    (is (= {"a" "b" "c" "d"}
107  
-	   (read-properties f)))))
108  
-	   
109  
-(deftest test-write-properties
110  
-  (let [f (File/createTempFile "test" "properties")]
111  
-    (write-properties [['a 'b] ['c 'd]] f)
112  
-    (is (= {"a" "b" "c" "d"}
113  
-	   (read-properties f)))))
114  
-	   
115  
-
116  
-(deftest test-delete-file
117  
-  (let [file (File/createTempFile "test" "deletion")
118  
-        not-file (File. (str (java.util.UUID/randomUUID)))]
119  
-    (delete-file (.getAbsolutePath file))
120  
-    (is (not (.exists file)))
121  
-    (is (thrown? ArithmeticException (/ 1 0)))
122  
-    (is (thrown? java.io.IOException (delete-file not-file)))
123  
-    (is (delete-file not-file :silently))))

0 notes on commit 65363bd

Please sign in to comment.
Something went wrong with that request. Please try again.