Reputation: 27196
This works for me :
(is (thrown? AbstractMethodError (.fun obj 1) ))
But this blows up
(is (not (thrown? AbstractMethodError (.fun obj 1) )))
with the following error :
java.lang.RuntimeException: Unable to resolve symbol: thrown? in this context
Presumably "thrown?" has some special meaning inside the "is" and isn't visible when I put the "not" in the way.
So how can I test a negation of an assertion like thrown?
Upvotes: 5
Views: 679
Reputation: 13079
You're correct, thrown?
is a special assertion that must appear after is
. If you want to test that an exception is not thrown (in other words, the call evaluated to something), you might want to do something like:
(is (.fun obj 1))
although that has one problem: it would fail if the result is falsey (false, nil). To be completely sure:
(let [r (.fun obj 1)]
(is (= r r)))
(this is a tautology, and will only fail if it does throw an exception).
Upvotes: 5