jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1499781 - in /jackrabbit/oak/trunk/oak-commons/src: main/java/org/apache/jackrabbit/oak/commons/PathUtils.java test/java/org/apache/jackrabbit/oak/commons/PathTest.java test/java/org/apache/jackrabbit/oak/commons/PathUtilsTest.java
Date Thu, 04 Jul 2013 15:16:22 GMT
Author: angela
Date: Thu Jul  4 15:16:22 2013
New Revision: 1499781

URL: http://svn.apache.org/r1499781
Log:
OAK-888 : PathUtils#getDepth returns 1 for empty path

Added:
    jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathUtilsTest.java
  (contents, props changed)
      - copied, changed from r1498991, jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathTest.java
Removed:
    jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathTest.java
Modified:
    jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java

Modified: jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java?rev=1499781&r1=1499780&r2=1499781&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java
Thu Jul  4 15:16:22 2013
@@ -185,6 +185,9 @@ public final class PathUtils {
     public static int getDepth(String path) {
         assert isValid(path);
 
+        if (path.isEmpty()) {
+            return 0;
+        }
         int count = 1, i = 0;
         if (isAbsolutePath(path)) {
             if (denotesRootPath(path)) {

Copied: jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathUtilsTest.java
(from r1498991, jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathUtilsTest.java?p2=jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathUtilsTest.java&p1=jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathTest.java&r1=1498991&r2=1499781&rev=1499781&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathTest.java
(original)
+++ jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathUtilsTest.java
Thu Jul  4 15:16:22 2013
@@ -18,17 +18,19 @@ package org.apache.jackrabbit.oak.common
 
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
+import org.junit.Test;
 
 /**
  * Test the PathUtils class.
  */
-public class PathTest extends TestCase {
+public class PathUtilsTest extends TestCase {
     static boolean assertsEnabled;
 
     static {
         assert assertsEnabled = true;
     }
 
+    @Test
     public void test() {
 
         try {
@@ -57,6 +59,17 @@ public class PathTest extends TestCase {
         test("x", "y");
     }
 
+    @Test
+    public void testGetDepth() {
+        assertEquals(0, PathUtils.getDepth("/"));
+        assertEquals(0, PathUtils.getDepth(""));
+        assertEquals(1, PathUtils.getDepth("/a"));
+        assertEquals(1, PathUtils.getDepth("a"));
+        assertEquals(2, PathUtils.getDepth("/a/b"));
+        assertEquals(2, PathUtils.getDepth("a/b"));
+    }
+
+
     private static int getElementCount(String path) {
         int count = 0;
         for (String p : PathUtils.elements(path)) {
@@ -158,13 +171,6 @@ public class PathTest extends TestCase {
         assertTrue(PathUtils.denotesRoot("/"));
         assertFalse(PathUtils.denotesRoot("/" + parent));
 
-        // getDepth
-        assertEquals(0, PathUtils.getDepth("/"));
-        assertEquals(1, PathUtils.getDepth("/" + parent));
-        assertEquals(2, PathUtils.getDepth("/" + parent + "/" + child));
-        assertEquals(1, PathUtils.getDepth(parent));
-        assertEquals(2, PathUtils.getDepth(parent + "/" + child));
-
         // getName
         assertEquals("", PathUtils.getName("/"));
         assertEquals(parent, PathUtils.getName("/" + parent));

Propchange: jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message