KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > io > path > PathTrackingWriterTest


1 package com.thoughtworks.xstream.io.path;
2
3 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
4 import com.thoughtworks.xstream.io.xml.CompactWriter;
5 import junit.framework.TestCase;
6
7 import java.io.StringWriter JavaDoc;
8
9 public class PathTrackingWriterTest extends TestCase {
10     private StringWriter JavaDoc out;
11     private HierarchicalStreamWriter writer;
12     private PathTracker pathTracker;
13
14     protected void setUp() throws Exception JavaDoc {
15         super.setUp();
16         pathTracker = new PathTracker();
17         out = new StringWriter JavaDoc();
18         HierarchicalStreamWriter originalWriter = new CompactWriter(out);
19
20         writer = new PathTrackingWriter(originalWriter, pathTracker);
21     }
22
23     public void testDecoratesXmlWriterProxyingAllInvocations() {
24
25         writer.startNode("foo");
26         writer.addAttribute("att", "something");
27         writer.setValue("getValue");
28         writer.endNode();
29
30         assertEquals("<foo att=\"something\">getValue</foo>", out.toString());
31     }
32
33     public void testInterceptsWhenWriterMovesLocationInDocumentAndUpdatesPathTracker() {
34
35         assertEquals("", pathTracker.getCurrentPath());
36
37         writer.startNode("foo");
38         assertEquals("/foo", pathTracker.getCurrentPath());
39
40         writer.startNode("do");
41         assertEquals("/foo/do", pathTracker.getCurrentPath());
42
43         writer.endNode();
44         assertEquals("/foo", pathTracker.getCurrentPath());
45
46         writer.endNode();
47         assertEquals("", pathTracker.getCurrentPath());
48
49     }
50
51 }
52
Popular Tags