|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
XMLExceptionT.java | - | 100% | 100% | 100% |
|
1 |
package junit.extensions.xml;
|
|
2 |
|
|
3 |
import org.w3c.dom.Element;
|
|
4 |
import junit.extensions.xml.elements.ElementFixture;
|
|
5 |
import junit.framework.TestCase;
|
|
6 |
|
|
7 |
/**
|
|
8 |
* <p>Title: XMLException test case.</p>
|
|
9 |
* <p>Copyright: Copyright (c) 2003</p>
|
|
10 |
* <p>Company: JFCUnit OpenSource Project</p>
|
|
11 |
* @author Kevin Wilson
|
|
12 |
* @version 1.0
|
|
13 |
*/
|
|
14 |
|
|
15 |
public class XMLExceptionT extends TestCase { |
|
16 |
/**
|
|
17 |
* Exception to be tested.
|
|
18 |
*/
|
|
19 |
private XMLException m_xmlException = null; |
|
20 |
/**
|
|
21 |
* element fixture.
|
|
22 |
*/
|
|
23 |
private ElementFixture m_elementFixture;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* Setup the test.
|
|
27 |
* @throws Exception may be thrown.
|
|
28 |
*/
|
|
29 | 2 |
protected void setUp() throws Exception { |
30 | 2 |
super.setUp();
|
31 | 2 |
m_xmlException = new XMLException("", null, null, null); |
32 | 2 |
m_elementFixture = new ElementFixture(this); |
33 |
|
|
34 | 2 |
m_elementFixture.setUp(); |
35 |
} |
|
36 |
|
|
37 |
/**
|
|
38 |
* Tear down the test.
|
|
39 |
* @throws Exception may be thrown.
|
|
40 |
*/
|
|
41 | 2 |
protected void tearDown() throws Exception { |
42 | 2 |
m_xmlException = null;
|
43 | 2 |
m_elementFixture.tearDown(); |
44 |
|
|
45 | 2 |
m_elementFixture = null;
|
46 | 2 |
super.tearDown();
|
47 |
} |
|
48 |
|
|
49 |
/**
|
|
50 |
* Test the exceptoin.
|
|
51 |
*/
|
|
52 | 1 |
public void testXMLException() { |
53 | 1 |
String msg = "test not allowed in a test";
|
54 | 1 |
Element element = m_elementFixture.newElement("test",
|
55 |
new String[] {
|
|
56 |
"robot", "true" |
|
57 |
}); |
|
58 | 1 |
XMLObjectCache properties = m_elementFixture.getTestCase().getPropertyCache(); |
59 | 1 |
properties.put("param1", "value1"); |
60 | 1 |
properties.put("param2", "value2"); |
61 | 1 |
properties.put("../param3", "value3"); |
62 | 1 |
m_xmlException = new XMLException(msg, null, element, properties); |
63 |
|
|
64 | 1 |
assertSame(element, m_xmlException.getElement()); |
65 |
|
|
66 | 1 |
String exp = |
67 |
"junit.extensions.xml.XMLException: test not allowed in a test\r\n"
|
|
68 |
+ "While processing element:\r\n"
|
|
69 |
+ "<test robot=\"true\"/>\r\n"
|
|
70 |
+ "Within:\r\n"
|
|
71 |
+ "<test name=\"Automated TestCase\">"
|
|
72 |
+ "<test robot=\"true\"/>"
|
|
73 |
+ "</test>\r\n"
|
|
74 |
+ "Local Parameters:\r\n"
|
|
75 |
+ "param2 = value2\r\n"
|
|
76 |
+ "param1 = value1\r\n";
|
|
77 | 1 |
String result = m_xmlException.toString(); |
78 | 1 |
assertEquals(exp, result); |
79 |
} |
|
80 |
|
|
81 |
/**
|
|
82 |
* Test a null Exception.
|
|
83 |
*/
|
|
84 | 1 |
public void testNullElement() { |
85 | 1 |
m_xmlException = new XMLException("test", null, null, null); |
86 | 1 |
String result = m_xmlException.toString(); |
87 | 1 |
String expected = "junit.extensions.xml.XMLException: test\r\n";
|
88 | 1 |
assertEquals(expected, result); |
89 |
} |
|
90 |
} |
|
91 |
|
|