You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2018/03/20 09:56:13 UTC

[GitHub] stefanseifert closed pull request #2: SLING-7550 Return services even when class param is null in

stefanseifert closed pull request #2: SLING-7550 Return services even when class param is null in
URL: https://github.com/apache/sling-org-apache-sling-testing-osgi-mock/pull/2
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
index 7a2e87d..095d3dc 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
@@ -93,7 +93,7 @@ public void unregister() {
 
     boolean matches(final String clazz, final String filter) throws InvalidSyntaxException {
         // ignore filter for now
-        return this.clazzes.contains(clazz)
+        return (clazz == null || this.clazzes.contains(clazz))
                 && (filter == null || new FilterImpl(filter).match(properties));
     }
     
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
index 1760ced..e031f72 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
@@ -297,6 +297,18 @@ public void testGetServiceOrderWithoutRanking() {
         
         bundleContext.ungetService(ref);
     }
+    
+    @Test
+    public void testGetServicesWithNoClassOnlyFilter() throws InvalidSyntaxException {
+        bundleContext.registerService(String.class, "service1", testProperty());
+        bundleContext.registerService(Long.class, new Long(2), testProperty());
+        bundleContext.registerService(Integer.class, new Integer(9), testProperty());
+        
+        // should return service with lowest service id = which was registered first
+        ServiceReference[] refs = bundleContext.getServiceReferences((String)null, "(prop1=value1)");
+        assertNotNull(refs);
+        assertEquals(3, refs.length);
+    }
 
     private static Dictionary<String, Object> ranking(final Integer serviceRanking) {
         Dictionary<String, Object> props = new Hashtable<String, Object>();
@@ -305,5 +317,11 @@ public void testGetServiceOrderWithoutRanking() {
         }
         return props;
     }
+    
+    private static Dictionary<String, Object> testProperty() {
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("prop1", "value1");
+        return props;
+    }
 
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services