You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2021/12/07 11:27:56 UTC

[sling-org-apache-sling-testing-sling-mock] branch master updated: cosmetic: use MockOsgi.registerInjectActivateService consistently

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

sseifert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git


The following commit(s) were added to refs/heads/master by this push:
     new b3894c0  cosmetic: use MockOsgi.registerInjectActivateService consistently
b3894c0 is described below

commit b3894c02d6ef233920d9f76cc4e21a9e2614351b
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Tue Dec 7 12:25:57 2021 +0100

    cosmetic: use MockOsgi.registerInjectActivateService consistently
---
 .../mock/sling/ResourceResolverFactoryInitializer.java       | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

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 1199a35..f98facf 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
@@ -123,8 +123,7 @@ class ResourceResolverFactoryInitializer {
      */
     private static void initializeJcrResourceProvider(@NotNull BundleContext bundleContext) {
         Dictionary<String, Object> config = new Hashtable<>();
-        JcrResourceProvider provider = new JcrResourceProvider();
-        MockOsgi.registerInjectActivateService(provider, bundleContext, config);
+        MockOsgi.registerInjectActivateService(JcrResourceProvider.class, bundleContext, config);
     }
 
     /**
@@ -152,10 +151,7 @@ class ResourceResolverFactoryInitializer {
         // do not required a specific resource provider (otherwise "NONE" will not work)
         config.put("resource.resolver.required.providers", "");
         config.put("resource.resolver.required.providernames", "");
-        ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
-        MockOsgi.injectServices(activator, bundleContext);
-        MockOsgi.activate(activator, bundleContext, config);
-        bundleContext.registerService(ResourceResolverFactoryActivator.class.getName(), activator, config);
+        MockOsgi.registerInjectActivateService(ResourceResolverFactoryActivator.class, bundleContext, config);
     }
 
     @SuppressWarnings({ "unchecked", "null" })
@@ -221,12 +217,10 @@ class ResourceResolverFactoryInitializer {
      * @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);
+            MockOsgi.registerInjectActivateService(implClass, bundleContext, config);
         }
     }