jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1346879 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
Date Wed, 06 Jun 2012 13:20:53 GMT
Author: angela
Date: Wed Jun  6 13:20:52 2012
New Revision: 1346879

URL: http://svn.apache.org/viewvc?rev=1346879&view=rev
Log:
minor improvement (prevent NPE in AbstractNameMapper)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java?rev=1346879&r1=1346878&r2=1346879&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
Wed Jun  6 13:20:52 2012
@@ -26,9 +26,10 @@ public abstract class AbstractNameMapper
 
     @Override
     public String getOakName(String jcrName) {
-
+        if (jcrName == null || jcrName.isEmpty()) {
+            return jcrName;
+        }
         int pos = jcrName.indexOf(':');
-        
         if (pos < 0) {
             // no colon
             return jcrName.startsWith("{}") ? jcrName.substring(2) : jcrName;
@@ -66,6 +67,10 @@ public abstract class AbstractNameMapper
 
     @Override
     public String getJcrName(String oakName) {
+        if (oakName == null || oakName.isEmpty()) {
+            return oakName;
+        }
+
         int pos = oakName.indexOf(':');
         if (pos < 0) {
             // non-prefixed
@@ -88,5 +93,4 @@ public abstract class AbstractNameMapper
             }
         }
     }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java?rev=1346879&r1=1346878&r2=1346879&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
Wed Jun  6 13:20:52 2012
@@ -29,12 +29,11 @@ import static org.junit.Assert.assertNul
 import static org.junit.Assert.fail;
 
 public class NamePathMapperImplTest {
+    private TestNameMapper mapper = new TestNameMapper(true);
+    private NamePathMapper npMapper = new NamePathMapperImpl(mapper);
 
     @Test
     public void testInvalidIdentifierPath() {
-        TestNameMapper mapper = new TestNameMapper(true);
-        NamePathMapper npMapper = new NamePathMapperImpl(mapper);
-
         List<String> invalid = new ArrayList<String>();
         invalid.add('[' + UUID.randomUUID().toString() + "]abc");
         invalid.add('[' + UUID.randomUUID().toString() + "]/a/b/c");
@@ -45,10 +44,19 @@ public class NamePathMapperImplTest {
     }
 
     @Test
-    public void testJcrToOak() {
-        TestNameMapper mapper = new TestNameMapper(true);
-        NamePathMapper npMapper = new NamePathMapperImpl(mapper);
+    public void testNullName() {
+        assertNull(npMapper.getJcrName(null));
+        assertNull(npMapper.getOakName(null));
+    }
+
+    @Test
+    public void testEmptyName() {
+        assertEquals("", npMapper.getJcrName(""));
+        assertEquals("", npMapper.getOakName(""));
+    }
 
+    @Test
+    public void testJcrToOak() {
         assertEquals("/", npMapper.getOakPath("/"));
         assertEquals("foo", npMapper.getOakPath("{}foo"));
         assertEquals("/oak-foo:bar", npMapper.getOakPath("/foo:bar"));
@@ -73,9 +81,6 @@ public class NamePathMapperImplTest {
 
     @Test
     public void testJcrToOakKeepIndex() {
-        TestNameMapper mapper = new TestNameMapper(true);
-        NamePathMapper npMapper = new NamePathMapperImpl(mapper);
-
         assertEquals("/", npMapper.getOakPathKeepIndex("/"));
         assertEquals("foo", npMapper.getOakPathKeepIndex("{}foo"));
         assertEquals("/oak-foo:bar", npMapper.getOakPathKeepIndex("/foo:bar"));
@@ -111,9 +116,6 @@ public class NamePathMapperImplTest {
 
     @Test
     public void testOakToJcr() {
-        TestNameMapper mapper = new TestNameMapper(true);
-        NamePathMapper npMapper = new NamePathMapperImpl(mapper);
-
         assertEquals("/jcr-foo:bar", npMapper.getJcrPath("/foo:bar"));
         assertEquals("/jcr-foo:bar/jcr-quu:qux", npMapper.getJcrPath("/foo:bar/quu:qux"));
         assertEquals("jcr-foo:bar", npMapper.getJcrPath("foo:bar"));



Mime
View raw message