1 21 22 package nu.xom.tests; 23 24 import nu.xom.ParsingException; 25 import nu.xom.ValidityException; 26 27 36 public class ValidityExceptionTest extends XOMTestCase { 37 38 39 private ValidityException ex = new ValidityException("message"); 40 private Exception cause = new Exception (); 41 private String message = "testing 1-2-3"; 42 43 44 public ValidityExceptionTest(String name) { 45 super(name); 46 } 47 48 49 public void testConstructor() { 50 ParsingException ex = new ValidityException(message, cause); 51 assertEquals(message, ex.getMessage()); 52 assertEquals(cause, ex.getCause()); 53 } 54 55 56 public void testFourArgumentConstructor() { 57 58 ParsingException ex = new ValidityException(message, 10000, 40000, cause); 59 assertEquals(message, ex.getMessage()); 60 assertEquals(cause, ex.getCause()); 61 assertEquals(10000, ex.getLineNumber()); 62 assertEquals(40000, ex.getColumnNumber()); 63 64 } 65 66 67 public void testAnotherFourArgumentConstructor() { 68 69 ParsingException ex = new ValidityException( 70 message, "http://www.example.com/", 10000, 40000); 71 assertEquals(message, ex.getMessage()); 72 assertNull(ex.getCause()); 73 assertEquals(10000, ex.getLineNumber()); 74 assertEquals(40000, ex.getColumnNumber()); 75 assertEquals("http://www.example.com/", ex.getURI()); 76 77 } 78 79 80 public void testLineAndColumnNumbers() { 81 82 ValidityException ex = new ValidityException(message, 10, 20); 83 assertEquals(message, ex.getMessage()); 84 assertNull(ex.getCause()); 85 assertEquals(10, ex.getLineNumber()); 86 assertEquals(20, ex.getColumnNumber()); 87 88 } 89 90 91 public void testInitCause() { 92 93 assertNull(ex.getCause()); 94 ex.initCause(cause); 95 assertEquals(cause, ex.getCause()); 96 97 try { 98 ex.initCause(null); 99 fail("Reinitialized cause over null"); 100 } 101 catch (IllegalStateException success) { 102 } 104 105 try { 106 ex.initCause(new Exception ()); 107 fail("Reinitialized cause over null"); 108 } 109 catch (IllegalStateException success) { 110 } 112 113 } 114 115 116 public void testNullInitCause() { 117 118 ValidityException ex = new ValidityException(null, null); 119 assertNull(ex.getCause()); 120 assertNull(ex.getMessage()); 121 assertEquals(-1, ex.getLineNumber()); 122 assertEquals(-1, ex.getColumnNumber()); 123 124 try { 125 ex.initCause(new Exception ()); 126 fail("Reinitialized cause over null"); 127 } 128 catch (IllegalStateException result) { 129 } 131 132 try { 133 ex.initCause(null); 134 fail("Reinitialized cause over null"); 135 } 136 catch (IllegalStateException result) { 137 } 139 140 } 141 142 143 public void testSelfCause() { 144 145 try { 146 ex.initCause(ex); 147 fail("Allowed self-causation"); 148 } 149 catch (IllegalArgumentException result) { 150 } 152 153 } 154 155 156 public void testGetMessage() { 157 Exception ex = new ValidityException("testing"); 158 assertEquals("testing", ex.getMessage()); 159 } 160 161 162 } 163 | Popular Tags |