You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2015/06/15 11:27:16 UTC

svn commit: r1685521 - in /sling/trunk/testing/mocks/osgi-mock/src: main/java/org/apache/sling/testing/mock/osgi/MockBundle.java test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java

Author: rombert
Date: Mon Jun 15 09:27:16 2015
New Revision: 1685521

URL: http://svn.apache.org/r1685521
Log:
SLING-4781 - Implement MockBundle.getEntryPaths 

Cleanup MockBundle.getEntry to always use an absolute path

Modified:
    sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
    sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java

Modified: sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java?rev=1685521&r1=1685520&r2=1685521&view=diff
==============================================================================
--- sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java (original)
+++ sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java Mon Jun 15 09:27:16 2015
@@ -70,20 +70,9 @@ public final class MockBundle implements
     @Override
     public URL getEntry(final String name) {
         
-        // the original implementation of this method performed getClass().getResource()
-        // however, this means that the it does not work out-of-the-box with paths
-        // returned from getEntryPaths(), which are by definition relative
-        
-        // as a fallback we make sure the resource is absolute if the relative one does
-        // not get a result, but perhaps we should enforce a relative lookup at all times
-        
-        // try to load resource from classpath
-        URL resource = getClass().getResource(name);
-        
-        if ( resource == null || ! name.startsWith("/")) {
-            resource = getClass().getResource("/" + name);
-        }
-        return resource;
+        String nameToQuery = name.startsWith("/") ? name : "/" + name;
+
+        return getClass().getResource(nameToQuery);
     }
 
     @Override

Modified: sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java?rev=1685521&r1=1685520&r2=1685521&view=diff
==============================================================================
--- sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java (original)
+++ sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java Mon Jun 15 09:27:16 2015
@@ -57,6 +57,7 @@ public class MockBundleTest {
     @Test
     public void testGetEntry() {
         assertNotNull(bundle.getEntry("/META-INF/test.txt"));
+        assertNotNull(bundle.getEntry("META-INF/test.txt"));
         assertNull(bundle.getEntry("/invalid"));
     }