1 21 22 package nu.xom.tests; 23 24 import nu.xom.CycleException; 25 import nu.xom.IllegalAddException; 26 import nu.xom.IllegalDataException; 27 import nu.xom.IllegalNameException; 28 import nu.xom.IllegalTargetException; 29 import nu.xom.MalformedURIException; 30 import nu.xom.MultipleParentException; 31 import nu.xom.NamespaceConflictException; 32 import nu.xom.NoSuchAttributeException; 33 import nu.xom.NoSuchChildException; 34 import nu.xom.XMLException; 35 36 46 public class XMLExceptionTest extends XOMTestCase { 47 48 private XMLException ex; 49 private Exception cause; 50 private String message = "testing 1-2-3"; 51 52 public XMLExceptionTest(String name) { 53 super(name); 54 } 55 56 57 protected void setUp() { 58 ex = new XMLException("message"); 59 cause = new Exception (); 60 } 61 62 63 public void testConstructor() { 64 XMLException ex = new XMLException(message, cause); 65 assertEquals(message, ex.getMessage()); 66 assertEquals(cause, ex.getCause()); 67 } 68 69 70 public void testMalformedURIExceptionConstructor() { 71 XMLException ex = new MalformedURIException(message, cause); 72 assertEquals(message, ex.getMessage()); 73 assertEquals(cause, ex.getCause()); 74 } 75 76 77 public void testValidityExceptionConstructor() { 78 XMLException ex = new MalformedURIException(message, cause); 79 assertEquals(message, ex.getMessage()); 80 assertEquals(cause, ex.getCause()); 81 } 82 83 84 public void testNamespaceConflictExceptionConstructor() { 85 XMLException ex = new NamespaceConflictException(message, cause); 86 assertEquals(message, ex.getMessage()); 87 assertEquals(cause, ex.getCause()); 88 } 89 90 91 public void testMultipleParentExceptionConstructor() { 92 XMLException ex = new MultipleParentException(message, cause); 93 assertEquals(message, ex.getMessage()); 94 assertEquals(cause, ex.getCause()); 95 } 96 97 98 public void testNoSuchAttributeExceptionConstructor() { 99 XMLException ex = new NoSuchAttributeException(message, cause); 100 assertEquals(message, ex.getMessage()); 101 assertEquals(cause, ex.getCause()); 102 } 103 104 105 public void testNoSuchChildExceptionConstructor() { 106 XMLException ex = new NoSuchChildException(message, cause); 107 assertEquals(message, ex.getMessage()); 108 assertEquals(cause, ex.getCause()); 109 } 110 111 112 public void testCycleExceptionConstructor() { 113 XMLException ex = new CycleException(message, cause); 114 assertEquals(message, ex.getMessage()); 115 assertEquals(cause, ex.getCause()); 116 } 117 118 119 public void testIllegalNameExceptionConstructor() { 120 XMLException ex = new IllegalNameException(message, cause); 121 assertEquals(message, ex.getMessage()); 122 assertEquals(cause, ex.getCause()); 123 } 124 125 126 public void testIllegalTargetExceptionConstructor() { 127 XMLException ex = new IllegalTargetException(message, cause); 128 assertEquals(message, ex.getMessage()); 129 assertEquals(cause, ex.getCause()); 130 } 131 132 133 public void testIllegalAddExceptionConstructor() { 134 XMLException ex = new IllegalAddException(message, cause); 135 assertEquals(message, ex.getMessage()); 136 assertEquals(cause, ex.getCause()); 137 } 138 139 140 public void testIllegalDataExceptionConstructor() { 141 XMLException ex = new IllegalDataException(message, cause); 142 assertEquals(message, ex.getMessage()); 143 assertEquals(cause, ex.getCause()); 144 } 145 146 public void testInitCause() { 147 148 assertNull(ex.getCause()); 149 ex.initCause(cause); 150 assertEquals(cause, ex.getCause()); 151 152 try { 153 ex.initCause(null); 154 fail("Reinitialized cause over null"); 155 } 156 catch (IllegalStateException result) { 157 } 159 160 try { 161 ex.initCause(new Exception ()); 162 fail("Reinitialized cause over null"); 163 } 164 catch (IllegalStateException result) { 165 } 167 168 } 169 170 171 public void testNullInitCause() { 172 173 ex = new XMLException(null, null); 174 assertNull(ex.getCause()); 175 176 try { 177 ex.initCause(new Exception ()); 178 fail("Reinitialized cause over null"); 179 } 180 catch (IllegalStateException result) { 181 } 183 184 try { 185 ex.initCause(null); 186 fail("Reinitialized cause over null"); 187 } 188 catch (IllegalStateException result) { 189 } 191 192 } 193 194 195 public void testSelfCause() { 196 197 try { 198 ex.initCause(ex); 199 fail("Allowed self-causation"); 200 } 201 catch (IllegalArgumentException result) { 202 } 204 205 } 206 207 208 public void testGetMessage() { 209 Exception ex = new XMLException("testing"); 210 assertEquals("testing", ex.getMessage()); 211 } 212 213 214 } 215 | Popular Tags |