Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 318   Methods: 22
NCLOC: 197   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XMLTestCaseT.java 100% 98.3% 100% 98.6%
coverage coverage
 1   
 package junit.extensions.xml;
 2   
 
 3   
 import java.util.Arrays;
 4   
 import java.util.List;
 5   
 
 6   
 import org.w3c.dom.Element;
 7   
 import junit.extensions.xml.elements.ElementFixture;
 8   
 import junit.framework.TestCase;
 9   
 
 10   
 /**
 11   
  * <p>Title: Test the XMLTestCase.</p>
 12   
  * <p>Copyright: Copyright (c) 2003</p>
 13   
  * <p>Company: JFCUnit OpenSource Project</p>
 14   
  * @author Kevin Wilson
 15   
  * @version 1.0
 16   
  */
 17   
 public class XMLTestCaseT extends TestCase {
 18   
   /**
 19   
    * Testcase to be tested.
 20   
    */
 21   
   private XMLTestCase m_xmlTestCase = null;
 22   
   /**
 23   
    * main element fixture.
 24   
    */
 25   
   private ElementFixture m_fixture;
 26   
   /**
 27   
    * Secondary element fixture.
 28   
    */
 29   
   private ElementFixture m_fixture2 = null;
 30   
 
 31   
   /**
 32   
    * Setup the test case.
 33   
    * @throws Exception may be thrown.
 34   
    */
 35  19
   protected void setUp() throws Exception {
 36  19
     super.setUp();
 37  19
     m_fixture = new ElementFixture(this);
 38  19
     m_fixture.setUp();
 39  19
     m_xmlTestCase = new XMLTestCase("test", m_fixture.getTestElement());
 40   
   }
 41   
 
 42   
   /**
 43   
    * Setup the secondary fixture.
 44   
    */
 45  1
   protected void setUpEf2() {
 46  1
     m_fixture2 = new ElementFixture(this);
 47  1
     m_fixture2.setUp();
 48   
   }
 49   
 
 50   
   /**
 51   
    * Teardown the test case.
 52   
    * @throws Exception may be thrown.
 53   
    */
 54  19
   protected void tearDown() throws Exception {
 55  19
     m_xmlTestCase = null;
 56  19
     m_fixture.tearDown();
 57  19
     m_fixture = null;
 58  19
     if (m_fixture2 != null) {
 59  1
       m_fixture2.tearDown();
 60  1
       m_fixture2 = null;
 61   
     }
 62  19
     super.tearDown();
 63   
   }
 64   
 
 65   
   /**
 66   
    * Test the constructor.
 67   
    */
 68  1
   public void testXMLTestCase() {
 69  1
     String filename = "test";
 70  1
     Element element = m_fixture.getTestElement();
 71  1
     m_xmlTestCase = new XMLTestCase(filename, element);
 72   
   }
 73   
 
 74   
   /**
 75   
    * Test adding a procedure.
 76   
    */
 77  1
   public void testAddProcedure() {
 78  1
     Element suite = m_fixture.getSuiteElement();
 79  1
     Element procedure = m_fixture.newChild(suite, "procedure",
 80   
                             new String[] {
 81   
                             "name", "abc"
 82   
                             });
 83  1
     XMLProcedure proc = new XMLProcedure(procedure);
 84  1
     m_xmlTestCase.addProcedure(proc);
 85   
   }
 86   
 
 87   
   /**
 88   
    * Test adding a property.
 89   
    */
 90  1
   public void testAddProperty() {
 91  1
     String name = "abc";
 92  1
     Object obj = "def";
 93  1
     m_xmlTestCase.addProperty(name, obj);
 94  1
     Object o = m_xmlTestCase.getProperty(name);
 95  1
     assertEquals("value", obj, o);
 96   
   }
 97   
 
 98   
   /**
 99   
    * Test calling a procedure.
 100   
    * @throws XMLException may be thrown.
 101   
    */
 102  1
   public void testCallProcedure() throws XMLException {
 103  1
     Element suite = m_fixture.getSuiteElement();
 104  1
     Element test = m_fixture.getTestElement();
 105  1
     m_xmlTestCase = new XMLTestCase("test", test);
 106  1
     Element call = m_fixture.newElement("procedure",
 107   
                                              new String[] {
 108   
                                              "call", "abc",
 109   
                                              "test", "success"
 110   
                                              });
 111  1
     Element procedure = m_fixture.newChild(suite, "procedure",
 112   
                             new String[] {
 113   
                             "name", "abc"
 114   
                             });
 115  1
     m_fixture.newChild(procedure, "property", new String[] {
 116   
                             "name", "../abc",
 117   
                             "value", "test"
 118   
     });
 119  1
     XMLProcedure proc = new XMLProcedure(procedure);
 120  1
     m_xmlTestCase.addProcedure(proc);
 121  1
     m_xmlTestCase.callProcedure("abc", call);
 122   
 
 123  1
     Object o = m_xmlTestCase.getProperty("abc");
 124  1
     assertEquals("test", o);
 125   
   }
 126   
 
 127   
   /**
 128   
    * Test clearing the properties.
 129   
    */
 130  1
   public void testClearProperties() {
 131  1
     m_xmlTestCase.addProperty("Abc", "def");
 132  1
     m_xmlTestCase.clearProperties();
 133  1
     int size = m_xmlTestCase.getPropertyNames().length;
 134  1
     assertEquals(0, size);
 135   
   }
 136   
 
 137   
   /**
 138   
    * Test getDebug().
 139   
    */
 140  1
   public void testGetDebug() {
 141  1
     boolean expectedReturn = false;
 142  1
     boolean actualReturn = m_xmlTestCase.getDebug();
 143  1
     assertEquals("return value", expectedReturn, actualReturn);
 144   
 
 145  1
     m_xmlTestCase.addProperty("debug", "false");
 146  1
     actualReturn = m_xmlTestCase.getDebug();
 147  1
     assertEquals("return value", expectedReturn, actualReturn);
 148   
 
 149  1
     m_xmlTestCase.addProperty("debug", Boolean.FALSE);
 150  1
     actualReturn = m_xmlTestCase.getDebug();
 151  1
     assertEquals("return value", expectedReturn, actualReturn);
 152   
 
 153  1
     expectedReturn = true;
 154  1
     m_xmlTestCase.addProperty("debug", "true");
 155  1
     actualReturn = m_xmlTestCase.getDebug();
 156  1
     assertEquals("return value", expectedReturn, actualReturn);
 157   
 
 158  1
     m_xmlTestCase.addProperty("debug", Boolean.TRUE);
 159  1
     actualReturn = m_xmlTestCase.getDebug();
 160  1
     assertEquals("return value", expectedReturn, actualReturn);
 161   
   }
 162   
 
 163   
   /**
 164   
    * Test getProcedure.
 165   
    */
 166  1
   public void testGetProcedure() {
 167  1
     String name = "";
 168  1
     IXMLProcedure expectedReturn = null;
 169  1
     IXMLProcedure actualReturn = m_xmlTestCase.getProcedure(name);
 170  1
     assertEquals("return value", expectedReturn, actualReturn);
 171   
   }
 172   
 
 173   
   /**
 174   
    * Test getProcedureCache().
 175   
    */
 176  1
   public void testGetProcedureCache() {
 177  1
     XMLObjectCache actualReturn = m_xmlTestCase.getProcedureCache();
 178  1
     assertNotNull("return value", actualReturn);
 179   
   }
 180   
 
 181   
   /**
 182   
    * Test getProperty().
 183   
    */
 184  1
   public void testGetProperty() {
 185  1
     String name = "Abc";
 186  1
     Object expectedReturn = "value";
 187  1
     m_xmlTestCase.addProperty(name, expectedReturn);
 188  1
     Object actualReturn = m_xmlTestCase.getProperty(name);
 189  1
     assertEquals("return value", expectedReturn, actualReturn);
 190   
   }
 191   
 
 192   
   /**
 193   
    * Test getPropertyCache.
 194   
    */
 195  1
   public void testGetPropertyCache() {
 196  1
     XMLObjectCache actualReturn = m_xmlTestCase.getPropertyCache();
 197  1
     assertNotNull("return value", actualReturn);
 198   
   }
 199   
 
 200   
   /**
 201   
    * Test getPropertyName().
 202   
    */
 203  1
   public void testGetPropertyName() {
 204  1
     m_xmlTestCase.addProperty("abc", "def");
 205  1
     m_xmlTestCase.addProperty("def", "ghi");
 206  1
     Object comp = "ghi";
 207  1
     String expectedReturn = "def";
 208  1
     String actualReturn = m_xmlTestCase.getPropertyName(comp);
 209  1
     assertEquals("return value", expectedReturn, actualReturn);
 210   
   }
 211   
 
 212   
   /**
 213   
    * test getPropertyNames().
 214   
    */
 215  1
   public void testGetPropertyNames() {
 216  1
     m_xmlTestCase.addProperty("abc", "def");
 217  1
     m_xmlTestCase.addProperty("def", "ghi");
 218  1
     String[] expectedReturn = new String[] {"abc", "def"};
 219  1
     String[] actualReturn = m_xmlTestCase.getPropertyNames();
 220  1
     List l = Arrays.asList(actualReturn);
 221  1
     assertEquals("return value", expectedReturn.length, actualReturn.length);
 222  1
     for (int i = 0; i < expectedReturn.length; i++) {
 223  2
       boolean val = l.contains(expectedReturn[i]);
 224  2
       assertTrue("does not contain:" + expectedReturn[i], val);
 225   
     }
 226   
   }
 227   
 
 228   
   /**
 229   
    * Test process children.
 230   
    * @throws XMLException may thrown exception.
 231   
    */
 232  1
   public void testProcessChildren() throws XMLException {
 233  1
     Element element = m_fixture.newElement("property",
 234   
                                                 new String[] {
 235   
                                                 "name", "prop",
 236   
                                                 "value", "success"
 237   
     });
 238   
 
 239  1
     m_xmlTestCase.processChildren(m_fixture.getTestElement());
 240  1
     Object o = m_xmlTestCase.getProperty("prop");
 241  1
     assertEquals("success", o);
 242   
   }
 243   
 
 244   
   /**
 245   
    * Test removeProperty().
 246   
    */
 247  1
   public void testRemoveProperty() {
 248  1
     String name = "test";
 249  1
     m_xmlTestCase.addProperty(name, "AB");
 250  1
     Object o = m_xmlTestCase.getProperty(name);
 251  1
     assertNotNull("Value should be set", o);
 252  1
     m_xmlTestCase.removeProperty(name);
 253  1
     o = m_xmlTestCase.getProperty(name);
 254  1
     assertNull("Value should not be set", o);
 255   
   }
 256   
 
 257   
   /**
 258   
    * Test resolveProperties().
 259   
    */
 260  1
   public void testResolveProperties() {
 261  1
     String s = "a";
 262  1
     String expectedReturn = "a";
 263  1
     String actualReturn = m_xmlTestCase.resolveProperties(s);
 264  1
     assertEquals("return value", expectedReturn, actualReturn);
 265   
   }
 266   
 
 267   
   /**
 268   
    * Test resolveProperties().
 269   
    */
 270  1
   public void testResolveProperties2() {
 271  1
     m_xmlTestCase.addProperty("test", "a");
 272  1
     String s = "${test}";
 273  1
     String expectedReturn = "a";
 274  1
     String actualReturn = m_xmlTestCase.resolveProperties(s);
 275  1
     assertEquals("return value", expectedReturn, actualReturn);
 276   
   }
 277   
 
 278   
 
 279   
 
 280   
   /**
 281   
    * Test setParent().
 282   
    */
 283  1
   public void testSetParent() {
 284   
 
 285  1
     setUpEf2();
 286  1
     IXMLTest parent = m_fixture2.getTestCase();
 287  1
     m_xmlTestCase.setParent(parent);
 288   
   }
 289   
 
 290   
   /**
 291   
    * Test runBare().
 292   
    */
 293  1
   public void testRunBare() {
 294  1
     Throwable t = null;
 295  1
     try {
 296  1
       m_xmlTestCase.runBare();
 297   
     } catch (Throwable ex) {
 298  0
       t = ex;
 299   
     }
 300  1
     assertNull(t);
 301   
   }
 302   
 
 303   
   /**
 304   
    * Test runBare with debug.
 305   
    */
 306  1
   public void testRunBareDebug() {
 307  1
     Throwable t = null;
 308  1
     try {
 309  1
       Element e = m_fixture.getTestElement();
 310  1
       e.setAttribute("debug", "true");
 311  1
       m_xmlTestCase.runBare();
 312   
     } catch (Throwable ex) {
 313  0
       t = ex;
 314   
     }
 315  1
     assertNull(t);
 316   
   }
 317   
 }
 318