|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| WhileTagHandler.java | 75% | 91.7% | 100% | 89.5% |
|
||||||||||||||
| 1 |
package junit.extensions.xml.elements;
|
|
| 2 |
|
|
| 3 |
import junit.extensions.xml.IXMLTestCase;
|
|
| 4 |
import junit.extensions.xml.XMLException;
|
|
| 5 |
import junit.extensions.xml.XMLTagResourceBundle;
|
|
| 6 |
|
|
| 7 |
import org.w3c.dom.Element;
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
/**
|
|
| 11 |
* <H3>Title:</H3>
|
|
| 12 |
* WhileTagHandler
|
|
| 13 |
* <H3>Description:</H3>
|
|
| 14 |
* <p>The WhileTagHandler allows for some
|
|
| 15 |
* flow control in a test case. The handler is pattered
|
|
| 16 |
* after the xsl:choose elements.</p>
|
|
| 17 |
*
|
|
| 18 |
*
|
|
| 19 |
* <H3>Example:</H3>
|
|
| 20 |
* <pre>
|
|
| 21 |
* <while test="assertnotnull" actualrefid="ComponentA" >
|
|
| 22 |
* ...do while...
|
|
| 23 |
* </while>
|
|
| 24 |
* </pre>
|
|
| 25 |
*
|
|
| 26 |
* <p>Copyright: Copyright (c) 2003</p>
|
|
| 27 |
* <p>Company: JFCUnit Sourceforge project</p>
|
|
| 28 |
*/
|
|
| 29 |
public class WhileTagHandler extends AbstractTagHandler { |
|
| 30 |
/**
|
|
| 31 |
* Constructor.
|
|
| 32 |
* @param element Element to be processed
|
|
| 33 |
* @param testCase Test case processing tag handler.
|
|
| 34 |
*/
|
|
| 35 | 5 |
public WhileTagHandler(final Element element, final IXMLTestCase testCase) {
|
| 36 | 5 |
super(element, testCase);
|
| 37 |
} |
|
| 38 |
|
|
| 39 |
/**
|
|
| 40 |
* process the element.
|
|
| 41 |
* @throws XMLException is thrown if the element cannot be understood.
|
|
| 42 |
*/
|
|
| 43 | 2 |
public void processElement() throws XMLException { |
| 44 | 2 |
validateElement(); |
| 45 |
|
|
| 46 | 2 |
boolean finished = false; |
| 47 |
|
|
| 48 | 2 |
while (!finished) {
|
| 49 | 2 |
Element e = getElement(); |
| 50 |
|
|
| 51 | 2 |
try {
|
| 52 | 2 |
XMLTagResourceBundle.getTagHandler( |
| 53 |
e, |
|
| 54 |
getXMLTestCase(), |
|
| 55 |
getString(e, TEST)).processElement(); |
|
| 56 |
} catch (XMLException xe) {
|
|
| 57 | 1 |
throw xe;
|
| 58 |
} catch (Throwable t) {
|
|
| 59 | 1 |
finished = true;
|
| 60 |
} |
|
| 61 |
|
|
| 62 | 1 |
if (!finished) {
|
| 63 | 0 |
getXMLTestCase().processChildren(e); |
| 64 |
} |
|
| 65 |
} |
|
| 66 |
} |
|
| 67 |
|
|
| 68 |
/**
|
|
| 69 |
* Validate that the element is correct.
|
|
| 70 |
* @throws XMLException if the tag name is not while.
|
|
| 71 |
*/
|
|
| 72 | 4 |
public void validateElement() throws XMLException { |
| 73 | 4 |
super.checkElementTagName(WHILE);
|
| 74 |
} |
|
| 75 |
} |
|
| 76 |
|
|
||||||||||