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:02:29 UTC
[sling-org-apache-sling-testing-sling-mock] 02/02: consistently use MockOsgi.registerInjectActivateService
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch experimental/WTES-69-diagnosis
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 0b9c4bb43fad203bfa5084541013e2396bc3ee7a
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Tue Dec 7 12:01:56 2021 +0100
consistently use MockOsgi.registerInjectActivateService
---
.../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);
}
}