You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2022/02/04 10:09:43 UTC

[GitHub] [sling-org-apache-sling-scripting-core] raducotescu commented on a change in pull request #11: SLING-11118 null returned even if OSGi service is found

raducotescu commented on a change in pull request #11:
URL: https://github.com/apache/sling-org-apache-sling-scripting-core/pull/11#discussion_r799328944



##########
File path: src/test/java/org/apache/sling/scripting/core/impl/bundled/AbstractBundledRenderUnitTest.java
##########
@@ -0,0 +1,87 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.scripting.core.impl.bundled;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class AbstractBundledRenderUnitTest {
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    @Test
+    public void testGetService() throws Exception {

Review comment:
       Thanks for adding a test here, @bosschaert! I would like though one tiny change: rather than use the white-box approach, where you check the private `services` map and `references` list, I'd switch to a black-box approach.
   
   Keep the mocking like you do now, but after doing the first service retrieval make the reference return a different service object. The do another retrieval and check that the service instance is still the same (since it was retrieved from the cache). Call then `releaseDependencies` and check that the service returned is now the second service object you prepared above. Does that make sense?

##########
File path: src/main/java/org/apache/sling/scripting/core/impl/bundled/AbstractBundledRenderUnit.java
##########
@@ -126,7 +124,7 @@ public BundleContext getBundleContext() {
                 }
             }
         }
-        return null;
+        return result;

Review comment:
       Should we remove the `return` at line 123 and have only one `return` statement? It would make the code simpler to read.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org