You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:21:23 UTC
[sling-org-apache-sling-testing-sling-mock] 14/26: SLING-4085 NPE
when using SlingContext rule without constructor argument
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.testing.sling-mock-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 1f522355aaed60502df5db0138cb22deb2659ada
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Oct 21 19:22:32 2014 +0000
SLING-4085 NPE when using SlingContext rule without constructor argument
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1633438 13f79535-47bb-0310-9956-ffa450edef68
---
.../context/ContextResourceResolverFactory.java | 12 ++++---
.../mock/sling/context/SlingContextImplTest.java | 8 +++++
.../sling/junit/SlingContextDefaultRRTypeTest.java | 37 ++++++++++++++++++++++
3 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
index 2891fc6..8df107f 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
@@ -38,10 +38,14 @@ final class ContextResourceResolverFactory {
}
public static ResourceResolverFactory get(final ResourceResolverType resourceResolverType) {
+ ResourceResolverType type = resourceResolverType;
+ if (type == null) {
+ type = MockSling.DEFAULT_RESOURCERESOLVER_TYPE;
+ }
try {
- ResourceResolverFactory factory = MockSling.newResourceResolverFactory(resourceResolverType);
+ ResourceResolverFactory factory = MockSling.newResourceResolverFactory(type);
- switch (resourceResolverType) {
+ switch (type) {
case JCR_MOCK:
initializeJcrMock(factory);
break;
@@ -52,12 +56,12 @@ final class ContextResourceResolverFactory {
initializeResourceResolverMock(factory);
break;
default:
- throw new IllegalArgumentException("Invalid resource resolver type: " + resourceResolverType);
+ throw new IllegalArgumentException("Invalid resource resolver type: " + type);
}
return factory;
} catch (Throwable ex) {
- throw new RuntimeException("Unable to initialize " + resourceResolverType + " resource resolver factory.", ex);
+ throw new RuntimeException("Unable to initialize " + type + " resource resolver factory.", ex);
}
}
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/SlingContextImplTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/SlingContextImplTest.java
index d667002..2c7aed5 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/SlingContextImplTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/SlingContextImplTest.java
@@ -200,6 +200,14 @@ public class SlingContextImplTest {
assertNotNull(factory);
}
+ @Test
+ public void testWithoutResourceResolverType() {
+ SlingContextImpl contextTest = new SlingContextImpl();
+ contextTest.setUp();
+ ResourceResolverFactory factory = contextTest.getService(ResourceResolverFactory.class);
+ assertNotNull(factory);
+ }
+
@Model(adaptables = SlingHttpServletRequest.class)
public interface RequestAttributeModel {
@Inject
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextDefaultRRTypeTest.java b/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextDefaultRRTypeTest.java
new file mode 100644
index 0000000..d5579af
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextDefaultRRTypeTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.testing.mock.sling.junit;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+public class SlingContextDefaultRRTypeTest {
+
+ // Run all unit tests for each resource resolver types listed here
+ @Rule
+ public SlingContext context = new SlingContext();
+
+ @Test
+ public void testRequest() {
+ assertNotNull(context.request());
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.