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.HierarchicalStreamReader;
15: import com.thoughtworks.xstream.io.xml.XppReader;
16:
17: import junit.framework.TestCase;
18:
19: import java.io.Reader;
20: import java.io.StringReader;
21:
22: public class PathTrackingReaderTest extends TestCase {
23:
24: public void testDecoratesReaderAndTracksPath() {
25: Reader input = new StringReader("" + "<a>" + " <b><c/></b>"
26: + " <b/>" + " <d/>" + "</a>");
27: HierarchicalStreamReader reader = new XppReader(input);
28: PathTracker pathTracker = new PathTracker();
29:
30: reader = new PathTrackingReader(reader, pathTracker);
31: assertEquals(new Path("/a"), pathTracker.getPath());
32:
33: reader.moveDown();
34: assertEquals(new Path("/a/b"), pathTracker.getPath());
35:
36: reader.moveDown();
37: assertEquals(new Path("/a/b/c"), pathTracker.getPath());
38:
39: reader.moveUp();
40: assertEquals(new Path("/a/b"), pathTracker.getPath());
41:
42: reader.moveUp();
43: reader.moveDown();
44: assertEquals(new Path("/a/b[2]"), pathTracker.getPath());
45:
46: reader.moveUp();
47: reader.moveDown();
48: assertEquals(new Path("/a/d"), pathTracker.getPath());
49:
50: reader.moveUp();
51: assertEquals(new Path("/a"), pathTracker.getPath());
52: }
53: }
|