Clover coverage report - Clover results for XOM 1.2d1
Coverage timestamp: Wed Feb 8 2006 08:31:33 EST
file stats: LOC: 227   Methods: 19
NCLOC: 139   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XMLExceptionTest.java - 92.5% 100% 94.2%
coverage coverage
 1    /* Copyright 2003, 2004 Elliotte Rusty Harold
 2   
 3    This library is free software; you can redistribute it and/or modify
 4    it under the terms of version 2.1 of the GNU Lesser General Public
 5    License as published by the Free Software Foundation.
 6   
 7    This library is distributed in the hope that it will be useful,
 8    but WITHOUT ANY WARRANTY; without even the implied warranty of
 9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 10    GNU Lesser General Public License for more details.
 11   
 12    You should have received a copy of the GNU Lesser General Public
 13    License along with this library; if not, write to the
 14    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 15    Boston, MA 02111-1307 USA
 16   
 17    You can contact Elliotte Rusty Harold by sending e-mail to
 18    elharo@metalab.unc.edu. Please include the word "XOM" in the
 19    subject line. The XOM home page is located at http://www.xom.nu/
 20    */
 21   
 22    package nu.xom.tests;
 23   
 24    import java.io.PrintWriter;
 25    import java.io.StringWriter;
 26   
 27    import nu.xom.CycleException;
 28    import nu.xom.IllegalAddException;
 29    import nu.xom.IllegalDataException;
 30    import nu.xom.IllegalNameException;
 31    import nu.xom.IllegalTargetException;
 32    import nu.xom.MalformedURIException;
 33    import nu.xom.MultipleParentException;
 34    import nu.xom.NamespaceConflictException;
 35    import nu.xom.NoSuchAttributeException;
 36    import nu.xom.NoSuchChildException;
 37    import nu.xom.XMLException;
 38   
 39    /**
 40    * <p>
 41    * This class provides unit tests for the <code>XMLException</code>
 42    * class.
 43    * </p>
 44    *
 45    * @author Elliotte Rusty Harold
 46    * @version 1.1b2
 47    *
 48    */
 49    public class XMLExceptionTest extends XOMTestCase {
 50   
 51    private XMLException ex;
 52    private Exception cause;
 53    private String message = "testing 1-2-3";
 54   
 55  17 public XMLExceptionTest(String name) {
 56  17 super(name);
 57    }
 58   
 59   
 60  17 protected void setUp() {
 61  17 ex = new XMLException("message");
 62  17 cause = new Exception();
 63    }
 64   
 65   
 66  1 public void testConstructor() {
 67  1 XMLException ex = new XMLException(message, cause);
 68  1 assertEquals(message, ex.getMessage());
 69  1 assertEquals(cause, ex.getCause());
 70    }
 71   
 72   
 73  1 public void testPrintStackTrace() {
 74  1 XMLException ex = new XMLException(message, cause);
 75  1 StringWriter out = new StringWriter();
 76  1 PrintWriter pw = new PrintWriter(out);
 77  1 ex.printStackTrace(pw);
 78  1 pw.close();
 79  1 assertTrue(out.toString().indexOf("Caused by: ") > 0);
 80    }
 81   
 82   
 83  1 public void testMalformedURIExceptionConstructor() {
 84  1 XMLException ex = new MalformedURIException(message, cause);
 85  1 assertEquals(message, ex.getMessage());
 86  1 assertEquals(cause, ex.getCause());
 87    }
 88   
 89   
 90  1 public void testValidityExceptionConstructor() {
 91  1 XMLException ex = new MalformedURIException(message, cause);
 92  1 assertEquals(message, ex.getMessage());
 93  1 assertEquals(cause, ex.getCause());
 94    }
 95   
 96   
 97  1 public void testNamespaceConflictExceptionConstructor() {
 98  1 XMLException ex = new NamespaceConflictException(message, cause);
 99  1 assertEquals(message, ex.getMessage());
 100  1 assertEquals(cause, ex.getCause());
 101    }
 102   
 103   
 104  1 public void testMultipleParentExceptionConstructor() {
 105  1 XMLException ex = new MultipleParentException(message, cause);
 106  1 assertEquals(message, ex.getMessage());
 107  1 assertEquals(cause, ex.getCause());
 108    }
 109   
 110   
 111  1 public void testNoSuchAttributeExceptionConstructor() {
 112  1 XMLException ex = new NoSuchAttributeException(message, cause);
 113  1 assertEquals(message, ex.getMessage());
 114  1 assertEquals(cause, ex.getCause());
 115    }
 116   
 117   
 118  1 public void testNoSuchChildExceptionConstructor() {
 119  1 XMLException ex = new NoSuchChildException(message, cause);
 120  1 assertEquals(message, ex.getMessage());
 121  1 assertEquals(cause, ex.getCause());
 122    }
 123   
 124   
 125  1 public void testCycleExceptionConstructor() {
 126  1 XMLException ex = new CycleException(message, cause);
 127  1 assertEquals(message, ex.getMessage());
 128  1 assertEquals(cause, ex.getCause());
 129    }
 130   
 131   
 132  1 public void testIllegalNameExceptionConstructor() {
 133  1 XMLException ex = new IllegalNameException(message, cause);
 134  1 assertEquals(message, ex.getMessage());
 135  1 assertEquals(cause, ex.getCause());
 136    }
 137   
 138   
 139  1 public void testIllegalTargetExceptionConstructor() {
 140  1 XMLException ex = new IllegalTargetException(message, cause);
 141  1 assertEquals(message, ex.getMessage());
 142  1 assertEquals(cause, ex.getCause());
 143    }
 144   
 145   
 146  1 public void testIllegalAddExceptionConstructor() {
 147  1 XMLException ex = new IllegalAddException(message, cause);
 148  1 assertEquals(message, ex.getMessage());
 149  1 assertEquals(cause, ex.getCause());
 150    }
 151   
 152   
 153  1 public void testIllegalDataExceptionConstructor() {
 154  1 XMLException ex = new IllegalDataException(message, cause);
 155  1 assertEquals(message, ex.getMessage());
 156  1 assertEquals(cause, ex.getCause());
 157    }
 158   
 159  1 public void testInitCause() {
 160   
 161  1 assertNull(ex.getCause());
 162  1 ex.initCause(cause);
 163  1 assertEquals(cause, ex.getCause());
 164   
 165  1 try {
 166  1 ex.initCause(null);
 167  0 fail("Reinitialized cause over null");
 168    }
 169    catch (IllegalStateException result) {
 170    // success
 171    }
 172   
 173  1 try {
 174  1 ex.initCause(new Exception());
 175  0 fail("Reinitialized cause over null");
 176    }
 177    catch (IllegalStateException result) {
 178    // success
 179    }
 180   
 181    }
 182   
 183   
 184  1 public void testNullInitCause() {
 185   
 186  1 ex = new XMLException(null, null);
 187  1 assertNull(ex.getCause());
 188   
 189  1 try {
 190  1 ex.initCause(new Exception());
 191  0 fail("Reinitialized cause over null");
 192    }
 193    catch (IllegalStateException result) {
 194    // success
 195    }
 196   
 197  1 try {
 198  1 ex.initCause(null);
 199  0 fail("Reinitialized cause over null");
 200    }
 201    catch (IllegalStateException result) {
 202    // success
 203    }
 204   
 205    }
 206   
 207   
 208  1 public void testSelfCause() {
 209   
 210  1 try {
 211  1 ex.initCause(ex);
 212  0 fail("Allowed self-causation");
 213    }
 214    catch (IllegalArgumentException result) {
 215    // success
 216    }
 217   
 218    }
 219   
 220   
 221  1 public void testGetMessage() {
 222  1 Exception ex = new XMLException("testing");
 223  1 assertEquals("testing", ex.getMessage());
 224    }
 225   
 226   
 227    }