KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > io > xml > StaxWriterTest


1 package com.thoughtworks.xstream.io.xml;
2
3 import javax.xml.stream.XMLOutputFactory;
4 import java.io.StringWriter JavaDoc;
5
6 /*
7  * @author James Strachan
8  */

9 public class StaxWriterTest extends AbstractXMLWriterTest {
10
11     private StringWriter JavaDoc buffer;
12
13     protected void setUp() throws Exception JavaDoc {
14         super.setUp();
15         XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
16         buffer = new StringWriter JavaDoc();
17         writer = new StaxWriter(new QNameMap(), outputFactory.createXMLStreamWriter(buffer));
18     }
19
20     protected void assertXmlProducedIs(String JavaDoc expected) {
21         expected = "<?xml version='1.0' encoding='utf-8'?>" + expected; // include header
22
assertEquals(expected, buffer.toString());
23     }
24
25     public void testEscapesWhitespaceCharacters() {
26         // overriding test in superclass... this doesn't seem to work with StaxWriter.
27
}
28
29     public void testSupportsEmptyTags() {
30         // overriding test in superclass.... StaxWriter writes <blah></blah> instead of <blah/>
31
writer.startNode("empty");
32         writer.endNode();
33
34         assertXmlProducedIs("<empty></empty>");
35     }
36
37     public void testSupportsAttributes() {
38         // overriding test in superclass.... StaxWriter writes <blah></blah> instead of <blah/>
39
writer.startNode("person");
40         writer.addAttribute("firstname", "Joe");
41         writer.addAttribute("lastname", "Walnes");
42         writer.endNode();
43
44         assertXmlProducedIs("<person firstname=\"Joe\" lastname=\"Walnes\"></person>");
45     }
46
47 }
48
49
Popular Tags