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