testLogicalDoc = new LogicalDocumentImpl(-4); assertTrue(testLogicalDoc==null); In my code above, I have an assert condition with which I want to make sure I don't create my object with negative size. It is a stringBuilder beneath the covers which throws NegativeArrayBoundsException for a size less than zero. But my junit test fails here. I don't know any other way of making sure an object is not created with a negative size. Any thoughts on how this could be tested ? or should it be a Junit test at all ??
Many thanks,
-Pan
EDIT:
@Test(expected=NegativeArraySizeException.class) public void testCreate4b() { LogicalDocumentImpl testLogicalDoc = new LogicalDocumentImpl(-4); } I'm catching the exception in the LogicalDocumentImpl class but still this test fails with an assertion error but only succeeds when I do a try catch on assertion error ..why is that so ??