pathtrackertest.java

来自「xstream是一个把java object序列化成xml文件的开源库,轻便好用」· Java 代码 · 共 123 行

JAVA
123
字号
package com.thoughtworks.xstream.io.path;import junit.framework.TestCase;public class PathTrackerTest extends TestCase {    private PathTracker pathTracker;    protected void setUp() throws Exception {        super.setUp();        // small initial capacity to ensure resizing works        pathTracker = new PathTracker(1);    }    public void testExposesXpathLikeExpressionOfLocationInWriter() {        assertEquals(new Path(""), pathTracker.getPath());        // <root>        pathTracker.pushElement("root");        assertEquals(new Path("/root"), pathTracker.getPath());        //   <childA>        pathTracker.pushElement("childA");        assertEquals(new Path("/root/childA"), pathTracker.getPath());        //   </childA>        pathTracker.popElement();        assertEquals(new Path("/root"), pathTracker.getPath());        //   <childB>        pathTracker.pushElement("childB");        assertEquals(new Path("/root/childB"), pathTracker.getPath());        //     <grandchild>        pathTracker.pushElement("grandchild");        assertEquals(new Path("/root/childB/grandchild"), pathTracker.getPath());        //     </grandchild>        pathTracker.popElement();        assertEquals(new Path("/root/childB"), pathTracker.getPath());        //   </childB>        pathTracker.popElement();        assertEquals(new Path("/root"), pathTracker.getPath());        // </root>        pathTracker.popElement();        assertEquals(new Path(""), pathTracker.getPath());    }    public void testAddsIndexIfSiblingOfSameTypeAlreadyExists() {        // <root>        pathTracker.pushElement("root");        //   <child>        pathTracker.pushElement("child");        assertEquals(new Path("/root/child"), pathTracker.getPath());        //   </child>        pathTracker.popElement();        //   <child>        pathTracker.pushElement("child");        assertEquals(new Path("/root/child[2]"), pathTracker.getPath());        //   </child>        pathTracker.popElement();        //   <another>        pathTracker.pushElement("another");        assertEquals(new Path("/root/another"), pathTracker.getPath());        //   </another>        pathTracker.popElement();        //   <child>        pathTracker.pushElement("child");        assertEquals(new Path("/root/child[3]"), pathTracker.getPath());        //   </child>        pathTracker.popElement();        // ...    }    public void testAssociatesIndexOnlyWithDirectParent() {        // <root>        pathTracker.pushElement("root");        //   <child>        pathTracker.pushElement("child");        //     <child>        pathTracker.pushElement("child");        assertEquals(new Path("/root/child/child"), pathTracker.getPath());        //     </child>        pathTracker.popElement();        //     <child>        pathTracker.pushElement("child");        assertEquals(new Path("/root/child/child[2]"), pathTracker.getPath());        //     </child>        pathTracker.popElement();        //   </child>        pathTracker.popElement();        //   <child>        pathTracker.pushElement("child");        //     <child>        pathTracker.pushElement("child");        assertEquals(new Path("/root/child[2]/child"), pathTracker.getPath());        //     </child>        pathTracker.popElement();        //     <child>        pathTracker.pushElement("child");        assertEquals(new Path("/root/child[2]/child[2]"), pathTracker.getPath());        // ...    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?