Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 141   Methods: 3
NCLOC: 42   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TokenizeTagHandler.java 100% 100% 100% 100%
coverage
 1   
 package junit.extensions.xml.elements;
 2   
 
 3   
 import junit.extensions.xml.IXMLTestCase;
 4   
 import junit.extensions.xml.XMLException;
 5   
 
 6   
 import junit.framework.Assert;
 7   
 
 8   
 import org.w3c.dom.Element;
 9   
 
 10   
 
 11   
 /**
 12   
  * Return the tokens of a string one at a time.
 13   
  *
 14   
  * <H2>Title:</H2>
 15   
  * TokenizeTagHandler
 16   
  * <H2>Description:</H2>
 17   
  *
 18   
  * The TokenizeTagHandler provides a mechanism for breaking
 19   
  * up a string into pieces.  The refid points to the string
 20   
  * that will be broken up, each call to tokenize returns
 21   
  * the token, and the remainder of the token string that
 22   
  * can be used again in a subsequent call.
 23   
  *
 24   
  * <H2>Attributes:</H2>
 25   
  * <pre>
 26   
  * id        - the string token to be returned [required]
 27   
  * refid     - the string of tokens to separate [required]
 28   
  * delimiter - the token separator [required]
 29   
  * </pre>
 30   
  *
 31   
  *
 32   
  * <H2>Example:</H2>
 33   
  *    If array contained "File>New" and your delimiter was ">".
 34   
  *    As in:
 35   
  * <pre>
 36   
  * <code>
 37   
  *    &lt;property name="array" value="File>New"/&gt;
 38   
  *    &lt;tokenize id="token" refid="array" delimiter="&gt;"/&gt;
 39   
  *    &lt;!-- Now array="New" token="File" --&gt;
 40   
  *    &lt;tokenize id="token" refid="array" delimiter="&gt;"/&gt;
 41   
  *    &lt;!-- Now array="" token="New" --&gt;
 42   
  * </code>
 43   
  * </pre>
 44   
  *    The first call would return "File" in the token property
 45   
  *    and update the array to "New".
 46   
  *    The second call would return "New" and update the
 47   
  array to: ""
 48   
  *    Any subsequent call would return ""<br>
 49   
  *
 50   
  * Another example is to return the values of various fields of
 51   
  * which some may be null.
 52   
  * <code>
 53   
  *    &lt;property name="array" value="userid:*:Guest:::"/&gt;
 54   
  *    &lt;tokenize id="token" refid="array" delimiter=":"/&gt;
 55   
  *    &lt;!-- Now array="*:Guest:::" token="userid" --&gt;
 56   
  *    &lt;tokenize id="token" refid="array" delimiter=":"/&gt;
 57   
  *    &lt;!-- Now array="Guest:::" token="*" --&gt;
 58   
  *    &lt;tokenize id="token" refid="array" delimiter=":"/&gt;
 59   
  *    &lt;!-- Now array="::" token="Guest" --&gt;
 60   
  *    &lt;tokenize id="token" refid="array" delimiter=":"/&gt;
 61   
  *    &lt;!-- Now array=":" token="" --&gt;
 62   
  *    &lt;tokenize id="token" refid="array" delimiter=":"/&gt;
 63   
  *    &lt;!-- Now array="" token="" --&gt;
 64   
  * </code>
 65   
  * <p>Copyright: Copyright (c) 2004</p>
 66   
  * <p>Company: JFCUnit Sourceforge project</p>
 67   
  *
 68   
  */
 69   
 public class TokenizeTagHandler extends AbstractTagHandler {
 70   
     /**
 71   
      * Constructor.
 72   
      * @param element Element to be created.
 73   
      * @param testcase IXMLTestCase parent test case.
 74   
      */
 75  2
     public TokenizeTagHandler(final Element element, final IXMLTestCase testcase) {
 76  2
         super(element, testcase);
 77   
     }
 78   
 
 79   
     /**
 80   
      * Handle the XML processing of the tag.
 81   
      * @throws XMLException may be thrown.
 82   
      */
 83  7
     public void processElement() throws XMLException {
 84  7
         validateElement();
 85   
 
 86  7
         String tokenlist = (String) getXMLTestCase().getProperty(
 87   
                 getString(REFID));
 88   
 
 89  7
         if (getXMLTestCase().getDebug()) {
 90  3
             System.out.println("tokenlist:" + tokenlist);
 91   
         }
 92   
 
 93  7
         String delimiter = getString(DELIMITER);
 94   
 
 95  7
         Assert.assertNotNull("Error: Unable to obtain delimiter : ", delimiter);
 96   
 
 97  7
         int index = tokenlist.indexOf(delimiter);
 98   
 
 99   
         // Last token.
 100  7
         if (index == -1) {
 101   
             // set the token value to the ID property
 102  2
             ((IXMLTestCase) getTestCase()).addProperty(
 103   
                 getString(ID),
 104   
                 tokenlist);
 105   
 
 106   
             // clear the refid  (remove the property to make null)
 107  2
             ((IXMLTestCase) getTestCase()).removeProperty(getString(REFID));
 108   
         } else {
 109   
             // More tokens so break off the first.
 110   
             // set the token value to the ID property
 111  5
             String first  = tokenlist.substring(0, index);
 112  5
             String others = tokenlist.substring(index + delimiter.length());
 113  5
             ((IXMLTestCase) getTestCase()).addProperty(
 114   
                 getString(ID),
 115   
                 first);
 116   
 
 117   
             // update the refid with the remainder of the tokenizer
 118  5
             ((IXMLTestCase) getTestCase()).addProperty(
 119   
                 getString(REFID),
 120   
                 others);
 121   
         }
 122   
     }
 123   
 
 124   
     /**
 125   
      * Make sure the appropriate tag and attributes are
 126   
      * used.
 127   
      * @throws XMLException upon failure to validate.
 128   
      */
 129  7
     public void validateElement() throws XMLException {
 130  7
         super.validateElement();
 131   
 
 132   
         // check the element tag name
 133   
         // checkElementTagName("selectMenuOnToolbar");
 134  7
         checkRequiredAttribute(ID);
 135   
 
 136  7
         checkRequiredAttribute(DELIMITER);
 137   
 
 138  7
         checkRequiredAttribute(REFID);
 139   
     }
 140   
 }
 141