joerghoh commented on code in PR #7:
URL: 
https://github.com/apache/sling-org-apache-sling-scripting-sightly-js-provider/pull/7#discussion_r1929610357


##########
src/test/java/org/apache/sling/scripting/sightly/js/impl/jsapi/SlyBindingsValuesProviderTest.java:
##########
@@ -0,0 +1,93 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.sightly.js.impl.jsapi;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Objects;
+
+import javax.script.Bindings;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.scripting.core.ScriptNameAwareReader;
+import org.apache.sling.scripting.sightly.js.impl.JsEnvironment;
+import org.apache.sling.scripting.sightly.js.impl.async.AsyncContainer;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mozilla.javascript.Function;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class SlyBindingsValuesProviderTest {
+
+    @Mock
+    private ResourceResolver resolver;
+
+    @Mock
+    private Resource scriptResource;
+
+    @Mock
+    private SlyBindingsValuesProvider.Configuration configuration;
+
+    @Mock
+    private JsEnvironment jsEnvironment;
+
+    @Mock
+    private AsyncContainer asyncContainer;
+
+    @Mock
+    private Function function;
+
+    private InputStream inputStream;
+
+    @BeforeEach
+    void setUp() {
+        String scriptPath = 
SlyBindingsValuesProvider.SLING_NS_PATH.split(":")[1];
+        inputStream = 
spy(Objects.requireNonNull(getClass().getResourceAsStream("/SLING-INF" + 
scriptPath)));
+        when(scriptResource.getPath()).thenReturn(scriptPath);
+        when(resolver.getResource(scriptPath)).thenReturn(scriptResource);
+        
when(scriptResource.adaptTo(InputStream.class)).thenReturn(inputStream);
+        when(asyncContainer.getResult()).thenReturn(function);
+        when(jsEnvironment.runScript(any(ScriptNameAwareReader.class), 
any(Bindings.class), any(Bindings.class))).thenReturn(asyncContainer);
+    }
+
+    @Test
+    void testResourceLoading() throws IOException {

Review Comment:
   ```suggestion
       void whenResourceLoading_InputStreamIsNotRead() throws IOException {
   ```



##########
src/test/java/org/apache/sling/scripting/sightly/js/impl/use/DependencyResolverTest.java:
##########
@@ -0,0 +1,138 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.sightly.js.impl.use;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.script.Bindings;
+import javax.script.ScriptEngine;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.scripting.core.ScriptNameAwareReader;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class DependencyResolverTest {
+
+    private static final String CALLER_PATH = "/libs/caller/caller.html";
+    private static final String SCRIPT_PATH = "/libs/caller/caller.js";
+
+    @Mock
+    private ResourceResolver scriptingResourceResolver;
+
+    @Mock
+    private Resource caller;
+
+    @Mock
+    private Resource callerParent;
+
+    @Mock
+    private Resource dependency;
+
+    @Mock
+    private Resource content;
+
+    @Mock
+    private SlingHttpServletRequest request;
+
+    private DependencyResolver dependencyResolver;
+    private Bindings bindings;
+
+
+    @BeforeEach
+    void beforeEach() {
+        when(dependency.getPath()).thenReturn(SCRIPT_PATH);
+        when(caller.getParent()).thenReturn(callerParent);
+        
when(scriptingResourceResolver.getResource(CALLER_PATH)).thenReturn(caller);
+        
when(scriptingResourceResolver.getResource(SCRIPT_PATH)).thenReturn(dependency);
+        dependencyResolver = new DependencyResolver(scriptingResourceResolver);
+        bindings = new SlingBindings();
+        bindings.put(ScriptEngine.FILENAME, CALLER_PATH);
+        bindings.put(SlingBindings.REQUEST, request);
+    }
+
+    @Test
+    void testStreamLoading() throws IOException {

Review Comment:
   ```suggestion
       void whenResourceLoading_InputStreamIsNotRead() throws IOException {
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to