KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thoughtworks.xstream.io.path;
2
3 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
4 import com.thoughtworks.xstream.io.xml.XppReader;
5 import junit.framework.TestCase;
6
7 import java.io.Reader JavaDoc;
8 import java.io.StringReader JavaDoc;
9
10 public class PathTrackingReaderTest extends TestCase {
11
12     public void testDecoratesReaderAndTracksPath() {
13         Reader input = new StringReader JavaDoc("" +
14                 "<a>" +
15                 " <b><c/></b>" +
16                 " <b/>" +
17                 " <d/>" +
18                 "</a>");
19         HierarchicalStreamReader reader = new XppReader(input);
20         PathTracker pathTracker = new PathTracker();
21
22         reader = new PathTrackingReader(reader, pathTracker);
23         assertEquals("/a", pathTracker.getCurrentPath());
24
25         reader.moveDown();
26         assertEquals("/a/b", pathTracker.getCurrentPath());
27
28         reader.moveDown();
29         assertEquals("/a/b/c", pathTracker.getCurrentPath());
30
31         reader.moveUp();
32         assertEquals("/a/b", pathTracker.getCurrentPath());
33
34         reader.moveUp();
35         reader.moveDown();
36         assertEquals("/a/b[2]", pathTracker.getCurrentPath());
37
38         reader.moveUp();
39         reader.moveDown();
40         assertEquals("/a/d", pathTracker.getCurrentPath());
41
42         reader.moveUp();
43         assertEquals("/a", pathTracker.getCurrentPath());
44     }
45 }
46
Popular Tags