commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r151540 - jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/ContextTestCase.java
Date Sun, 06 Feb 2005 04:37:18 GMT
Author: skitching
Date: Sat Feb  5 20:37:18 2005
New Revision: 151540

URL: http://svn.apache.org/viewcvs?view=rev&rev=151540
Log:
Added tests for setRoot/getRoot methods.

Modified:
    jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/ContextTestCase.java

Modified: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/ContextTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/ContextTestCase.java?view=diff&r1=151539&r2=151540
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/ContextTestCase.java
(original)
+++ jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/ContextTestCase.java
Sat Feb  5 20:37:18 2005
@@ -124,8 +124,69 @@
     /**
      * Test storage of the 'root' variable
      */
-    public void testRoot() {
+    public void testRoot1() {
         // setRoot, getRoot
+        SAXHandler saxHandler = new SAXHandler();
+        Log log = saxHandler.getLogger();
+        Context context = new Context(saxHandler, log);
+
+        Object root;
+
+        // initially, getRoot returns null
+        root = context.getRoot();
+        assertNull("Initial root object is null", root);
+        
+        // after setRoot, returns the object set
+        context.setRoot("root1");
+        root = context.getRoot();
+        assertEquals("setRoot/getRoot retrieves set object", "root1", root);
+        
+        // can set multiple times, always returns the last object set
+        // also, stack depth should be max of 1
+        context.setRoot("root2");
+        context.setRoot("root3");
+        context.setRoot("root4");
+        root = context.getRoot();
+        assertEquals("setRoot multiple times", "root4", root);
+        assertEquals(context.getStackSize(), 1);
+    }
+    
+    /**
+     * Test storage of the 'root' variable
+     */
+    public void testRoot2() {
+        // setRoot, getRoot
+        SAXHandler saxHandler = new SAXHandler();
+        Log log = saxHandler.getLogger();
+        Context context = new Context(saxHandler, log);
+
+        Object root;
+
+        // initially, getRoot returns null
+        root = context.getRoot();
+        assertNull("Initial root object is null", root);
+        
+        // after pushing an object, root is set
+        context.push("item1");
+        root = context.getRoot();
+        assertEquals("push sets root", "item1", root);
+        
+        // after pushing other objects, root does not change
+        context.push("item2");
+        context.push("item3");
+        context.push("item4");
+        root = context.getRoot();
+        assertEquals("push sets root", "item1", root);
+        assertEquals("push increases stackdepth", 4, context.getStackSize());
+        
+        // after popping all objects off stack, root remains set
+        context.pop();
+        context.pop();
+        context.pop();
+        context.pop();
+        root = context.getRoot();
+        assertEquals("root remains set after pop", "item1", root);
+        assertEquals("root remains set after pop", 0, context.getStackSize());
     }
     
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message