01: /*
02: * Copyright (C) 2004, 2005 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 05. September 2004 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.io.xml;
13:
14: import org.dom4j.io.OutputFormat;
15:
16: import java.io.StringWriter;
17:
18: public class Dom4JXmlWriterTest extends AbstractXMLWriterTest {
19:
20: private StringWriter out;
21:
22: protected void setUp() throws Exception {
23: super .setUp();
24:
25: Dom4JDriver driver = new Dom4JDriver();
26:
27: OutputFormat format = OutputFormat.createCompactFormat();
28: format.setTrimText(false);
29: format.setSuppressDeclaration(true);
30: driver.setOutputFormat(format);
31:
32: out = new StringWriter();
33: writer = driver.createWriter(out);
34: }
35:
36: protected void assertXmlProducedIs(String expected) {
37: writer.close();
38: String actual = out.toString().trim();
39: assertEquals(expected, actual);
40: }
41:
42: // inherits tests from superclass
43:
44: public void testEscapesWhitespaceCharacters() {
45: // This method overrides a test in the superclass to prevent it from being run, since the
46: // OutputFormat will not encode \r.
47: writer.startNode("evil");
48: writer.setValue("one\ntwo\rthree\r\nfour\n\rfive\tsix");
49: writer.endNode();
50:
51: assertXmlProducedIs("<evil>one\n" + "two\rthree\r\n" + "four\n"
52: + "\rfive\tsix</evil>");
53: }
54: }
|