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 2017/11/07 10:20:49 UTC

[sling-org-apache-sling-testing-osgi-mock] 01/10: SLING-5323 Update to OSGi R6

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.testing.osgi-mock-2.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit 9618e26a3b43964f05ce3382f4123b519a4ee757
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Nov 23 20:32:53 2015 +0000

    SLING-5323 Update to OSGi R6
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1715946 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 50 +++++++------
 .../apache/sling/testing/mock/osgi/MapUtil.java    |  1 -
 .../sling/testing/mock/osgi/MatchAllFilter.java    |  6 ++
 .../apache/sling/testing/mock/osgi/MockBundle.java | 14 ++--
 .../sling/testing/mock/osgi/MockBundleContext.java | 47 ++++++------
 .../testing/mock/osgi/MockComponentContext.java    |  4 +-
 .../sling/testing/mock/osgi/MockConfiguration.java |  7 +-
 .../apache/sling/testing/mock/osgi/MockOsgi.java   | 84 +---------------------
 .../testing/mock/osgi/MockServiceReference.java    |  8 +--
 .../testing/mock/osgi/MockServiceRegistration.java | 19 ++---
 .../sling/testing/mock/osgi/OsgiServiceUtil.java   |  6 +-
 .../sling/testing/mock/osgi/package-info.java      |  2 +-
 .../testing/mock/osgi/MockBundleContextTest.java   | 20 +++---
 .../mock/osgi/MockComponentContextTest.java        |  2 +-
 .../testing/mock/osgi/OsgiServiceUtilTest.java     |  3 +-
 .../mock/osgi/context/OsgiContextImplTest.java     |  2 +-
 16 files changed, 109 insertions(+), 166 deletions(-)

diff --git a/pom.xml b/pom.xml
index 1f9613d..085b1ad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
     </parent>
 
     <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-    <version>1.7.1-SNAPSHOT</version>
+    <version>2.0.0-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <name>Apache Sling Testing OSGi Mock</name>
@@ -39,17 +39,43 @@
         <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock</developerConnection>
         <url>http://svn.apache.org/viewvc/sling/trunk/testing/mocks/osgi-mock</url>
     </scm>
+    
+    <properties>
+        <!-- OSGi mocks 2.x only support Java 7, 1.x still supports Java 6 -->
+        <sling.java.version>7</sling.java.version>
+    </properties>
 
     <dependencies>
   
+        <!-- This version of OSGi mocks is targeted at OSGi R6. osgi-mocks 1.x is compatible with older versions. -->
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
+            <version>6.0.0</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.cm</artifactId>
+            <version>1.5.0</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.event</artifactId>
+            <version>1.3.1</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
+            <artifactId>org.osgi.service.log</artifactId>
+            <version>1.3.0</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component</artifactId>
+            <version>1.3.0</version>
             <scope>compile</scope>
         </dependency>
     
@@ -136,24 +162,4 @@
         </plugins>
     </build>
     
-    <profiles>
-      <profile>
-        <id>osgi-6</id>
-        <dependencies>
-          <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-            <version>6.0.0</version>
-            <scope>provided</scope>
-          </dependency>
-          <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-            <version>5.0.0</version>
-            <scope>provided</scope>
-          </dependency>
-        </dependencies>
-      </profile>
-    </profiles>
-  
 </project>
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java b/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java
index 45d7a31..e53442b 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java
@@ -71,7 +71,6 @@ final class MapUtil {
      * @param properties Properties from unit test code or null if none where passed
      * @return Merged properties
      */
-    @SuppressWarnings("unchecked")
     public static Map<String, Object> propertiesMergeWithOsgiMetadata(Object target,
             ConfigurationAdmin configAdmin,
             Map<String, Object> properties) {
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MatchAllFilter.java b/src/main/java/org/apache/sling/testing/mock/osgi/MatchAllFilter.java
index 0a7aaf3..3ef02df 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MatchAllFilter.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MatchAllFilter.java
@@ -19,6 +19,7 @@
 package org.apache.sling.testing.mock.osgi;
 
 import java.util.Dictionary;
+import java.util.Map;
 
 import org.osgi.framework.Filter;
 import org.osgi.framework.ServiceReference;
@@ -43,4 +44,9 @@ class MatchAllFilter implements Filter {
         return true;
     }
 
+    @Override
+    public boolean matches(Map<String, ?> map) {
+        return true;
+    }
+
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
index 1a7a7c1..1fc9483 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
@@ -186,7 +186,7 @@ public final class MockBundle implements Bundle {
     }
 
     @Override
-    public ServiceReference[] getRegisteredServices() {
+    public ServiceReference<?>[] getRegisteredServices() {
         throw new UnsupportedOperationException();
     }
 
@@ -201,7 +201,7 @@ public final class MockBundle implements Bundle {
     }
 
     @Override
-    public ServiceReference[] getServicesInUse() {
+    public ServiceReference<?>[] getServicesInUse() {
         throw new UnsupportedOperationException();
     }
 
@@ -250,27 +250,27 @@ public final class MockBundle implements Bundle {
         throw new UnsupportedOperationException();
     }
 
-    // this is part of org.osgi 4.2.0
+    @Override
     public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(final int signersType) {
         throw new UnsupportedOperationException();
     }
 
-    // this is part of org.osgi 4.2.0
+    @Override
     public Version getVersion() {
         throw new UnsupportedOperationException();
     }
 
-    // this is part of org.osgi.core 6.0.0
+    @Override
     public int compareTo(Bundle o) {
         throw new UnsupportedOperationException();
     }
 
-    // this is part of org.osgi.core 6.0.0
+    @Override
     public <A> A adapt(Class<A> type) {
         throw new UnsupportedOperationException();
     }
 
-    // this is part of org.osgi.core 6.0.0
+    @Override
     public File getDataFile(String filename) {
         throw new UnsupportedOperationException();
     }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
index 786fad7..6a659cb 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
@@ -47,6 +47,7 @@ import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceObjects;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.cm.ConfigurationAdmin;
@@ -86,6 +87,7 @@ class MockBundleContext implements BundleContext {
         }
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public ServiceRegistration registerService(final String clazz, final Object service, final Dictionary properties) {
         String[] clazzes;
@@ -97,8 +99,9 @@ class MockBundleContext implements BundleContext {
         return registerService(clazzes, service, properties);
     }
 
-    // this is part of org.osgi.core 6.0.0
-    public <S> ServiceRegistration registerService(Class<S> clazz, S service, Dictionary<String, ?> properties) {
+    @SuppressWarnings("unchecked")
+    @Override
+    public <S> ServiceRegistration<S> registerService(Class<S> clazz, S service, Dictionary<String, ?> properties) {
         return registerService(clazz.getName(), service, properties);
     }
 
@@ -171,6 +174,7 @@ class MockBundleContext implements BundleContext {
         }
     }
     
+    @SuppressWarnings("unchecked")
     @Override
     public ServiceReference getServiceReference(final String clazz) {
         try {
@@ -185,11 +189,13 @@ class MockBundleContext implements BundleContext {
         return null;
     }
 
-    // this is part of org.osgi.core 6.0.0
-    public ServiceReference getServiceReference(Class clazz) {
+    @SuppressWarnings("unchecked")
+    @Override
+    public <S> ServiceReference<S> getServiceReference(Class<S> clazz) {
         return getServiceReference(clazz.getName());
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public ServiceReference[] getServiceReferences(final String clazz, final String filter) throws InvalidSyntaxException {
         Set<ServiceReference> result = new TreeSet<ServiceReference>();
@@ -205,11 +211,13 @@ class MockBundleContext implements BundleContext {
         }
     }
 
-    // this is part of org.osgi.core 6.0.0
-    public Collection<ServiceReference> getServiceReferences(Class clazz, String filter) throws InvalidSyntaxException {
-        return ImmutableList.<ServiceReference>copyOf(getServiceReferences(clazz.getName(), filter));
+    @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));
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public ServiceReference[] getAllServiceReferences(final String clazz, final String filter) throws InvalidSyntaxException {
         // for now just do the same as getServiceReferences
@@ -217,8 +225,8 @@ class MockBundleContext implements BundleContext {
     }
 
     @Override
-    public Object getService(final ServiceReference serviceReference) {
-        return ((MockServiceReference)serviceReference).getService();
+    public <S> S getService(final ServiceReference<S> serviceReference) {
+        return ((MockServiceReference<S>)serviceReference).getService();
     }
 
     @Override
@@ -284,10 +292,11 @@ class MockBundleContext implements BundleContext {
         // accept method, but ignore it
     }
 
-    Object locateService(final String name, final ServiceReference reference) {
-        for (MockServiceRegistration serviceRegistration : this.registeredServices) {
+    @SuppressWarnings("unchecked")
+    <S> S locateService(final String name, final ServiceReference<S> reference) {
+        for (MockServiceRegistration<?> serviceRegistration : this.registeredServices) {
             if (serviceRegistration.getReference() == reference) {
-                return serviceRegistration.getService();
+                return (S)serviceRegistration.getService();
             }
         }
         return null;
@@ -308,7 +317,7 @@ class MockBundleContext implements BundleContext {
      * Deactivates all bundles registered in this mocked bundle context.
      */
     public void shutdown() {
-        for (MockServiceRegistration serviceRegistration : ImmutableList.copyOf(registeredServices).reverse()) {
+        for (MockServiceRegistration<?> serviceRegistration : ImmutableList.copyOf(registeredServices).reverse()) {
             try {
                 MockOsgi.deactivate(serviceRegistration.getService(), this, serviceRegistration.getProperties());
             }
@@ -339,21 +348,19 @@ class MockBundleContext implements BundleContext {
         throw new UnsupportedOperationException();
     }
 
-    // this is part of org.osgi.core 6.0.0
+    @Override
     public Bundle getBundle(String location) {
         throw new UnsupportedOperationException();
     }
 
-    // this is part of org.osgi.core 6.0.0
-    public <S> ServiceRegistration registerService(Class<S> clazz, ServiceFactory factory, Dictionary<String, ?> properties) {
+    @Override
+    public <S> ServiceRegistration<S> registerService(Class<S> clazz, ServiceFactory<S> factory, Dictionary<String, ?> properties) {
         throw new UnsupportedOperationException();
     }
 
-    // this is part of org.osgi.core 6.0.0
-    /* class org.osgi.framework.ServiceObjects does not exist in older OSGi versions
-    public ServiceObjects getServiceObjects(ServiceReference reference) {
+    @Override
+    public <S> ServiceObjects<S> getServiceObjects(ServiceReference<S> reference) {
         throw new UnsupportedOperationException();
     }
-    */
 
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockComponentContext.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockComponentContext.java
index 78154a5..a00ec72 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockComponentContext.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockComponentContext.java
@@ -48,7 +48,7 @@ class MockComponentContext implements ComponentContext {
     }
 
     @Override
-    public Object locateService(final String name, final ServiceReference reference) {
+    public <S> S locateService(final String name, final ServiceReference<S> reference) {
         return this.bundleContext.locateService(name, reference);
     }
 
@@ -79,7 +79,7 @@ class MockComponentContext implements ComponentContext {
     }
 
     @Override
-    public ServiceReference getServiceReference() {
+    public ServiceReference<?> getServiceReference() {
         throw new UnsupportedOperationException();
     }
 
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockConfiguration.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockConfiguration.java
index 4959cb6..7bcac56 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockConfiguration.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockConfiguration.java
@@ -46,7 +46,7 @@ class MockConfiguration implements Configuration {
     }
 
     @Override
-    public Dictionary getProperties() {
+    public Dictionary<String, Object> getProperties() {
         // return copy of dictionary
         return new Hashtable<String,Object>(MapUtil.toMap(props));
     }
@@ -100,4 +100,9 @@ class MockConfiguration implements Configuration {
         throw new UnsupportedOperationException();
     }
 
+    @Override
+    public long getChangeCount() {
+        throw new UnsupportedOperationException();
+    }
+
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
index a189fda..431ef27 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
@@ -130,18 +130,6 @@ public final class MockOsgi {
     /**
      * Simulate activation of service instance. Invokes the @Activate annotated method.
      * @param target Service instance.
-     * @return true if activation method was called. False if no activate method is defined.
-     * @deprecated Please use {@link #activate(Object, BundleContext)}
-     *   and shutdown the bundle context after usage.
-     */
-    @Deprecated
-    public static boolean activate(Object target) {
-        return MockOsgi.activate(target, (Dictionary<String, Object>)null);
-    }
-
-    /**
-     * Simulate activation of service instance. Invokes the @Activate annotated method.
-     * @param target Service instance.
      * @param bundleContext Bundle context
      * @return true if activation method was called. False if no activate method is defined.
      */
@@ -152,34 +140,6 @@ public final class MockOsgi {
     /**
      * Simulate activation of service instance. Invokes the @Activate annotated method.
      * @param target Service instance.
-     * @param properties Properties
-     * @return true if activation method was called. False if no activate method is defined.
-     * @deprecated Please use {@link #activate(Object, BundleContext, Dictionary)}
-     *   and shutdown the bundle context after usage.
-     */
-    @Deprecated
-    public static boolean activate(Object target, Dictionary<String, Object> properties) {
-        Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, null, properties);
-        ComponentContext componentContext = newComponentContext(mergedProperties);
-        return OsgiServiceUtil.activateDeactivate(target, componentContext, true);
-    }
-
-    /**
-     * Simulate activation of service instance. Invokes the @Activate annotated method.
-     * @param target Service instance.
-     * @param properties Properties
-     * @return true if activation method was called. False if no activate method is defined.
-     * @deprecated Please use {@link #activate(Object, BundleContext, Map)}
-     *   and shutdown the bundle context after usage.
-     */
-    @Deprecated
-    public static boolean activate(Object target, Map<String, Object> properties) {
-        return activate(target, toDictionary(properties));
-    }
-
-    /**
-     * Simulate activation of service instance. Invokes the @Activate annotated method.
-     * @param target Service instance.
      * @param bundleContext Bundle context
      * @param properties Properties
      * @return true if activation method was called. False if no activate method is defined.
@@ -204,18 +164,6 @@ public final class MockOsgi {
     /**
      * Simulate deactivation of service instance. Invokes the @Deactivate annotated method.
      * @param target Service instance.
-     * @return true if deactivation method was called. False if no deactivate method is defined.
-     * @deprecated Please use {@link #deactivate(Object, BundleContext)}
-     *   and shutdown the bundle context after usage.
-     */
-    @Deprecated
-    public static boolean deactivate(Object target) {
-        return MockOsgi.deactivate(target, (Dictionary<String, Object>)null);
-    }
-
-    /**
-     * Simulate deactivation of service instance. Invokes the @Deactivate annotated method.
-     * @param target Service instance.
      * @param bundleContext Bundle context.
      * @return true if deactivation method was called. False if no deactivate method is defined.
      */
@@ -226,34 +174,6 @@ public final class MockOsgi {
     /**
      * Simulate deactivation of service instance. Invokes the @Deactivate annotated method.
      * @param target Service instance.
-     * @param properties Properties
-     * @return true if deactivation method was called. False if no deactivate method is defined.
-     * @deprecated Please use {@link #deactivate(Object, BundleContext, Dictionary)}
-     *   and shutdown the bundle context after usage.
-     */
-    @Deprecated
-    public static boolean deactivate(Object target, Dictionary<String, Object> properties) {
-        Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, null, properties);
-        ComponentContext componentContext = newComponentContext(mergedProperties);
-        return OsgiServiceUtil.activateDeactivate(target, componentContext, false);
-    }
-
-    /**
-     * Simulate deactivation of service instance. Invokes the @Deactivate annotated method.
-     * @param target Service instance.
-     * @param properties Properties
-     * @return true if deactivation method was called. False if no deactivate method is defined.
-     * @deprecated Please use {@link #deactivate(Object, BundleContext, Map)}
-     *   and shutdown the bundle context after usage.
-     */
-    @Deprecated
-    public static boolean deactivate(Object target, Map<String, Object> properties) {
-        return deactivate(target, toDictionary(properties));
-    }
-
-    /**
-     * Simulate deactivation of service instance. Invokes the @Deactivate annotated method.
-     * @param target Service instance.
      * @param bundleContext Bundle context
      * @param properties Properties
      * @return true if deactivation method was called. False if no deactivate method is defined.
@@ -312,9 +232,9 @@ public final class MockOsgi {
      * @return Configuration admin or null if not registered.
      */
     private static ConfigurationAdmin getConfigAdmin(BundleContext bundleContext) {
-        ServiceReference ref = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
+        ServiceReference<ConfigurationAdmin> ref = bundleContext.getServiceReference(ConfigurationAdmin.class);
         if (ref != null) {
-            return (ConfigurationAdmin)bundleContext.getService(ref);
+            return bundleContext.getService(ref);
         }
         return null;
     }
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceReference.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceReference.java
index c7568be..6af3a37 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceReference.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceReference.java
@@ -28,12 +28,12 @@ import org.osgi.framework.ServiceReference;
 /**
  * Mock {@link ServiceReference} implementation.
  */
-class MockServiceReference implements ServiceReference {
+class MockServiceReference<T> implements ServiceReference<T> {
 
     private final Bundle bundle;
-    private final MockServiceRegistration serviceRegistration;
+    private final MockServiceRegistration<T> serviceRegistration;
 
-    public MockServiceReference(final Bundle bundle, final MockServiceRegistration serviceRegistration) {
+    public MockServiceReference(final Bundle bundle, final MockServiceRegistration<T> serviceRegistration) {
         this.bundle = bundle;
         this.serviceRegistration = serviceRegistration;
     }
@@ -113,7 +113,7 @@ class MockServiceReference implements ServiceReference {
         }
     }
 
-    Object getService() {
+    T getService() {
         return this.serviceRegistration.getService();
     }
 
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 8ef25a4..7141949 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
@@ -38,24 +38,25 @@ import com.google.common.collect.ImmutableList;
 /**
  * Mock {@link ServiceRegistration} implementation.
  */
-class MockServiceRegistration implements ServiceRegistration, Comparable<MockServiceRegistration> {
+class MockServiceRegistration<T> implements ServiceRegistration<T>, Comparable<MockServiceRegistration<T>> {
 
     private static volatile long serviceCounter;
 
     private final Long serviceId;
     private final Set<String> clazzes;
-    private final Object service;
+    private final T service;
     private Dictionary<String, Object> properties;
-    private final ServiceReference serviceReference;
+    private final ServiceReference<T> serviceReference;
     private final MockBundleContext bundleContext;
 
-    public MockServiceRegistration(final Bundle bundle, final String[] clazzes, final Object service,
+    @SuppressWarnings("unchecked")
+    public MockServiceRegistration(final Bundle bundle, final String[] clazzes, final T service,
             final Dictionary<String, Object> properties, MockBundleContext bundleContext) {
         this.serviceId = ++serviceCounter;
         this.clazzes = new HashSet<String>(ImmutableList.copyOf(clazzes));
         
         if (service instanceof ServiceFactory) {
-            this.service = ((ServiceFactory)service).getService(bundleContext.getBundle(), this);
+            this.service = ((ServiceFactory<T>)service).getService(bundleContext.getBundle(), this);
         }
         else {
             this.service = service;
@@ -64,14 +65,14 @@ class MockServiceRegistration implements ServiceRegistration, Comparable<MockSer
         this.properties = properties != null ? properties : new Hashtable<String,Object>();
         this.properties.put(Constants.SERVICE_ID, this.serviceId);
         this.properties.put(Constants.OBJECTCLASS, clazzes);
-        this.serviceReference = new MockServiceReference(bundle, this);
+        this.serviceReference = new MockServiceReference<T>(bundle, this);
         this.bundleContext = bundleContext;
         
         readOsgiMetadata();
     }
 
     @Override
-    public ServiceReference getReference() {
+    public ServiceReference<T> getReference() {
         return this.serviceReference;
     }
 
@@ -100,7 +101,7 @@ class MockServiceRegistration implements ServiceRegistration, Comparable<MockSer
         return clazzes;
     }
 
-    Object getService() {
+    T getService() {
         return this.service;
     }
     
@@ -118,7 +119,7 @@ class MockServiceRegistration implements ServiceRegistration, Comparable<MockSer
     }
 
     @Override
-    public int compareTo(MockServiceRegistration obj) {
+    public int compareTo(MockServiceRegistration<T> obj) {
         return serviceId.compareTo(obj.serviceId);
     }
 
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtil.java b/src/main/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtil.java
index 05a26bc..84ccbf8 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtil.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtil.java
@@ -53,7 +53,6 @@ final class OsgiServiceUtil {
      * @param componentContext Component context
      * @return true if activation/deactivation method was called. False if it failed.
      */
-    @SuppressWarnings("unchecked")
     public static boolean activateDeactivate(Object target, ComponentContext componentContext, boolean activate) {
         Class<?> targetClass = target.getClass();
 
@@ -390,7 +389,7 @@ final class OsgiServiceUtil {
         try {
             ServiceReference[] references = bundleContext.getServiceReferences(type.getName(), null);
             if (references != null) {
-                for (ServiceReference serviceReference : references) {
+                for (ServiceReference<?> serviceReference : references) {
                     Object serviceInstance = bundleContext.getService(serviceReference);
                     Map<String, Object> serviceConfig = new HashMap<String, Object>();
                     String[] keys = serviceReference.getPropertyKeys();
@@ -413,7 +412,7 @@ final class OsgiServiceUtil {
      * @return List of references
      */
     public static List<ReferenceInfo> getMatchingDynamicReferences(SortedSet<MockServiceRegistration> registeredServices,
-            MockServiceRegistration registration) {
+            MockServiceRegistration<?> registration) {
         List<ReferenceInfo> references = new ArrayList<ReferenceInfo>();
         for (MockServiceRegistration existingRegistration : registeredServices) {
             OsgiMetadata metadata = OsgiMetadataUtil.getMetadata(existingRegistration.getService().getClass());
@@ -444,6 +443,7 @@ final class OsgiServiceUtil {
             this.serviceReference = serviceReference;
         }
 
+        @SuppressWarnings("unchecked")
         public ServiceInfo(MockServiceRegistration registration) {
             this.serviceInstance = registration.getService();
             this.serviceConfig = MapUtil.toMap(registration.getProperties());
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java b/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
index fe5f126..f15b6d0 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
@@ -19,5 +19,5 @@
 /**
  * Mock implementation of selected OSGi APIs.
  */
-@aQute.bnd.annotation.Version("2.4")
+@aQute.bnd.annotation.Version("3.0")
 package org.apache.sling.testing.mock.osgi;
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 092ab81..fb704f1 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
@@ -67,37 +67,37 @@ public class MockBundleContextTest {
         // prepare test services
         String clazz1 = String.class.getName();
         Object service1 = new Object();
-        Dictionary properties1 = getServiceProperties(null);
+        Dictionary<String, Object> properties1 = getServiceProperties(null);
         ServiceRegistration reg1 = bundleContext.registerService(clazz1, service1, properties1);
 
         String[] clazzes2 = new String[] { String.class.getName(), Integer.class.getName() };
         Object service2 = new Object();
-        Dictionary properties2 = getServiceProperties(null);
+        Dictionary<String, Object> properties2 = getServiceProperties(null);
         ServiceRegistration reg2 = bundleContext.registerService(clazzes2, service2, properties2);
 
         String clazz3 = Integer.class.getName();
         Object service3 = new Object();
-        Dictionary properties3 = getServiceProperties(100L);
+        Dictionary<String, Object> properties3 = getServiceProperties(100L);
         ServiceRegistration reg3 = bundleContext.registerService(clazz3, service3, properties3);
 
         // test get service references
-        ServiceReference refString = bundleContext.getServiceReference(String.class.getName());
+        ServiceReference<?> refString = bundleContext.getServiceReference(String.class.getName());
         assertSame(reg1.getReference(), refString);
 
-        ServiceReference refInteger = bundleContext.getServiceReference(Integer.class.getName());
+        ServiceReference<?> refInteger = bundleContext.getServiceReference(Integer.class.getName());
         assertSame(reg3.getReference(), refInteger);
 
-        ServiceReference[] refsString = bundleContext.getServiceReferences(String.class.getName(), null);
+        ServiceReference<?>[] refsString = bundleContext.getServiceReferences(String.class.getName(), null);
         assertEquals(2, refsString.length);
         assertSame(reg1.getReference(), refsString[0]);
         assertSame(reg2.getReference(), refsString[1]);
 
-        ServiceReference[] refsInteger = bundleContext.getServiceReferences(Integer.class.getName(), null);
+        ServiceReference<?>[] refsInteger = bundleContext.getServiceReferences(Integer.class.getName(), null);
         assertEquals(2, refsInteger.length);
         assertSame(reg3.getReference(), refsInteger[0]);
         assertSame(reg2.getReference(), refsInteger[1]);
 
-        ServiceReference[] allRefsString = bundleContext.getAllServiceReferences(String.class.getName(), null);
+        ServiceReference<?>[] allRefsString = bundleContext.getAllServiceReferences(String.class.getName(), null);
         assertArrayEquals(refsString, allRefsString);
 
         // test get services
@@ -116,7 +116,7 @@ public class MockBundleContextTest {
         // prepare test services
         String clazz1 = String.class.getName();
         Object service1 = new Object();
-        Dictionary properties1 = getServiceProperties(null);
+        Dictionary<String, Object> properties1 = getServiceProperties(null);
         ServiceRegistration reg1 = bundleContext.registerService(clazz1, service1, properties1);
         
         assertNotNull(bundleContext.getServiceReference(clazz1));
@@ -127,7 +127,7 @@ public class MockBundleContextTest {
     }
     
 
-    private Dictionary getServiceProperties(final Long serviceRanking) {
+    private Dictionary<String, Object> getServiceProperties(final Long serviceRanking) {
         Dictionary<String, Object> props = new Hashtable<String, Object>();
         if (serviceRanking != null) {
             props.put(Constants.SERVICE_RANKING, serviceRanking);
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockComponentContextTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/MockComponentContextTest.java
index b4497eb..aab327e 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/MockComponentContextTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/MockComponentContextTest.java
@@ -71,7 +71,7 @@ public class MockComponentContextTest {
         String clazz = String.class.getName();
         Object service = new Object();
         underTest.getBundleContext().registerService(clazz, service, null);
-        ServiceReference ref = underTest.getBundleContext().getServiceReference(clazz);
+        ServiceReference<?> ref = underTest.getBundleContext().getServiceReference(clazz);
 
         // test locate service
         Object locatedService = underTest.locateService(null, ref);
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
index f8b9a73..170957f 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
@@ -251,7 +251,6 @@ public class OsgiServiceUtilTest {
         private ComponentContext componentContext;
         private Map<String, Object> config;
 
-        @SuppressWarnings("unchecked")
         @Activate
         private void activate(ComponentContext ctx) {
             this.componentContext = ctx;
@@ -278,7 +277,7 @@ public class OsgiServiceUtilTest {
 
         public List<ServiceInterface2> getReferences2() {
             List<ServiceInterface2> services = new ArrayList<ServiceInterface2>();
-            for (ServiceReference serviceReference : references2) {
+            for (ServiceReference<?> serviceReference : references2) {
                 services.add((ServiceInterface2)componentContext.getBundleContext().getService(serviceReference));
             }
             return services;
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java b/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
index 60d5b0b..59990d5 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
@@ -75,7 +75,7 @@ public class OsgiContextImplTest {
         Set<String> myService = new HashSet<String>();
         context.registerService(Set.class, myService, props);
 
-        ServiceReference serviceReference = context.bundleContext().getServiceReference(Set.class.getName());
+        ServiceReference<?> serviceReference = context.bundleContext().getServiceReference(Set.class.getName());
         Object serviceResult = context.bundleContext().getService(serviceReference);
         assertSame(myService, serviceResult);
         assertEquals("value1", serviceReference.getProperty("prop1"));

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.