You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by js...@apache.org on 2024/01/10 07:31:29 UTC

(sling-whiteboard) branch org.apache.sling.testing.osgi.unit updated: reload injected classes with bundle ClassLoader

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

jsedding pushed a commit to branch org.apache.sling.testing.osgi.unit
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/org.apache.sling.testing.osgi.unit by this push:
     new 3d8e9e8f reload injected classes with bundle ClassLoader
3d8e9e8f is described below

commit 3d8e9e8f1b5881764df83c47cfb0bc0e13805944
Author: Julian Sedding <js...@apache.org>
AuthorDate: Tue Jan 9 11:57:00 2024 +0100

    reload injected classes with bundle ClassLoader
---
 .../testing/osgi/unit/OSGiSupportInvocationInterceptor.java      | 7 ++++++-
 .../org/apache/sling/testing/osgi/unit/impl/OSGiSupportTest.java | 9 ++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/osgi/unit/OSGiSupportInvocationInterceptor.java b/src/main/java/org/apache/sling/testing/osgi/unit/OSGiSupportInvocationInterceptor.java
index e5af46e1..d5544460 100644
--- a/src/main/java/org/apache/sling/testing/osgi/unit/OSGiSupportInvocationInterceptor.java
+++ b/src/main/java/org/apache/sling/testing/osgi/unit/OSGiSupportInvocationInterceptor.java
@@ -80,7 +80,12 @@ class OSGiSupportInvocationInterceptor implements InvocationInterceptor {
             if (serviceAnnotations[i] != null) {
                 arguments[i] = resolveServiceObject(serviceAnnotations[i], store, parameters[i]);
             } else {
-                arguments[i] = invocationContext.getArguments().get(i);
+                final Object argument = invocationContext.getArguments().get(i);
+                if (argument instanceof Class) {
+                    arguments[i] = bundle.loadClass(((Class<?>)argument).getName());
+                } else {
+                    arguments[i] = argument;
+                }
             }
         }
 
diff --git a/src/test/java/org/apache/sling/testing/osgi/unit/impl/OSGiSupportTest.java b/src/test/java/org/apache/sling/testing/osgi/unit/impl/OSGiSupportTest.java
index f787cbe4..c02d2a6c 100644
--- a/src/test/java/org/apache/sling/testing/osgi/unit/impl/OSGiSupportTest.java
+++ b/src/test/java/org/apache/sling/testing/osgi/unit/impl/OSGiSupportTest.java
@@ -136,6 +136,9 @@ class OSGiSupportTest {
     @Component(service = ServiceA.class)
     public static class ServiceA {}
 
+    @Component(service = ServiceB.class)
+    public static class ServiceB {}
+
     @Test
     @OSGiSupport(logService = SLING, additionalBundles = {"org.apache.felix.scr"})
     void serviceInjection(Framework framework, @Service ServiceComponentRuntime scr, @Service ServiceA serviceA) {
@@ -268,9 +271,9 @@ class OSGiSupportTest {
     }
 
     @ParameterizedTest
-    @ValueSource(strings = {"foo", "bar"})
-    void parameterizedTestSupport(String fooOrBar, Framework framework, @Service Condition condition) {
-        assertThat(fooOrBar).matches(List.of("foo", "bar")::contains);
+    @ValueSource(classes = {OSGiSupportTest.ServiceA.class, OSGiSupportTest.ServiceB.class})
+    void parameterizedTestSupport(Class<?> serviceClass, Framework framework, @Service Condition condition) {
+        assertThat(serviceClass).matches(List.of(ServiceA.class, ServiceB.class)::contains);
         assertNotNull(framework);
         assertNotNull(condition);
     }