db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1066600 - in /db/torque/torque4/trunk/torque-generator/src: main/java/org/apache/torque/generator/source/SourcePath.java test/java/org/apache/torque/generator/source/SourcePathTest.java
Date Wed, 02 Feb 2011 20:00:46 GMT
Author: tfischer
Date: Wed Feb  2 20:00:45 2011
New Revision: 1066600

URL: http://svn.apache.org/viewvc?rev=1066600&view=rev
Log:
fix getPreceding() in SourcePath

Modified:
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourcePath.java
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/SourcePathTest.java

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourcePath.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourcePath.java?rev=1066600&r1=1066599&r2=1066600&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourcePath.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourcePath.java
Wed Feb  2 20:00:45 2011
@@ -108,7 +108,7 @@ public final class SourcePath
      */
     public static boolean hasPreceding(SourceElement sourceElement)
     {
-        return !getPreceding(sourceElement, null).isEmpty();
+        return !getPreceding(sourceElement, sourceElement.getName()).isEmpty();
     }
 
     /**
@@ -168,9 +168,16 @@ public final class SourcePath
         {
             return result;
         }
+        boolean first = true;
         while (sameLevelIt.hasPrevious())
         {
             SourceElement sameLevelElement = sameLevelIt.previous();
+            // skip first iterated element because it is input element,
+            // but we want to begin before the input element.
+            if (first) {
+                first = false;
+                continue;
+            }
             if (name == null || name.equals(sameLevelElement.getName()))
             {
                 result.add(sameLevelElement);
@@ -224,7 +231,9 @@ public final class SourcePath
 
     /**
      * Returns a ListIterator of the siblings of the input source element.
-     * The iterator is positioned on the input element.
+     * The iterator is positioned such that the next method returns
+     * the element after the input element, and the previous method returns
+     * the input element.
      *
      * @param sourceElement the source element for which the sibling iterator
      *        should be created, not null.

Modified: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/SourcePathTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/SourcePathTest.java?rev=1066600&r1=1066599&r2=1066600&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/SourcePathTest.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/SourcePathTest.java
Wed Feb  2 20:00:45 2011
@@ -20,6 +20,7 @@ package org.apache.torque.generator.sour
  */
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -33,7 +34,9 @@ import org.junit.Test;
 public class SourcePathTest
 {
     private SourceElement root;
-    private SourceElement firstLevel;
+    private SourceElement firstLevel1;
+    private SourceElement firstLevel2;
+    private SourceElement firstLevel3;
     private SourceElement secondLevel;
     private SourceElement thirdLevel;
 
@@ -41,12 +44,14 @@ public class SourcePathTest
     public void setUp()
     {
         root = new SourceElement("root");
-        root.getChildren().add(new SourceElement("firstLevel1"));
-        firstLevel  = new SourceElement("firstLevel2");
-        root.getChildren().add(firstLevel);
-        root.getChildren().add(new SourceElement("firstLevel3"));
+        firstLevel1 = new SourceElement("firstLevel1");
+        root.getChildren().add(firstLevel1);
+        firstLevel2  = new SourceElement("firstLevel2");
+        root.getChildren().add(firstLevel2);
+        firstLevel3 = new SourceElement("firstLevel3");
+        root.getChildren().add(firstLevel3);
         secondLevel = new SourceElement("secondLevel");
-        firstLevel.getChildren().add(secondLevel);
+        firstLevel2.getChildren().add(secondLevel);
         thirdLevel = new SourceElement("thirdLevel");
         secondLevel.getChildren().add(thirdLevel);
     }
@@ -104,4 +109,38 @@ public class SourcePathTest
                 = SourcePath.getElementsFromRoot(root, "/root1");
         assertEquals(0, result.size());
     }
+
+    @Test
+    public void testGetPreceding()
+    {
+        List<SourceElement> result
+                = SourcePath.getPreceding(firstLevel2, "firstLevel1");
+        assertEquals(1, result.size());
+        assertSame(firstLevel1, result.get(0));
+    }
+
+    @Test
+    public void testGetPrecedingNoMatch()
+    {
+        List<SourceElement> result
+                = SourcePath.getPreceding(firstLevel2, "firstLevel2");
+        assertEquals(0, result.size());
+    }
+    @Test
+
+    public void testGetFollowing()
+    {
+        List<SourceElement> result
+                = SourcePath.getFollowing(firstLevel2, "firstLevel3");
+        assertEquals(1, result.size());
+        assertSame(firstLevel3, result.get(0));
+    }
+
+    @Test
+    public void testGetFollowingNoMatch()
+    {
+        List<SourceElement> result
+                = SourcePath.getFollowing(firstLevel2, "firstLevel2");
+        assertEquals(0, result.size());
+    }
 }



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


Mime
View raw message