I haven't used the library myself, but it seems reasonably clear why your usage would fail: your code for the first statement is equivalent to:
Operation op = new Operation("" , ".");
verifyException(op, IllegalArgumentException.class);
Think about it - the first line of that is going to throw the exception, so there's nothing the second line can do about it.
As far as I can tell, verifyException
is designed to return something you can then call a "bad" operation on, and the returned fake will delegate the call and check the exception appropriately. I can't see how this would work for constructor calls, basically.
Indeed, the documentation you linked to explicitly states that:
Catch-exception does not provide an API to to catch exceptions that are thrown by constructors. Use try-catch-blocks instead. Alternatively, you can use the builder pattern if this makes sense anyway for your application
(Then there's an example.)
I strongly expect that with Java 8 bringing lambda expressions to Java, unit test frameworks will start using those so you'll be able to write something like:
// Not valid yet as far as I know! (But likely to be coming to a test framework
// near you soon...)
assertThrows(IllegalArgumentException.class, () -> new Operation("", "."));