SLING-10190 make compatible with org.apache.sling.serviceusermapper 1.5.2 by supporting constructor injection
diff --git a/core/pom.xml b/core/pom.xml
index edb5ff4..5a7f160 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -318,7 +318,7 @@
                 <dependency>
                     <groupId>org.apache.sling</groupId>
                     <artifactId>org.apache.sling.serviceusermapper</artifactId>
-                    <version>1.4.6</version>
+                    <version>1.5.2</version>
                     <scope>compile</scope>
                 </dependency>
                 <dependency>
diff --git a/core/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java b/core/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
index b9457a1..a220299 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
@@ -82,7 +82,7 @@
         if (factoryRef == null) {
             throw new IllegalStateException("Unable to get ResourceResolverFactory.");
         }
-        return (ResourceResolverFactory)bundleContext.getService(factoryRef);
+        return bundleContext.getService(factoryRef);
     }
 
     /**
@@ -120,7 +120,7 @@
      * @param bundleContext Bundle context
      */
     private static void initializeJcrResourceProvider(@NotNull BundleContext bundleContext) {
-        Dictionary<String, Object> config = new Hashtable<String, Object>();
+        Dictionary<String, Object> config = new Hashtable<>();
         JcrResourceProvider provider = new JcrResourceProvider();
         MockOsgi.injectServices(provider, bundleContext);
         MockOsgi.activate(provider, bundleContext, config);
@@ -132,12 +132,12 @@
      * @param bundleContext Bundle context
      */
     private static void ensureResourceResolverFactoryActivatorDependencies(@NotNull BundleContext bundleContext) {
-        Dictionary<String, Object> config = new Hashtable<String, Object>();
+        Dictionary<String, Object> config = new Hashtable<>();
         config.put("user.mapping", bundleContext.getBundle().getSymbolicName() + "=admin");
-        registerServiceIfNotPresent(bundleContext, ServiceUserMapper.class, new ServiceUserMapperImpl(), config);
+        registerServiceIfNotPresent(bundleContext, ServiceUserMapper.class, ServiceUserMapperImpl.class, config);
 
-        registerServiceIfNotPresent(bundleContext, ResourceAccessSecurityTracker.class, new ResourceAccessSecurityTracker());
-        registerServiceIfNotPresent(bundleContext, EventAdmin.class, new MockEventAdmin());
+        registerServiceIfNotPresent(bundleContext, ResourceAccessSecurityTracker.class, ResourceAccessSecurityTracker.class);
+        registerServiceIfNotPresent(bundleContext, EventAdmin.class, MockEventAdmin.class);
         // dependency required since resourceresolver 1.7.0
         registerServiceIfNotPresentByName(bundleContext, "org.apache.sling.resourceresolver.impl.mapping.StringInterpolationProvider",
                 "org.apache.sling.resourceresolver.impl.mapping.StringInterpolationProviderImpl");
@@ -148,7 +148,7 @@
      * @param bundleContext Bundle context
      */
     private static void initializeResourceResolverFactoryActivator(@NotNull BundleContext bundleContext) {
-        Dictionary<String, Object> config = new Hashtable<String, Object>();
+        Dictionary<String, Object> config = new Hashtable<>();
         // do not required a specific resource provider (otherwise "NONE" will not work)
         config.put("resource.resolver.required.providers", "");
         config.put("resource.resolver.required.providernames", "");
@@ -179,7 +179,7 @@
      */
     private static <T> void registerServiceIfNotPresent(@NotNull BundleContext bundleContext, @NotNull Class<T> serviceClass,
             @NotNull T instance) {
-        registerServiceIfNotPresent(bundleContext, serviceClass, instance, new Hashtable<String, Object>());
+        registerServiceIfNotPresent(bundleContext, serviceClass, instance, new Hashtable<>());
     }
 
     /**
@@ -200,6 +200,35 @@
     }
 
     /**
+     * Registers a service if the service class is found in classpath,
+     * and if no service with this class is already registered.
+     * @param className Service class name
+     * @param serviceClass Service class
+     * @param implClass Implementation class
+     */
+    private static <T> void registerServiceIfNotPresent(@NotNull BundleContext bundleContext, @NotNull Class<T> serviceClass,
+            @NotNull Class<?> implClass) {
+        registerServiceIfNotPresent(bundleContext, serviceClass, implClass, new Hashtable<>());
+    }
+
+    /**
+     * Registers a service if the service class is found in classpath,
+     * and if no service with this class is already registered.
+     * @param className Service class name
+     * @param serviceClass Service class
+     * @param implClass Implementation class
+     * @param config OSGi config
+     */
+    @SuppressWarnings("unchecked")
+    private static <T> void registerServiceIfNotPresent(@NotNull BundleContext bundleContext, @NotNull Class<T> serviceClass,
+            @NotNull Class<?> implClass, Dictionary<String, Object> config) {
+        if (bundleContext.getServiceReference(serviceClass.getName()) == null) {
+            T instance = (T)MockOsgi.activateInjectServices(implClass, bundleContext, config);
+            bundleContext.registerService(serviceClass, instance, config);
+        }
+    }
+
+    /**
      * Registers all JCR node types found in classpath.
      * @param slingRepository Sling repository
      */