You will need to do this the old fashioned way:
@Test public void testRodneCisloRok() { try { new RodneCislo("891415",dopocitej("891415")); fail("expected an exception"); } catch (IllegalArgumentException ex) { assertEquals("error1", ex.getMessage()); } }
The syntax @Test(expected=...) convenient, but in many cases it is too simple.
If it is important to distinguish between exception conditions, you might consider creating a hierarchy of exception classes that can be caught on purpose. In this case, subclassing IllegalArgumentException might be a good idea. This is arguably the best design, and your test may catch this particular type of exception.
skaffman Mar 14 '10 at 22:31 2010-03-14 22:31
source share