|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AssertHasFocusTagHandler.java | 100% | 100% | 100% | 100% |
|
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 |
* This class will handle the processing of <assertenabled> nodes.
|
|
13 |
*
|
|
14 |
* <H3>Mandatory attributes</H3>
|
|
15 |
* refid is assumed to be a java.awt.Component.
|
|
16 |
*
|
|
17 |
* <H3>Optional attributes (default value)</H3>
|
|
18 |
* message Message to be displayed upon assertion.<br>
|
|
19 |
* focus (true)
|
|
20 |
*
|
|
21 |
* @author <a href="mailto:kwilson227@users.sourceforge.net">Kevin Wilson</a>
|
|
22 |
*/
|
|
23 |
public class AssertHasFocusTagHandler extends AbstractAssertTagHandler { |
|
24 |
/**
|
|
25 |
* Constructor for AssertEnabledTagHandler.
|
|
26 |
*
|
|
27 |
* @param element The element to be processed
|
|
28 |
* @param testCase The IXMLTestCase that uses this element
|
|
29 |
*/
|
|
30 | 6 |
public AssertHasFocusTagHandler(final Element element,
|
31 |
final IXMLTestCase testCase) { |
|
32 | 6 |
super(element, testCase);
|
33 |
} |
|
34 |
|
|
35 |
/**
|
|
36 |
* Obtains the component via the refid. The
|
|
37 |
* checks the focus state of the component.
|
|
38 |
* If the focus state does not match the state
|
|
39 |
* specified then assert.
|
|
40 |
*
|
|
41 |
* @throws XMLException upon assertion.
|
|
42 |
*/
|
|
43 | 5 |
public void processElement() throws XMLException { |
44 | 5 |
validateElement(); |
45 |
|
|
46 | 5 |
boolean result = false; |
47 | 5 |
Object object = getXMLTestCase().getProperty(getRefId()); |
48 | 5 |
Assert.assertNotNull( |
49 |
getMessage(), |
|
50 |
object); |
|
51 |
|
|
52 | 5 |
if (object instanceof java.awt.Component) { |
53 | 4 |
result = ((java.awt.Component) object).hasFocus(); |
54 |
} else {
|
|
55 | 1 |
throw new XMLException("Not a component", null, |
56 |
getElement(), |
|
57 |
getTest().getProcedureCache()); |
|
58 |
} |
|
59 |
|
|
60 | 4 |
Assert.assertTrue( |
61 |
getMessage(), |
|
62 |
result == getFocus()); |
|
63 |
} |
|
64 |
|
|
65 |
/**
|
|
66 |
* Insure that the refid is specified.
|
|
67 |
* @throws XMLException if refid is not specified.
|
|
68 |
*/
|
|
69 | 5 |
public void validateElement() throws XMLException { |
70 |
// do the default validations from the super class
|
|
71 | 5 |
super.validateElement();
|
72 |
|
|
73 |
// reqd attribute: refid
|
|
74 | 5 |
checkRequiredAttribute(REFID); |
75 |
} |
|
76 |
|
|
77 |
/**
|
|
78 |
* Returns the value of the "focus" attribute for this element.
|
|
79 |
* @return String The value of the FOCUS attribute.
|
|
80 |
*/
|
|
81 | 4 |
private boolean getFocus() { |
82 | 4 |
return getBoolean(FOCUS, true); |
83 |
} |
|
84 |
} |
|
85 |
|
|