1 package com.thoughtworks.xstream.io.xml; 2 3 import com.thoughtworks.xstream.io.HierarchicalStreamWriter; 4 import junit.framework.TestCase; 5 6 import java.io.StringWriter ; 7 8 public class PrettyPrintWriterTest extends TestCase { 9 10 public void testXmlIsIndented() { 11 StringWriter stringWriter = new StringWriter (); 12 HierarchicalStreamWriter xmlWriter = new PrettyPrintWriter(stringWriter, " "); 13 14 xmlWriter.startNode("hello"); 15 xmlWriter.startNode("world"); 16 xmlWriter.addAttribute("id", "one"); 17 18 xmlWriter.startNode("one"); 19 xmlWriter.setValue("potato"); 20 xmlWriter.endNode(); 21 22 xmlWriter.startNode("two"); 23 xmlWriter.addAttribute("id", "two"); 24 xmlWriter.setValue("potatae"); 25 xmlWriter.endNode(); 26 27 xmlWriter.endNode(); 28 29 xmlWriter.startNode("empty"); 30 xmlWriter.endNode(); 31 32 xmlWriter.endNode(); 33 34 String expected = 35 "<hello>\n" + 36 " <world id=\"one\">\n" + 37 " <one>potato</one>\n" + 38 " <two id=\"two\">potatae</two>\n" + 39 " </world>\n" + 40 " <empty/>\n" + 41 "</hello>"; 42 43 assertEquals(expected, stringWriter.toString()); 44 } 45 46 } 47 | Popular Tags |