Permalink
Browse files

Switch to implementing ILookup.

  • Loading branch information...
1 parent 0ad4ca1 commit 06df742ef5cc422bf421024e4139a369bb81763a @technomancy committed Jun 10, 2011
Showing with 26 additions and 15 deletions.
  1. +1 −0 .gitignore
  2. +13 −15 src/dce/Exception.clj
  3. +12 −0 test/dce/test/exception.clj
View
@@ -3,3 +3,4 @@ pom.xml
/lib/
/classes/
.lein-deps-sum
+/.lein-failures
View
@@ -1,22 +1,20 @@
(ns dce.Exception
(:gen-class :extends RuntimeException
- :state payload
+ :implements [clojure.lang.ILookup]
+ :state data
:init init
- :constructors {[String Throwable clojure.lang.Keyword
- java.util.Map]
- [String Throwable]
- [String clojure.lang.Keyword java.util.Map]
- [String]
- [clojure.lang.Keyword java.util.Map]
- []}))
+ :constructors {[java.util.Map]
+ [String Throwable]}))
(defn -init
- ([message cause type data]
- [[message cause] (vary-meta data assoc :type type)])
- ([message type data]
- [[message] (vary-meta data assoc :type type)])
- ([type data]
- [[] (vary-meta data assoc :type type)]))
+ ([{:keys [message cause] :as data}]
+ [[message cause] data]))
+
+(defn -valAt
+ ([self key]
+ (.valAt (.data self) key))
+ ([self key not-found]
+ (.valAt (.data self) key not-found)))
(defn -toString [e]
- (print-str (.getMessage e) (.payload e)))
+ (.toString (.data e)))
@@ -0,0 +1,12 @@
+(ns dce.test.exception
+ (:use [clojure.test]))
+
+(deftest test-constructing
+ (is (instance? dce.Exception (dce.Exception. {}))))
+
+(deftest test-get
+ (is (:data-conveying (dce.Exception. {:data-conveying true}))))
+
+(deftest test-str
+ (is (= (str {:data-conveying true})
+ (str (dce.Exception. {:data-conveying true})))))

0 comments on commit 06df742

Please sign in to comment.