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