Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 76DD7CEEB for ; Wed, 30 May 2012 13:37:09 +0000 (UTC) Received: (qmail 16214 invoked by uid 500); 30 May 2012 13:37:09 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 16191 invoked by uid 500); 30 May 2012 13:37:09 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-commits@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 16183 invoked by uid 99); 30 May 2012 13:37:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 May 2012 13:37:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 May 2012 13:37:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3D7DA2388847; Wed, 30 May 2012 13:36:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1344255 - /jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathTest.java Date: Wed, 30 May 2012 13:36:45 -0000 To: oak-commits@jackrabbit.apache.org From: thomasm@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120530133645.3D7DA2388847@eris.apache.org> Author: thomasm Date: Wed May 30 13:36:44 2012 New Revision: 1344255 URL: http://svn.apache.org/viewvc?rev=1344255&view=rev Log: OAK-77 Consolidate Utilities - use PathUtils.elements instead of PathUtils.split Modified: jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/PathTest.java Modified: 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/PathTest.java?rev=1344255&r1=1344254&r2=1344255&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/PathTest.java Wed May 30 13:36:44 2012 @@ -19,8 +19,6 @@ package org.apache.jackrabbit.oak.common import junit.framework.AssertionFailedError; import junit.framework.TestCase; -import java.util.Iterator; - public class PathTest extends TestCase { static boolean assertsEnabled; @@ -56,21 +54,41 @@ public class PathTest extends TestCase { test("x", "y"); } + private int getElementCount(String path) { + int count = 0; + for (String p : PathUtils.elements(path)) { + assertFalse(PathUtils.isAbsolute(p)); + count++; + } + return count; + } + + private String getElement(String path, int index) { + int count = 0; + for (String p : PathUtils.elements(path)) { + if (index == count++) { + return p; + } + } + fail(); + return ""; + } + private void test(String parent, String child) { // split - assertEquals(0, PathUtils.split("").length); - assertEquals(0, PathUtils.split("/").length); - assertEquals(1, PathUtils.split(parent).length); - assertEquals(2, PathUtils.split(parent + "/" + child).length); - assertEquals(1, PathUtils.split("/" + parent).length); - assertEquals(2, PathUtils.split("/" + parent + "/" + child).length); - assertEquals(3, PathUtils.split("/" + parent + "/" + child + "/" + child).length); - assertEquals(parent, PathUtils.split(parent)[0]); - assertEquals(parent, PathUtils.split(parent + "/" + child)[0]); - assertEquals(child, PathUtils.split(parent + "/" + child)[1]); - assertEquals(child, PathUtils.split(parent + "/" + child + "/" + child + "1")[1]); - assertEquals(child + "1", PathUtils.split(parent + "/" + child + "/" + child + "1")[2]); + assertEquals(0, getElementCount("")); + assertEquals(0, getElementCount("/")); + assertEquals(1, getElementCount(parent)); + assertEquals(2, getElementCount(parent + "/" + child)); + assertEquals(1, getElementCount("/" + parent)); + assertEquals(2, getElementCount("/" + parent + "/" + child)); + assertEquals(3, getElementCount("/" + parent + "/" + child + "/" + child)); + assertEquals(parent, getElement(parent, 0)); + assertEquals(parent, getElement(parent + "/" + child, 0)); + assertEquals(child, getElement(parent + "/" + child, 1)); + assertEquals(child, getElement(parent + "/" + child + "/" + child + "1", 1)); + assertEquals(child + "1", getElement(parent + "/" + child + "/" + child + "1", 2)); // concat assertEquals(parent + "/" + child, PathUtils.concat(parent, child)); @@ -414,30 +432,9 @@ public class PathTest extends TestCase { } catch (AssertionError e) { // expected } - try { - PathUtils.split(invalid); - if (assertsEnabled) { - fail(); - } - } catch (AssertionFailedError e) { - throw e; - } catch (AssertionError e) { - // expected - } } public void testPathElements() { - String[] paths = new String[]{"", "/", "/a", "a", "/abc/def/ghj", "abc/def/ghj"}; - for (String path : paths) { - String[] elements = PathUtils.split(path); - Iterator it = PathUtils.elements(path).iterator(); - for (String element : elements) { - assertTrue(it.hasNext()); - assertEquals(element, it.next()); - } - assertFalse(it.hasNext()); - } - String[] invalidPaths = new String[]{"//", "/a/", "a/", "/a//", "a//b"}; for (String path: invalidPaths) { try {