Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 141   Methods: 5
NCLOC: 83   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TokenizeTagHandlerT.java - 100% 100% 100%
coverage
 1   
 package junit.extensions.xml.elements;
 2   
 
 3   
 import org.w3c.dom.Element;
 4   
 import junit.extensions.xml.IXMLTestCase;
 5   
 import junit.extensions.xml.XMLException;
 6   
 import junit.framework.TestCase;
 7   
 import junit.extensions.xml.XMLTagResourceBundle;
 8   
 
 9   
 /**
 10   
  * <p>Title: Test the tokenize tag handler.</p>
 11   
  * <p>Copyright: Copyright (c) 2003</p>
 12   
  * <p>Company: JFCUnit OpenSource Project</p>
 13   
  * @author Kevin Wilson
 14   
  * @version 1.0
 15   
  */
 16   
 public class TokenizeTagHandlerT
 17   
     extends TestCase {
 18   
 
 19   
   /**
 20   
    * Test tag handler.
 21   
    */
 22   
   private TokenizeTagHandler m_tokenizeTagHandler = null;
 23   
 
 24   
   /**
 25   
    * Test fixture.
 26   
    */
 27   
   private ElementFixture m_fixture;
 28   
 
 29   
   /**
 30   
    * Test case.
 31   
    */
 32   
   private IXMLTestCase m_testCase;
 33   
 
 34   
   /**
 35   
    * Constructor.
 36   
    * @param name Name of the test case.
 37   
    */
 38  2
   public TokenizeTagHandlerT(final String name) {
 39  2
     super(name);
 40   
   }
 41   
 
 42   
   /**
 43   
    * Setup the test.
 44   
    * @throws Exception may be thrown.
 45   
    */
 46  2
   protected void setUp() throws Exception {
 47  2
     super.setUp();
 48  2
     m_fixture = new ElementFixture(this);
 49  2
     m_fixture.setUp();
 50  2
     m_testCase = m_fixture.getTestCase();
 51   
 
 52   
   }
 53   
 
 54   
   /**
 55   
    * Tear down the test.
 56   
    * @throws Exception may be thrown.
 57   
    */
 58  2
   protected void tearDown() throws Exception {
 59  2
     m_tokenizeTagHandler = null;
 60  2
     m_fixture.tearDown();
 61   
 
 62  2
     m_testCase = null;
 63  2
     m_fixture = null;
 64  2
     super.tearDown();
 65   
   }
 66   
 
 67   
   /**
 68   
    * Test process element.
 69   
    * @throws XMLException may be thrown.
 70   
    */
 71  1
   public void testProcessElement() throws XMLException {
 72  1
     Element element = m_fixture.newElement("tokenize", new String[] {
 73   
                                                 "id", "first",
 74   
                                                 "refid", "data",
 75   
                                                 "delimiter", ":"
 76   
     });
 77   
 
 78  1
     m_tokenizeTagHandler = new TokenizeTagHandler(element, m_testCase);
 79  1
     m_testCase.addProperty("data", "test1:test2:test3");
 80   
 
 81  1
     m_tokenizeTagHandler.processElement();
 82  1
     String first = (String) m_testCase.getProperty("first");
 83  1
     String data = (String) m_testCase.getProperty("data");
 84  1
     assertEquals("test1", first);
 85  1
     assertEquals("test2:test3", data);
 86   
 
 87  1
     m_tokenizeTagHandler.processElement();
 88  1
     first = (String) m_testCase.getProperty("first");
 89  1
     data = (String) m_testCase.getProperty("data");
 90  1
     assertEquals("test2", first);
 91  1
     assertEquals("test3", data);
 92   
 
 93  1
     m_tokenizeTagHandler.processElement();
 94  1
     first = (String) m_testCase.getProperty("first");
 95  1
     data = (String) m_testCase.getProperty("data");
 96  1
     assertEquals("test3", first);
 97  1
     assertNull(data);
 98   
 
 99   
     // Lets start another run.
 100  1
     m_testCase.addProperty("data", ":::test");
 101  1
     m_tokenizeTagHandler.processElement();
 102  1
     first = (String) m_testCase.getProperty("first");
 103  1
     data = (String) m_testCase.getProperty("data");
 104  1
     assertEquals("first token", "", first);
 105  1
     assertEquals("::test", data);
 106   
 
 107  1
     m_testCase.addProperty("debug", "true");
 108  1
     m_tokenizeTagHandler.processElement();
 109  1
     first = (String) m_testCase.getProperty("first");
 110  1
     data = (String) m_testCase.getProperty("data");
 111  1
     assertEquals("second token", "", first);
 112  1
     assertEquals(":test", data);
 113   
 
 114  1
     m_tokenizeTagHandler.processElement();
 115  1
     first = (String) m_testCase.getProperty("first");
 116  1
     data = (String) m_testCase.getProperty("data");
 117  1
     assertEquals("third token", "", first);
 118  1
     assertEquals("test", data);
 119   
 
 120  1
     m_tokenizeTagHandler.processElement();
 121  1
     first = (String) m_testCase.getProperty("first");
 122  1
     data = (String) m_testCase.getProperty("data");
 123  1
     assertEquals("third token", "test", first);
 124  1
     assertNull("test", data);
 125   
 
 126   
   }
 127   
 
 128   
   /**
 129   
    * Test with the Tag lookup.
 130   
    */
 131  1
   public void testLookup() {
 132  1
     Element element = m_fixture.newElement("tokenize", new String[] {
 133   
                                            "id", "first",
 134   
                                            "refid", "data",
 135   
                                            "delimiter", ":"
 136   
     });
 137  1
     Object o = XMLTagResourceBundle.getTagHandler(element, m_testCase, "tokenize");
 138  1
     assertNotNull(o);
 139   
   }
 140   
 }
 141