Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

alternate verify method idea, comments?

  • Loading branch information...
commit ae5dd362bbda8301e5d9f01c2ba458b4ccbc4ed1 1 parent d6458dd
@dakrone dakrone authored
Showing with 30 additions and 1 deletion.
  1. +13 −1 src/org/dipert/mockito.clj
  2. +17 −0 test/org/dipert/mockito_test.clj
View
14 src/org/dipert/mockito.clj
@@ -15,6 +15,7 @@
:throwing `(.thenThrow ~result)
:returning `(.thenReturn ~result))))
+
(defmacro verify
"Verifies that call(s) were made to mocked"
([mocked call]
@@ -22,4 +23,15 @@
(list* method `(Mockito/verify ~mocked) args)))
([mocked call & more]
(let [calls (list* call more)]
- `(do ~@(map #(list `verify `~mocked %) calls)))))
+ `(do ~@(map #(list `verify `~mocked %) calls)))))
+
+
+; Allows (verify-2 klass add "one") => (.add (org.mockito.Mockito/verify klass) "one")
+; (verify-2 klass clear) => (.clear (org.mockito.Mockito/verify klass))
+
+(defmacro verify-2
+ "Verifies that call(s) were made to mocked"
+ [mocked call & args]
+ (if (nil? args)
+ (list* (symbol (str \. call)) `((Mockito/verify ~mocked)))
+ (list* (symbol (str \. call)) `(Mockito/verify ~mocked) args)))
View
17 test/org/dipert/mockito_test.clj
@@ -0,0 +1,17 @@
+(ns org.dipert.mockito-test
+ (:use [clojure.test])
+ (:require [org.dipert.mockito :as mockito])
+ (:import [java.util ArrayList]))
+
+(deftest test-stub-method
+ (let [mocklist (mockito/mock java.util.ArrayList)]
+ (mockito/stub-method mocklist get [0] :returning "first")
+ (is (= (.get mocklist 0)
+ "first"))))
+
+(deftest test-verify
+ (let [mocklist (mockito/mock java.util.ArrayList)]
+ (.add mocklist "one")
+ (.clear mocklist)
+ (mockito/verify-2 mocklist add "one")
+ (mockito/verify-2 mocklist clear)))
Please sign in to comment.
Something went wrong with that request. Please try again.