diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2009-04-05 16:02:37 +0000 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2009-04-05 16:02:37 +0000 |
commit | 47024875854f8bed0301f9927d7faa6e0e83b595 (patch) | |
tree | c7daeb1071a26f59ceed2416a34f7914536f0a9e /src/clojure/contrib/test_contrib/test_java_utils.clj | |
parent | 57571874b35cd8df77ccdc96a4e158c74478280e (diff) |
java-util: the-str and with-system-properties
Diffstat (limited to 'src/clojure/contrib/test_contrib/test_java_utils.clj')
-rw-r--r-- | src/clojure/contrib/test_contrib/test_java_utils.clj | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/clojure/contrib/test_contrib/test_java_utils.clj b/src/clojure/contrib/test_contrib/test_java_utils.clj index 9c536322..427babca 100644 --- a/src/clojure/contrib/test_contrib/test_java_utils.clj +++ b/src/clojure/contrib/test_contrib/test_java_utils.clj @@ -31,6 +31,51 @@ (testing "no sneaking in absolute paths!" (is (thrown? IllegalArgumentException (file "foo" "bar" "/boom" "baz" "quux")))) ) + +(deftest test-the-str + (testing "keyword to string" + (is (= "foo") (the-str :foo))) + (testing "symbol to string" + (is (= "foo") (the-str 'foo))) + (testing "string to string" + (is (= "foo") (the-str "foo"))) + (testing "stringifying non-namish things" + (is (= "42") (the-str 42))) +) + +(deftest test-get-system-property + (testing "works the same with keywords, symbols, and strings" + (is (= (get-system-property "java.home") (get-system-property 'java.home))) + (is (= (get-system-property "java.home") (get-system-property :java.home)))) +) + +(deftest test-set-system-properties + (testing "set and then unset a property" + (let [propname :clojure.contrib.java-utils.test-set-system-properties] + (is (nil? (get-system-property propname))) + (set-system-properties {propname "foo"}) + (is (= "foo") (get-system-property propname)) + (set-system-properties {propname nil}) + (is (nil? (get-system-property propname))))) +) + +(deftest test-with-system-properties + (let [propname :clojure.contrib.java-utils.test-with-system-properties] + (testing "sets a property only for the duration of a block" + (is (= "foo" + (with-system-properties {propname "foo"} + (get-system-property propname)))) + (is (nil? (get-system-property propname))))) + (testing "leaves other properties alone" + ; TODO: write this test better, using a properties -> map function + (let [propname :clojure.contrib.java-utils.test-with-system-properties + propcount (count (System/getProperties))] + (with-system-properties {propname "foo"} + (is (= (inc propcount) (count (System/getProperties))))) + (is (= propcount (count (System/getProperties)))))) +) + + |