Clover coverage report - Clover results for XOM 1.2d1
Coverage timestamp: Wed Feb 8 2006 08:31:33 EST
file stats: LOC: 170   Methods: 9
NCLOC: 100   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XPathExceptionTest.java - 85.7% 100% 87.9%
coverage coverage
 1    /* Copyright 2005 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.ByteArrayOutputStream;
 25    import java.io.IOException;
 26    import java.io.ObjectOutputStream;
 27   
 28    import nu.xom.Element;
 29    import nu.xom.XPathException;
 30    import nu.xom.XPathTypeException;
 31   
 32    /**
 33    * <p>
 34    * Unit tests for the <code>XPathException</code> class.
 35    * </p>
 36    *
 37    * @author Elliotte Rusty Harold
 38    * @version 1.1b4
 39    *
 40    */
 41    public class XPathExceptionTest extends XOMTestCase {
 42   
 43   
 44    private XPathException ex;
 45    private Exception cause;
 46   
 47   
 48  7 public XPathExceptionTest(String name) {
 49  7 super(name);
 50    }
 51   
 52   
 53  7 protected void setUp() {
 54  7 ex = new XPathException("message");
 55  7 cause = new Exception();
 56    }
 57   
 58   
 59  1 public void testConstructor() {
 60  1 String message = "testing 1-2-3";
 61  1 XPathException ex = new XPathException(message, cause);
 62  1 assertEquals(message, ex.getMessage());
 63  1 assertEquals(cause, ex.getCause());
 64    }
 65   
 66   
 67  1 public void testInitCause() {
 68   
 69  1 assertNull(ex.getCause());
 70  1 ex.initCause(cause);
 71  1 assertEquals(cause, ex.getCause());
 72   
 73  1 try {
 74  1 ex.initCause(null);
 75  0 fail("Reinitialized cause over null");
 76    }
 77    catch (IllegalStateException success) {
 78  1 assertNotNull(success.getMessage());
 79    }
 80   
 81  1 try {
 82  1 ex.initCause(new Exception());
 83  0 fail("Reinitialized cause over null");
 84    }
 85    catch (IllegalStateException success) {
 86  1 assertNotNull(success.getMessage());
 87    }
 88   
 89    }
 90   
 91   
 92  1 public void testNullInitCause() {
 93   
 94  1 XPathException ex = new XPathException(null, null);
 95  1 assertNull(ex.getCause());
 96   
 97  1 try {
 98  1 ex.initCause(new Exception());
 99  0 fail("Reinitialized cause over null");
 100    }
 101    catch (IllegalStateException success) {
 102  1 assertNotNull(success.getMessage());
 103    }
 104   
 105  1 try {
 106  1 ex.initCause(null);
 107  0 fail("Reinitialized cause over null");
 108    }
 109    catch (IllegalStateException success) {
 110  1 assertNotNull(success.getMessage());
 111    }
 112   
 113    }
 114   
 115   
 116  1 public void testSelfCause() {
 117   
 118  1 try {
 119  1 ex.initCause(ex);
 120  0 fail("Allowed self-causation");
 121    }
 122    catch (IllegalArgumentException success) {
 123  1 assertNotNull(success.getMessage());
 124    }
 125   
 126    }
 127   
 128   
 129  1 public void testGetMessage() {
 130  1 Exception ex = new XPathException("testing");
 131  1 assertEquals("testing", ex.getMessage());
 132    }
 133   
 134  1 public void testGetXPathExpression() {
 135   
 136  1 Element parent = new Element("Test");
 137   
 138  1 try {
 139  1 parent.query("This is not an XPath expression");
 140  0 fail("Allowed malformed query");
 141    }
 142    catch (XPathException success) {
 143  1 assertEquals(
 144    "This is not an XPath expression", success.getXPath());
 145    }
 146   
 147    }
 148   
 149  1 public void testSerializeXPathTypeException() throws IOException {
 150   
 151  1 Element parent = new Element("Test");
 152  1 Element child = new Element("child");
 153  1 parent.appendChild(child);
 154   
 155  1 try {
 156  1 parent.query("count(*)");
 157  0 fail("Allowed query to return number");
 158    }
 159    catch (XPathTypeException success) {
 160  1 ByteArrayOutputStream out = new ByteArrayOutputStream();
 161  1 ObjectOutputStream oout = new ObjectOutputStream(out);
 162  1 oout.writeObject(success);
 163  1 oout.close();
 164    }
 165   
 166    }
 167   
 168   
 169   
 170    }