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 03. March 2004 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.io.path;
13:
14: import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15: import com.thoughtworks.xstream.io.xml.CompactWriter;
16:
17: import junit.framework.TestCase;
18:
19: import java.io.StringWriter;
20:
21: public class PathTrackingWriterTest extends TestCase {
22: private StringWriter out;
23: private HierarchicalStreamWriter writer;
24: private PathTracker pathTracker;
25:
26: protected void setUp() throws Exception {
27: super .setUp();
28: pathTracker = new PathTracker();
29: out = new StringWriter();
30: HierarchicalStreamWriter originalWriter = new CompactWriter(out);
31:
32: writer = new PathTrackingWriter(originalWriter, pathTracker);
33: }
34:
35: public void testDecoratesXmlWriterProxyingAllInvocations() {
36:
37: writer.startNode("foo");
38: writer.addAttribute("att", "something");
39: writer.setValue("getValue");
40: writer.endNode();
41:
42: assertEquals("<foo att=\"something\">getValue</foo>", out
43: .toString());
44: }
45:
46: public void testInterceptsWhenWriterMovesLocationInDocumentAndUpdatesPathTracker() {
47:
48: assertEquals(new Path(""), pathTracker.getPath());
49:
50: writer.startNode("foo");
51: assertEquals(new Path("/foo"), pathTracker.getPath());
52:
53: writer.startNode("do");
54: assertEquals(new Path("/foo/do"), pathTracker.getPath());
55:
56: writer.endNode();
57: assertEquals(new Path("/foo"), pathTracker.getPath());
58:
59: writer.endNode();
60: assertEquals(new Path(""), pathTracker.getPath());
61:
62: }
63:
64: }
|