sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1719219 - in /sling/trunk/testing/mocks/osgi-mock/src: main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
Date Thu, 10 Dec 2015 21:39:16 GMT
Author: sseifert
Date: Thu Dec 10 21:39:16 2015
New Revision: 1719219

URL: http://svn.apache.org/viewvc?rev=1719219&view=rev
Log:
SLING-5372 osgi-mock: MockBundleContext.getServices(Class,String) throws NPE when no services
found

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

Modified: sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java?rev=1719219&r1=1719218&r2=1719219&view=diff
==============================================================================
--- sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
(original)
+++ sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
Thu Dec 10 21:39:16 2015
@@ -218,7 +218,13 @@ class MockBundleContext implements Bundl
     @SuppressWarnings("unchecked")
     @Override
     public <S> Collection<ServiceReference<S>> getServiceReferences(Class<S>
clazz, String filter) throws InvalidSyntaxException {
-        return ImmutableList.<ServiceReference<S>>copyOf(getServiceReferences(clazz.getName(),
filter));
+        ServiceReference<S>[] result = getServiceReferences(clazz.getName(), filter);
+        if (result == null) {
+            return ImmutableList.<ServiceReference<S>>of();
+        }
+        else {
+            return ImmutableList.<ServiceReference<S>>copyOf(result);
+        }
     }
 
     @SuppressWarnings("unchecked")

Modified: sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java?rev=1719219&r1=1719218&r2=1719219&view=diff
==============================================================================
--- sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
(original)
+++ sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
Thu Dec 10 21:39:16 2015
@@ -29,6 +29,7 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
+import java.util.Collection;
 import java.util.Dictionary;
 import java.util.Hashtable;
 
@@ -92,6 +93,10 @@ public class MockBundleContextTest {
         assertSame(reg1.getReference(), refsString[0]);
         assertSame(reg2.getReference(), refsString[1]);
 
+        Collection<ServiceReference<String>> refColString = bundleContext.getServiceReferences(String.class,
null);
+        assertEquals(2, refColString.size());
+        assertSame(reg1.getReference(), refColString.iterator().next());
+
         ServiceReference<?>[] refsInteger = bundleContext.getServiceReferences(Integer.class.getName(),
null);
         assertEquals(2, refsInteger.length);
         assertSame(reg3.getReference(), refsInteger[0]);
@@ -112,6 +117,16 @@ public class MockBundleContextTest {
     }
     
     @Test
+    public void testNoServiceReferences() throws InvalidSyntaxException {
+        ServiceReference<?>[] refs = bundleContext.getServiceReferences(String.class.getName(),
null);
+        assertNull(refs);
+
+        Collection<ServiceReference<String>> refCol = bundleContext.getServiceReferences(String.class,
null);
+        assertNotNull(refCol);
+        assertTrue(refCol.isEmpty());
+    }
+    
+    @Test
     public void testServiceUnregistration() {
         // prepare test services
         String clazz1 = String.class.getName();



Mime
View raw message