|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| package nu.xom.tests; |
|
23 |
| |
|
24 |
| import nu.xom.Attribute; |
|
25 |
| import nu.xom.Comment; |
|
26 |
| import nu.xom.DocType; |
|
27 |
| import nu.xom.Document; |
|
28 |
| import nu.xom.Element; |
|
29 |
| import nu.xom.Node; |
|
30 |
| import nu.xom.ProcessingInstruction; |
|
31 |
| import nu.xom.Text; |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| public class SubclassTest extends XOMTestCase { |
|
45 |
| |
|
46 |
| private Element root; |
|
47 |
| private Document doc; |
|
48 |
| |
|
49 |
| |
|
50 |
9
| public SubclassTest(String name) {
|
|
51 |
9
| super(name);
|
|
52 |
| } |
|
53 |
| |
|
54 |
| |
|
55 |
9
| protected void setUp() {
|
|
56 |
9
| root = new Element("root");
|
|
57 |
9
| doc = new Document(new ElementSubclass("root"));
|
|
58 |
| } |
|
59 |
| |
|
60 |
| |
|
61 |
1
| public void testAttributeClassInCopy() {
|
|
62 |
1
| root.addAttribute(new AttributeSubclass("name", "value"));
|
|
63 |
1
| assertTrue(root.getAttribute(0) instanceof AttributeSubclass);
|
|
64 |
1
| Element copy = (Element) root.copy();
|
|
65 |
1
| assertTrue(copy.getAttribute(0) instanceof AttributeSubclass);
|
|
66 |
| } |
|
67 |
| |
|
68 |
| |
|
69 |
| private class AttributeSubclass extends Attribute { |
|
70 |
| |
|
71 |
2
| AttributeSubclass(String name, String value) {
|
|
72 |
2
| super(name, value);
|
|
73 |
| } |
|
74 |
| |
|
75 |
1
| public Node copy() {
|
|
76 |
1
| return new AttributeSubclass(this.getQualifiedName(), this.getValue());
|
|
77 |
| } |
|
78 |
| |
|
79 |
| } |
|
80 |
| |
|
81 |
| |
|
82 |
1
| public void testTextClassInCopy() {
|
|
83 |
1
| root.appendChild(new TextSubclass("value"));
|
|
84 |
1
| assertTrue(root.getChild(0) instanceof TextSubclass);
|
|
85 |
1
| Element copy = (Element) root.copy();
|
|
86 |
1
| assertTrue(copy.getChild(0) instanceof TextSubclass);
|
|
87 |
| } |
|
88 |
| |
|
89 |
| |
|
90 |
| private class TextSubclass extends Text { |
|
91 |
| |
|
92 |
2
| TextSubclass(String value) {
|
|
93 |
2
| super(value);
|
|
94 |
| } |
|
95 |
| |
|
96 |
1
| public Node copy() {
|
|
97 |
1
| return new TextSubclass(this.getValue());
|
|
98 |
| } |
|
99 |
| } |
|
100 |
| |
|
101 |
| |
|
102 |
1
| public void testElementClassInCopy() {
|
|
103 |
1
| root.appendChild(new ElementSubclass("child"));
|
|
104 |
1
| assertTrue(root.getChild(0) instanceof ElementSubclass);
|
|
105 |
1
| Element copy = (Element) root.copy();
|
|
106 |
1
| assertTrue(copy.getChild(0) instanceof ElementSubclass);
|
|
107 |
| } |
|
108 |
| |
|
109 |
| |
|
110 |
| private class ElementSubclass extends Element { |
|
111 |
| |
|
112 |
15
| ElementSubclass(String name) {
|
|
113 |
15
| super(name);
|
|
114 |
| } |
|
115 |
| |
|
116 |
5
| protected Element shallowCopy() {
|
|
117 |
5
| return new ElementSubclass(this.getQualifiedName());
|
|
118 |
| } |
|
119 |
| |
|
120 |
| } |
|
121 |
| |
|
122 |
| |
|
123 |
1
| public void testCommentClassInCopy() {
|
|
124 |
1
| root.appendChild(new CommentSubclass("value"));
|
|
125 |
1
| assertTrue(root.getChild(0) instanceof CommentSubclass);
|
|
126 |
1
| Element copy = (Element) root.copy();
|
|
127 |
1
| assertTrue(copy.getChild(0) instanceof CommentSubclass);
|
|
128 |
| } |
|
129 |
| |
|
130 |
| |
|
131 |
| private class CommentSubclass extends Comment { |
|
132 |
| |
|
133 |
4
| CommentSubclass(String value) {
|
|
134 |
4
| super(value);
|
|
135 |
| } |
|
136 |
| |
|
137 |
2
| public Node copy() {
|
|
138 |
2
| return new CommentSubclass(this.getValue());
|
|
139 |
| } |
|
140 |
| |
|
141 |
| } |
|
142 |
| |
|
143 |
| |
|
144 |
| private class DocTypeSubclass extends DocType { |
|
145 |
| |
|
146 |
2
| DocTypeSubclass(String name) {
|
|
147 |
2
| super(name);
|
|
148 |
| } |
|
149 |
| |
|
150 |
1
| public Node copy() {
|
|
151 |
1
| return new DocTypeSubclass(this.getRootElementName());
|
|
152 |
| } |
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
1
| public void testProcessingInstructionClassInCopy() {
|
|
157 |
1
| root.appendChild(new ProcessingInstructionSubclass("target", "value"));
|
|
158 |
1
| assertTrue(root.getChild(0) instanceof ProcessingInstructionSubclass);
|
|
159 |
1
| Element copy = (Element) root.copy();
|
|
160 |
1
| assertTrue(copy.getChild(0) instanceof ProcessingInstructionSubclass);
|
|
161 |
| } |
|
162 |
| |
|
163 |
| |
|
164 |
| private class ProcessingInstructionSubclass extends ProcessingInstruction { |
|
165 |
| |
|
166 |
4
| ProcessingInstructionSubclass(String target, String data) {
|
|
167 |
4
| super(target, data);
|
|
168 |
| } |
|
169 |
| |
|
170 |
2
| public Node copy() {
|
|
171 |
2
| return new ProcessingInstructionSubclass(this.getTarget(), this.getValue());
|
|
172 |
| } |
|
173 |
| |
|
174 |
| } |
|
175 |
| |
|
176 |
| |
|
177 |
1
| public void testProcessingInstructionClassInDocCopy() {
|
|
178 |
1
| doc.insertChild(new ProcessingInstructionSubclass("target", "value"), 0);
|
|
179 |
1
| assertTrue(doc.getChild(0) instanceof ProcessingInstructionSubclass);
|
|
180 |
1
| Document copy = (Document) doc.copy();
|
|
181 |
1
| assertTrue(copy.getChild(0) instanceof ProcessingInstructionSubclass);
|
|
182 |
| } |
|
183 |
| |
|
184 |
| |
|
185 |
1
| public void testCommentClassInDocCopy() {
|
|
186 |
1
| doc.insertChild(new CommentSubclass("target"), 0);
|
|
187 |
1
| assertTrue(doc.getChild(0) instanceof CommentSubclass);
|
|
188 |
1
| Document copy = (Document) doc.copy();
|
|
189 |
1
| assertTrue(copy.getChild(0) instanceof CommentSubclass);
|
|
190 |
| } |
|
191 |
| |
|
192 |
| |
|
193 |
1
| public void testElementClassInDocCopy() {
|
|
194 |
1
| assertTrue(doc.getChild(0) instanceof ElementSubclass);
|
|
195 |
1
| Document copy = (Document) doc.copy();
|
|
196 |
1
| assertTrue(copy.getChild(0) instanceof ElementSubclass);
|
|
197 |
| } |
|
198 |
| |
|
199 |
| |
|
200 |
1
| public void testDocTypeClassInDocCopy() {
|
|
201 |
1
| doc.insertChild(new DocTypeSubclass("root"), 0);
|
|
202 |
1
| assertTrue(doc.getChild(0) instanceof DocTypeSubclass);
|
|
203 |
1
| Document copy = (Document) doc.copy();
|
|
204 |
1
| assertTrue(copy.getChild(0) instanceof DocTypeSubclass);
|
|
205 |
| } |
|
206 |
| |
|
207 |
| |
|
208 |
| } |