1 package com.thoughtworks.xstream.io.xml; 2 3 import javax.xml.stream.XMLOutputFactory; 4 import java.io.StringWriter ; 5 6 9 public class StaxWriterTest extends AbstractXMLWriterTest { 10 11 private StringWriter buffer; 12 13 protected void setUp() throws Exception { 14 super.setUp(); 15 XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); 16 buffer = new StringWriter (); 17 writer = new StaxWriter(new QNameMap(), outputFactory.createXMLStreamWriter(buffer)); 18 } 19 20 protected void assertXmlProducedIs(String expected) { 21 expected = "<?xml version='1.0' encoding='utf-8'?>" + expected; assertEquals(expected, buffer.toString()); 23 } 24 25 public void testEscapesWhitespaceCharacters() { 26 } 28 29 public void testSupportsEmptyTags() { 30 writer.startNode("empty"); 32 writer.endNode(); 33 34 assertXmlProducedIs("<empty></empty>"); 35 } 36 37 public void testSupportsAttributes() { 38 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 |