|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
NamedComponentFinderTagHandlerT.java | - | 100% | 100% | 100% |
|
1 |
package junit.extensions.jfcunit.finder;
|
|
2 |
|
|
3 |
import javax.swing.BoxLayout;
|
|
4 |
import javax.swing.JButton;
|
|
5 |
import javax.swing.JFrame;
|
|
6 |
|
|
7 |
import org.w3c.dom.Element;
|
|
8 |
import junit.extensions.jfcunit.AbstractTestCase;
|
|
9 |
import junit.extensions.jfcunit.xml.JFCXMLTestCase;
|
|
10 |
import junit.extensions.xml.XMLException;
|
|
11 |
import junit.extensions.xml.XMLTagResourceBundle;
|
|
12 |
import junit.extensions.xml.elements.AbstractTagHandler;
|
|
13 |
import junit.extensions.xml.elements.ElementFixture;
|
|
14 |
|
|
15 |
/**
|
|
16 |
* Test case to test the named component tag handler.
|
|
17 |
* @author Kevin Wilson not attributable
|
|
18 |
* @version 1.0
|
|
19 |
*/
|
|
20 |
|
|
21 |
public class NamedComponentFinderTagHandlerT |
|
22 |
extends AbstractTestCase {
|
|
23 |
|
|
24 |
/**
|
|
25 |
* Fixture used to create the test elements and test
|
|
26 |
* cases and test suites.
|
|
27 |
*/
|
|
28 |
private ElementFixture m_fixture;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* Constructor.
|
|
32 |
* @param name of the test case.
|
|
33 |
*/
|
|
34 | 2 |
public NamedComponentFinderTagHandlerT(final String name) {
|
35 | 2 |
super(name);
|
36 |
} |
|
37 |
|
|
38 |
/**
|
|
39 |
* Setup the test.
|
|
40 |
* @throws Exception may be thrown.
|
|
41 |
*/
|
|
42 | 2 |
protected void setUp() throws Exception { |
43 | 2 |
super.setUp();
|
44 | 2 |
m_fixture = new ElementFixture(this); |
45 |
|
|
46 | 2 |
m_fixture.setUp(); |
47 |
} |
|
48 |
|
|
49 |
/**
|
|
50 |
* Tear down the test.
|
|
51 |
* @throws Exception may be thrown.
|
|
52 |
*/
|
|
53 | 2 |
protected void tearDown() throws Exception { |
54 | 2 |
m_fixture.tearDown(); |
55 | 2 |
m_fixture = null;
|
56 | 2 |
super.tearDown();
|
57 |
} |
|
58 |
|
|
59 |
/**
|
|
60 |
* Test the process element.
|
|
61 |
* @throws XMLException may be thrown.
|
|
62 |
*/
|
|
63 | 1 |
public void testProcessElement() throws XMLException { |
64 | 1 |
JFCXMLTestCase tc = m_fixture.getJFCTestCase(); |
65 | 1 |
Element e = m_fixture.newElement("find", new String[] { |
66 |
"finder", "NamedComponentFinder", |
|
67 |
"id", "component", |
|
68 |
"index", "0", |
|
69 |
"name", "TEST", |
|
70 |
"class", "javax.swing.JButton", |
|
71 |
"operation", "equals", |
|
72 |
"container", "frame" |
|
73 |
}); |
|
74 |
|
|
75 | 1 |
JFrame frame = this.createJFrame("TEST"); |
76 | 1 |
JButton b1 = new JButton("TEST"); |
77 | 1 |
b1.setName("Test");
|
78 |
|
|
79 | 1 |
JButton b2 = new JButton("TEST"); |
80 | 1 |
b2.setName("TEST");
|
81 |
|
|
82 | 1 |
frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(),
|
83 |
BoxLayout.X_AXIS)); |
|
84 | 1 |
frame.getContentPane().add(b1); |
85 | 1 |
frame.getContentPane().add(b2); |
86 | 1 |
tc.addProperty("frame", frame);
|
87 | 1 |
packAndShow(frame); |
88 |
|
|
89 | 1 |
AbstractTagHandler handler = XMLTagResourceBundle.getTagHandler(e, tc, |
90 |
"find");
|
|
91 | 1 |
handler.processElement(); |
92 | 1 |
Object o = tc.getProperty("component");
|
93 | 1 |
assertSame("ComponentFound should be B2.", b2, o);
|
94 |
} |
|
95 |
|
|
96 |
/**
|
|
97 |
* Test the processing when a invalid class is used.
|
|
98 |
* @throws XMLException may be thrown.
|
|
99 |
*/
|
|
100 | 1 |
public void testProcessInvalidClass() throws XMLException { |
101 | 1 |
JFCXMLTestCase tc = m_fixture.getJFCTestCase(); |
102 | 1 |
Element e = m_fixture.newElement("find", new String[] { |
103 |
"finder", "NamedComponentFinder", |
|
104 |
"id", "component", |
|
105 |
"index", "0", |
|
106 |
"name", "TEST", |
|
107 |
"class", "javax.swing.JButtonx", |
|
108 |
"operation", "equals", |
|
109 |
"container", "frame" |
|
110 |
}); |
|
111 |
|
|
112 | 1 |
JFrame frame = this.createJFrame("TEST"); |
113 | 1 |
JButton b1 = new JButton("TEST"); |
114 | 1 |
b1.setName("Test");
|
115 |
|
|
116 | 1 |
JButton b2 = new JButton("TEST"); |
117 | 1 |
b2.setName("TEST");
|
118 |
|
|
119 | 1 |
frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(),
|
120 |
BoxLayout.X_AXIS)); |
|
121 | 1 |
frame.getContentPane().add(b1); |
122 | 1 |
frame.getContentPane().add(b2); |
123 | 1 |
tc.addProperty("frame", frame);
|
124 | 1 |
packAndShow(frame); |
125 |
|
|
126 | 1 |
AbstractTagHandler handler = XMLTagResourceBundle.getTagHandler(e, tc, |
127 |
"find");
|
|
128 |
|
|
129 | 1 |
XMLException xe = null;
|
130 | 1 |
try {
|
131 | 1 |
handler.processElement(); |
132 |
} catch (XMLException xmle) {
|
|
133 | 1 |
xe = xmle; |
134 |
} |
|
135 | 1 |
assertNotNull("Exception not thrown", xe);
|
136 |
} |
|
137 |
|
|
138 |
} |
|
139 |
|
|