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 2018/08/03 13:21:03 UTC
[sling-org-apache-sling-testing-sling-mock] 01/01: SLING-7803 apply
jetbrains nullability annotations on public API
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch feature/SLING-7803-nullability
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit f711dc4e363686b214e838741e30c4bf4dea4071
Author: sseifert <ss...@pro-vision.de>
AuthorDate: Fri Aug 3 15:20:28 2018 +0200
SLING-7803 apply jetbrains nullability annotations on public API
---
pom.xml | 10 ++-
.../testing/mock/sling/MockAdapterManagerImpl.java | 6 +-
.../apache/sling/testing/mock/sling/MockSling.java | 22 +++---
.../testing/mock/sling/MockSlingScriptHelper.java | 48 ++++++------
.../sling/ResourceResolverFactoryInitializer.java | 25 +++---
.../testing/mock/sling/ResourceResolverType.java | 20 +++--
.../sling/ThreadsafeMockAdapterManagerWrapper.java | 7 +-
.../testing/mock/sling/builder/ContentBuilder.java | 20 +++--
.../testing/mock/sling/builder/package-info.java | 2 +-
.../context/ContextResourceResolverFactory.java | 14 ++--
.../sling/context/ModelAdapterFactoryUtil.java | 24 +++---
.../mock/sling/context/SlingContextImpl.java | 91 +++++++++++++---------
.../testing/mock/sling/context/UniqueRoot.java | 13 ++--
.../testing/mock/sling/context/package-info.java | 2 +-
.../testing/mock/sling/junit/SlingContext.java | 28 ++++---
.../mock/sling/junit/SlingContextBuilder.java | 23 +++---
.../testing/mock/sling/junit/package-info.java | 2 +-
.../testing/mock/sling/loader/ContentLoader.java | 59 ++++++++------
.../mock/sling/loader/LoaderContentHandler.java | 34 +++++---
.../testing/mock/sling/loader/package-info.java | 2 +-
.../sling/testing/mock/sling/package-info.java | 2 +-
.../sling/services/MockSlingSettingService.java | 6 +-
.../testing/mock/sling/services/package-info.java | 2 +-
.../sling/servlet/MockSlingHttpServletRequest.java | 9 ++-
.../testing/mock/sling/servlet/package-info.java | 2 +-
.../sling/spi/ResourceResolverTypeAdapter.java | 5 +-
.../sling/testing/mock/sling/spi/package-info.java | 2 +-
.../mock/sling/MockSlingScriptHelperTest.java | 1 +
.../mock/sling/builder/ContentBuilderTest.java | 1 +
.../context/AbstractSlingContextImplTest.java | 1 +
.../sling/context/NoResourceResolverTypeTest.java | 1 +
.../sling/jcrmock/resource/FindResourcesTest.java | 3 +-
.../testing/mock/sling/junit/SlingContextTest.java | 4 +-
.../AbstractContentLoaderAutoCommitTest.java | 1 +
.../loader/AbstractContentLoaderBinaryTest.java | 1 +
.../loader/AbstractContentLoaderJsonDamTest.java | 1 +
.../loader/AbstractContentLoaderJsonTest.java | 1 +
.../sling/resource/AbstractJcrNamespaceTest.java | 1 +
.../resource/AbstractJcrResourceResolverTest.java | 1 +
.../AbstractMultipleResourceResolverTest.java | 2 +
.../AbstractSlingCrudResourceResolverTest.java | 1 +
.../sling/resource/AbstractUniqueRootTest.java | 1 +
.../services/MockSlingSettingServiceTest.java | 1 +
.../servlet/MockSlingHttpServletRequestTest.java | 1 +
44 files changed, 307 insertions(+), 196 deletions(-)
diff --git a/pom.xml b/pom.xml
index 6402322..70417ad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,7 +58,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId>
- <version>1.1.20</version>
+ <version>1.1.21-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -223,6 +223,14 @@
<scope>compile</scope>
</dependency>
+ <!-- Nullability annotations -->
+ <dependency>
+ <groupId>org.jetbrains</groupId>
+ <artifactId>annotations</artifactId>
+ <version>16.0.2</version>
+ <scope>provided</scope>
+ </dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
index b3f3825..91af2f4 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
@@ -40,6 +40,7 @@ import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.adapter.AdapterManager;
import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.jetbrains.annotations.NotNull;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
@@ -125,8 +126,9 @@ public class MockAdapterManagerImpl implements AdapterManager {
*
* @see org.apache.sling.api.adapter.AdapterManager#getAdapter(java.lang.Object, java.lang.Class)
*/
- public <AdapterType> AdapterType getAdapter(final Object adaptable,
- final Class<AdapterType> type) {
+ @Override
+ public <AdapterType> AdapterType getAdapter(@NotNull final Object adaptable,
+ @NotNull final Class<AdapterType> type) {
// get the adapter factories for the type of adaptable object
final Map<String, List<AdapterFactoryDescriptor>> factories = getAdapterFactories(adaptable.getClass());
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
index fdc222e..35489ab 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
@@ -29,6 +29,7 @@ import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse;
import org.apache.sling.testing.mock.sling.spi.ResourceResolverTypeAdapter;
+import org.jetbrains.annotations.NotNull;
import org.osgi.framework.BundleContext;
/**
@@ -39,7 +40,7 @@ public final class MockSling {
/**
* Default resource resolver type is {@link ResourceResolverType#RESOURCERESOLVER_MOCK}.
*/
- public static final ResourceResolverType DEFAULT_RESOURCERESOLVER_TYPE = ResourceResolverType.RESOURCERESOLVER_MOCK;
+ public static final @NotNull ResourceResolverType DEFAULT_RESOURCERESOLVER_TYPE = ResourceResolverType.RESOURCERESOLVER_MOCK;
private static final ThreadsafeMockAdapterManagerWrapper ADAPTER_MANAGER = new ThreadsafeMockAdapterManagerWrapper();
static {
@@ -56,7 +57,7 @@ public final class MockSling {
* @param bundleContext Bundle context
* @return Resource resolver factory instance
*/
- public static ResourceResolverFactory newResourceResolverFactory(final BundleContext bundleContext) {
+ public static @NotNull ResourceResolverFactory newResourceResolverFactory(@NotNull final BundleContext bundleContext) {
return newResourceResolverFactory(DEFAULT_RESOURCERESOLVER_TYPE, bundleContext);
}
@@ -66,8 +67,8 @@ public final class MockSling {
* @param bundleContext Bundle context
* @return Resource resolver factory instance
*/
- public static ResourceResolverFactory newResourceResolverFactory(final ResourceResolverType type,
- final BundleContext bundleContext) {
+ public static @NotNull ResourceResolverFactory newResourceResolverFactory(@NotNull final ResourceResolverType type,
+ @NotNull final BundleContext bundleContext) {
ResourceResolverTypeAdapter adapter = getResourceResolverTypeAdapter(type);
ResourceResolverFactory factory = adapter.newResourceResolverFactory();
if (factory == null) {
@@ -111,7 +112,8 @@ public final class MockSling {
* @param bundleContext Bundle context
* @return Resource resolver instance
*/
- public static ResourceResolver newResourceResolver(final ResourceResolverType type, BundleContext bundleContext) {
+ @SuppressWarnings("deprecation")
+ public static @NotNull ResourceResolver newResourceResolver(@NotNull final ResourceResolverType type, @NotNull BundleContext bundleContext) {
ResourceResolverFactory factory = newResourceResolverFactory(type, bundleContext);
try {
return factory.getAdministrativeResourceResolver(null);
@@ -126,7 +128,7 @@ public final class MockSling {
* @param bundleContext Bundle context
* @return Resource resolver instance
*/
- public static ResourceResolver newResourceResolver(BundleContext bundleContext) {
+ public static @NotNull ResourceResolver newResourceResolver(@NotNull BundleContext bundleContext) {
return newResourceResolver(DEFAULT_RESOURCERESOLVER_TYPE, bundleContext);
}
@@ -137,8 +139,8 @@ public final class MockSling {
* @param bundleContext Bundle context
* @return Sling script helper instance
*/
- public static SlingScriptHelper newSlingScriptHelper(final SlingHttpServletRequest request,
- final SlingHttpServletResponse response, final BundleContext bundleContext) {
+ public static @NotNull SlingScriptHelper newSlingScriptHelper(@NotNull final SlingHttpServletRequest request,
+ @NotNull final SlingHttpServletResponse response, @NotNull final BundleContext bundleContext) {
return new MockSlingScriptHelper(request, response, bundleContext);
}
@@ -148,7 +150,7 @@ public final class MockSling {
* @param bundleContext Bundle context
* @return Sling script helper instance
*/
- public static SlingScriptHelper newSlingScriptHelper(BundleContext bundleContext) {
+ public static @NotNull SlingScriptHelper newSlingScriptHelper(@NotNull BundleContext bundleContext) {
SlingHttpServletRequest request = new MockSlingHttpServletRequest(newResourceResolver(bundleContext), bundleContext);
SlingHttpServletResponse response = new MockSlingHttpServletResponse();
return newSlingScriptHelper(request, response, bundleContext);
@@ -159,7 +161,7 @@ public final class MockSling {
* adapter factories are detected.
* @param bundleContext OSGi bundle context
*/
- public static void setAdapterManagerBundleContext(final BundleContext bundleContext) {
+ public static void setAdapterManagerBundleContext(@NotNull final BundleContext bundleContext) {
ADAPTER_MANAGER.setBundleContext(bundleContext);
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelper.java b/src/main/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelper.java
index bc68a72..6a6a7e8 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelper.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelper.java
@@ -28,6 +28,7 @@ import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.scripting.InvalidServiceFilterSyntaxException;
import org.apache.sling.api.scripting.SlingScript;
import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.jetbrains.annotations.NotNull;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
@@ -37,31 +38,31 @@ import org.osgi.framework.ServiceReference;
*/
public final class MockSlingScriptHelper implements SlingScriptHelper {
- private final SlingHttpServletRequest request;
- private final SlingHttpServletResponse response;
- private final BundleContext bundleContext;
+ private final @NotNull SlingHttpServletRequest request;
+ private final @NotNull SlingHttpServletResponse response;
+ private final @NotNull BundleContext bundleContext;
private SlingScript script;
- public MockSlingScriptHelper(final SlingHttpServletRequest request, final SlingHttpServletResponse response,
- final BundleContext bundleContext) {
+ public MockSlingScriptHelper(@NotNull final SlingHttpServletRequest request, @NotNull final SlingHttpServletResponse response,
+ @NotNull final BundleContext bundleContext) {
this.request = request;
this.response = response;
this.bundleContext = bundleContext;
}
@Override
- public SlingHttpServletRequest getRequest() {
+ public @NotNull SlingHttpServletRequest getRequest() {
return this.request;
}
@Override
- public SlingHttpServletResponse getResponse() {
+ public @NotNull SlingHttpServletResponse getResponse() {
return this.response;
}
@Override
@SuppressWarnings("unchecked")
- public <ServiceType> ServiceType getService(final Class<ServiceType> serviceType) {
+ public <ServiceType> ServiceType getService(@NotNull final Class<ServiceType> serviceType) {
ServiceReference serviceReference = this.bundleContext.getServiceReference(serviceType.getName());
if (serviceReference != null) {
return (ServiceType) this.bundleContext.getService(serviceReference);
@@ -72,7 +73,7 @@ public final class MockSlingScriptHelper implements SlingScriptHelper {
@Override
@SuppressWarnings("unchecked")
- public <ServiceType> ServiceType[] getServices(final Class<ServiceType> serviceType, final String filter) {
+ public <ServiceType> ServiceType[] getServices(@NotNull final Class<ServiceType> serviceType, final String filter) {
try {
ServiceReference[] serviceReferences = this.bundleContext.getServiceReferences(serviceType.getName(),
filter);
@@ -90,12 +91,13 @@ public final class MockSlingScriptHelper implements SlingScriptHelper {
}
}
+ @SuppressWarnings("null")
@Override
- public SlingScript getScript() {
+ public @NotNull SlingScript getScript() {
return this.script;
}
- public void setScript(SlingScript script) {
+ public void setScript(@NotNull SlingScript script) {
this.script = script;
}
@@ -106,62 +108,62 @@ public final class MockSlingScriptHelper implements SlingScriptHelper {
}
@Override
- public void forward(final String path, final RequestDispatcherOptions requestDispatcherOptions) {
+ public void forward(@NotNull final String path, final RequestDispatcherOptions requestDispatcherOptions) {
throw new UnsupportedOperationException();
}
@Override
- public void forward(final String path, final String requestDispatcherOptions) {
+ public void forward(@NotNull final String path, final String requestDispatcherOptions) {
throw new UnsupportedOperationException();
}
@Override
- public void forward(final String path) {
+ public void forward(@NotNull final String path) {
throw new UnsupportedOperationException();
}
@Override
- public void forward(final Resource resource) {
+ public void forward(@NotNull final Resource resource) {
throw new UnsupportedOperationException();
}
@Override
- public void forward(final Resource resource, final String requestDispatcherOptions) {
+ public void forward(@NotNull final Resource resource, final String requestDispatcherOptions) {
throw new UnsupportedOperationException();
}
@Override
- public void forward(final Resource resource, final RequestDispatcherOptions requestDispatcherOptions) {
+ public void forward(@NotNull final Resource resource, final RequestDispatcherOptions requestDispatcherOptions) {
throw new UnsupportedOperationException();
}
@Override
- public void include(final String path, final RequestDispatcherOptions requestDispatcherOptions) {
+ public void include(@NotNull final String path, final RequestDispatcherOptions requestDispatcherOptions) {
throw new UnsupportedOperationException();
}
@Override
- public void include(final String path, final String requestDispatcherOptions) {
+ public void include(@NotNull final String path, final String requestDispatcherOptions) {
throw new UnsupportedOperationException();
}
@Override
- public void include(final String path) {
+ public void include(@NotNull final String path) {
throw new UnsupportedOperationException();
}
@Override
- public void include(final Resource resource) {
+ public void include(@NotNull final Resource resource) {
throw new UnsupportedOperationException();
}
@Override
- public void include(final Resource resource, final String requestDispatcherOptions) {
+ public void include(@NotNull final Resource resource, final String requestDispatcherOptions) {
throw new UnsupportedOperationException();
}
@Override
- public void include(final Resource resource, final RequestDispatcherOptions requestDispatcherOptions) {
+ public void include(@NotNull final Resource resource, final RequestDispatcherOptions requestDispatcherOptions) {
throw new UnsupportedOperationException();
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
index 5b64c58..0bdbe9a 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
@@ -35,6 +35,8 @@ import org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl;
import org.apache.sling.spi.resource.provider.ResourceProvider;
import org.apache.sling.testing.mock.osgi.MockEventAdmin;
import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.event.EventAdmin;
@@ -53,8 +55,9 @@ class ResourceResolverFactoryInitializer {
* @param slingRepository Sling repository. If null resource resolver factory is setup without any resource provider.
* @param bundleContext Bundle context
*/
- public static ResourceResolverFactory setUp(SlingRepository slingRepository,
- BundleContext bundleContext, NodeTypeMode nodeTypeMode) {
+ @SuppressWarnings("null")
+ public static @NotNull ResourceResolverFactory setUp(@Nullable SlingRepository slingRepository,
+ @NotNull BundleContext bundleContext, @NotNull NodeTypeMode nodeTypeMode) {
if (slingRepository != null) {
// register sling repository as OSGi service
@@ -83,8 +86,8 @@ class ResourceResolverFactoryInitializer {
* Ensure dependencies for JcrResourceProvider are present.
* @param bundleContext Bundle context
*/
- @SuppressWarnings("unchecked")
- private static void ensureJcrResourceProviderDependencies(BundleContext bundleContext) {
+ @SuppressWarnings({ "unchecked", "null" })
+ private static void ensureJcrResourceProviderDependencies(@NotNull BundleContext bundleContext) {
if (bundleContext.getServiceReference(DynamicClassLoaderManager.class) == null) {
bundleContext.registerService(DynamicClassLoaderManager.class, new MockDynamicClassLoaderManager(), null);
}
@@ -102,7 +105,7 @@ class ResourceResolverFactoryInitializer {
* Initialize JCR resource provider.
* @param bundleContext Bundle context
*/
- private static void initializeJcrResourceProvider(BundleContext bundleContext) {
+ private static void initializeJcrResourceProvider(@NotNull BundleContext bundleContext) {
Dictionary<String, Object> config = new Hashtable<String, Object>();
JcrResourceProvider provider = new JcrResourceProvider();
MockOsgi.injectServices(provider, bundleContext);
@@ -114,7 +117,7 @@ class ResourceResolverFactoryInitializer {
* Ensure dependencies for ResourceResolverFactoryActivator are present.
* @param bundleContext Bundle context
*/
- private static void ensureResourceResolverFactoryActivatorDependencies(BundleContext bundleContext) {
+ private static void ensureResourceResolverFactoryActivatorDependencies(@NotNull BundleContext bundleContext) {
Dictionary<String, Object> config = new Hashtable<String, Object>();
config.put("user.mapping", bundleContext.getBundle().getSymbolicName() + "=admin");
registerServiceIfNotPresent(bundleContext, ServiceUserMapper.class, new ServiceUserMapperImpl(), config);
@@ -127,7 +130,7 @@ class ResourceResolverFactoryInitializer {
* Initialize resource resolver factory activator.
* @param bundleContext Bundle context
*/
- private static void initializeResourceResolverFactoryActivator(BundleContext bundleContext) {
+ private static void initializeResourceResolverFactoryActivator(@NotNull BundleContext bundleContext) {
Dictionary<String, Object> config = new Hashtable<String, Object>();
// do not required a specific resource provider (otherwise "NONE" will not work)
config.put("resource.resolver.required.providers", "");
@@ -145,8 +148,8 @@ class ResourceResolverFactoryInitializer {
* @param serviceClass Service class
* @param instance Service instance
*/
- private static <T> void registerServiceIfNotPresent(BundleContext bundleContext, Class<T> serviceClass,
- T instance) {
+ private static <T> void registerServiceIfNotPresent(@NotNull BundleContext bundleContext, @NotNull Class<T> serviceClass,
+ @NotNull T instance) {
registerServiceIfNotPresent(bundleContext, serviceClass, instance, new Hashtable<String, Object>());
}
@@ -158,8 +161,8 @@ class ResourceResolverFactoryInitializer {
* @param instance Service instance
* @param config OSGi config
*/
- private static <T> void registerServiceIfNotPresent(BundleContext bundleContext, Class<T> serviceClass,
- T instance, Dictionary<String, Object> config) {
+ private static <T> void registerServiceIfNotPresent(@NotNull BundleContext bundleContext, @NotNull Class<T> serviceClass,
+ @NotNull T instance, Dictionary<String, Object> config) {
if (bundleContext.getServiceReference(serviceClass.getName()) == null) {
MockOsgi.injectServices(instance, bundleContext);
MockOsgi.activate(instance, bundleContext, config);
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java
index f0d2b1d..70aae0f 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java
@@ -18,10 +18,13 @@
*/
package org.apache.sling.testing.mock.sling;
+import org.jetbrains.annotations.NotNull;
+
/**
* The resource resolver mock implementation supports different underlying
* repository implementations.
*/
+@SuppressWarnings("null")
public enum ResourceResolverType {
/**
@@ -79,30 +82,31 @@ public enum ResourceResolverType {
- private final String resourceResolverTypeAdapterClass;
- private final String artifactCoordinates;
- private final NodeTypeMode nodeTypeMode;
+ private final @NotNull String resourceResolverTypeAdapterClass;
+ private final @NotNull String artifactCoordinates;
+ private final @NotNull NodeTypeMode nodeTypeMode;
- private ResourceResolverType(final String resourceResolverTypeAdapterClass, final String artifactCoordinates,
- final NodeTypeMode nodeTypeMode) {
+ private ResourceResolverType(@NotNull final String resourceResolverTypeAdapterClass,
+ @NotNull final String artifactCoordinates,
+ @NotNull final NodeTypeMode nodeTypeMode) {
this.resourceResolverTypeAdapterClass = resourceResolverTypeAdapterClass;
this.artifactCoordinates = artifactCoordinates;
this.nodeTypeMode = nodeTypeMode;
}
- String getResourceResolverTypeAdapterClass() {
+ @NotNull String getResourceResolverTypeAdapterClass() {
return this.resourceResolverTypeAdapterClass;
}
- String getArtifactCoordinates() {
+ @NotNull String getArtifactCoordinates() {
return this.artifactCoordinates;
}
/**
* @return How JCR namespaces and node types have to be handled.
*/
- public NodeTypeMode getNodeTypeMode() {
+ public @NotNull NodeTypeMode getNodeTypeMode() {
return nodeTypeMode;
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java b/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java
index 428bd4c..aa0a572 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java
@@ -23,6 +23,7 @@ import java.util.Hashtable;
import org.apache.sling.api.adapter.AdapterManager;
import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.jetbrains.annotations.NotNull;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -41,7 +42,7 @@ class ThreadsafeMockAdapterManagerWrapper implements AdapterManager {
};
@Override
- public <AdapterType> AdapterType getAdapter(final Object adaptable, final Class<AdapterType> type) {
+ public <AdapterType> AdapterType getAdapter(@NotNull final Object adaptable, @NotNull final Class<AdapterType> type) {
AdapterManager adapterManager = THREAD_LOCAL.get().getAdapterManager();
return adapterManager.getAdapter(adaptable, type);
}
@@ -50,7 +51,7 @@ class ThreadsafeMockAdapterManagerWrapper implements AdapterManager {
* Sets bundle context.
* @param bundleContext Bundle context
*/
- public void setBundleContext(final BundleContext bundleContext) {
+ public void setBundleContext(@NotNull final BundleContext bundleContext) {
AdapterManagerBundleContextFactory adapterManager = THREAD_LOCAL.get();
adapterManager.setBundleContext(bundleContext);
}
@@ -68,7 +69,7 @@ class ThreadsafeMockAdapterManagerWrapper implements AdapterManager {
private BundleContext bundleContext;
- public void setBundleContext(final BundleContext bundleContext) {
+ public void setBundleContext(@NotNull final BundleContext bundleContext) {
this.bundleContext = bundleContext;
// register adapter manager
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java b/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java
index 2d74cb1..1ed73f2 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java
@@ -28,6 +28,7 @@ import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.testing.mock.osgi.MapUtil;
+import org.jetbrains.annotations.NotNull;
import com.google.common.collect.ImmutableMap;
@@ -44,7 +45,7 @@ public class ContentBuilder {
/**
* @param resourceResolver Resource resolver
*/
- public ContentBuilder(ResourceResolver resourceResolver) {
+ public ContentBuilder(@NotNull ResourceResolver resourceResolver) {
this.resourceResolver = resourceResolver;
}
@@ -54,7 +55,8 @@ public class ContentBuilder {
* @param path Page path
* @return Resource object
*/
- public final Resource resource(String path) {
+ @SuppressWarnings("null")
+ public final @NotNull Resource resource(@NotNull String path) {
return resource(path, ValueMap.EMPTY);
}
@@ -65,8 +67,11 @@ public class ContentBuilder {
* @param properties Properties for resource.
* @return Resource object
*/
- public final Resource resource(String path, Map<String, Object> properties) {
+ public final @NotNull Resource resource(@NotNull String path, @NotNull Map<String, Object> properties) {
String parentPath = ResourceUtil.getParent(path);
+ if (parentPath == null) {
+ throw new IllegalArgumentException("Path has no parent: " + path);
+ }
Resource parentResource = ensureResourceExists(parentPath);
String name = ResourceUtil.getName(path);
try {
@@ -83,7 +88,8 @@ public class ContentBuilder {
* @param properties Properties for resource.
* @return Resource object
*/
- public final Resource resource(String path, Object... properties) {
+ @SuppressWarnings("null")
+ public final @NotNull Resource resource(@NotNull String path, @NotNull Object... properties) {
return resource(path, MapUtil.toMap(properties));
}
@@ -93,7 +99,8 @@ public class ContentBuilder {
* @param path Resource path
* @return Resource at path (existing or newly created)
*/
- protected final Resource ensureResourceExists(String path) {
+ @SuppressWarnings("null")
+ protected final @NotNull Resource ensureResourceExists(@NotNull String path) {
if (StringUtils.isEmpty(path) || StringUtils.equals(path, "/")) {
return resourceResolver.getResource("/");
}
@@ -102,6 +109,9 @@ public class ContentBuilder {
return resource;
}
String parentPath = ResourceUtil.getParent(path);
+ if (parentPath == null) {
+ throw new IllegalArgumentException("Path has no parent: " + path);
+ }
String name = ResourceUtil.getName(path);
Resource parentResource = ensureResourceExists(parentPath);
try {
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/builder/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/builder/package-info.java
index e8a9066..ed6acd2 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/builder/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/builder/package-info.java
@@ -19,5 +19,5 @@
/**
* Content builder for creating test content.
*/
-@org.osgi.annotation.versioning.Version("1.1")
+@org.osgi.annotation.versioning.Version("1.1.1")
package org.apache.sling.testing.mock.sling.builder;
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 65cf6d2..5b2be68 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
@@ -24,6 +24,8 @@ import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.testing.mock.sling.MockSling;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.osgi.framework.BundleContext;
/**
@@ -35,8 +37,8 @@ final class ContextResourceResolverFactory {
// static methods only
}
- public static ResourceResolverFactory get(final ResourceResolverType resourceResolverType,
- final BundleContext bundleContext) {
+ public static @NotNull ResourceResolverFactory get(@Nullable final ResourceResolverType resourceResolverType,
+ @NotNull final BundleContext bundleContext) {
ResourceResolverType type = resourceResolverType;
if (type == null) {
type = MockSling.DEFAULT_RESOURCERESOLVER_TYPE;
@@ -67,19 +69,19 @@ final class ContextResourceResolverFactory {
}
}
- private static void initializeJcrMock(ResourceResolverFactory factory) throws RepositoryException, LoginException {
+ private static void initializeJcrMock(@NotNull ResourceResolverFactory factory) throws RepositoryException, LoginException {
// nothing to do
}
- private static void initializeJcrOak(ResourceResolverFactory factory) {
+ private static void initializeJcrOak(@NotNull ResourceResolverFactory factory) {
// register sling node types?
}
- private static void initializeResourceResolverMock(ResourceResolverFactory factory) {
+ private static void initializeResourceResolverMock(@NotNull ResourceResolverFactory factory) {
// nothing to do
}
- private static void initializeResourceResolverNone(ResourceResolverFactory factory) {
+ private static void initializeResourceResolverNone(@NotNull ResourceResolverFactory factory) {
// nothing to do
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java b/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
index 7ff2195..7f63026 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
@@ -40,6 +40,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.testing.mock.osgi.ManifestScanner;
import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.jetbrains.annotations.NotNull;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -53,14 +54,14 @@ import org.reflections.Reflections;
*/
final class ModelAdapterFactoryUtil {
- private static final String PACKAGE_HEADER = "Sling-Model-Packages";
- private static final String CLASSES_HEADER = "Sling-Model-Classes";
+ private static final @NotNull String PACKAGE_HEADER = "Sling-Model-Packages";
+ private static final @NotNull String CLASSES_HEADER = "Sling-Model-Classes";
- private static final String[] MODELS_PACKAGES_FROM_MANIFEST;
- private static final String[] MODELS_CLASSES_FROM_MANIFEST;
+ private static final @NotNull String[] MODELS_PACKAGES_FROM_MANIFEST;
+ private static final @NotNull String[] MODELS_CLASSES_FROM_MANIFEST;
- private static final ConcurrentMap<String, List<URL>> MODEL_URLS_FOR_PACKAGES = new ConcurrentHashMap<String, List<URL>>();
- private static final ConcurrentMap<String, List<URL>> MODEL_URLS_FOR_CLASSES = new ConcurrentHashMap<String, List<URL>>();
+ private static final @NotNull ConcurrentMap<String, List<URL>> MODEL_URLS_FOR_PACKAGES = new ConcurrentHashMap<String, List<URL>>();
+ private static final @NotNull ConcurrentMap<String, List<URL>> MODEL_URLS_FOR_CLASSES = new ConcurrentHashMap<String, List<URL>>();
static {
// suppress log entries from Reflections library
@@ -75,7 +76,8 @@ final class ModelAdapterFactoryUtil {
// static methods only
}
- private static String[] toArray(Collection<String> values) {
+ @SuppressWarnings("null")
+ private static @NotNull String[] toArray(@NotNull Collection<String> values) {
return values.toArray(new String[values.size()]);
}
@@ -85,7 +87,7 @@ final class ModelAdapterFactoryUtil {
* @param bundleContext Bundle context
* @param packageNames Java package names
*/
- public static void addModelsForPackages(BundleContext bundleContext, String... packageNames) {
+ public static void addModelsForPackages(@NotNull BundleContext bundleContext, @NotNull String... packageNames) {
Bundle bundle = new RegisterModelsBundle(bundleContext, Bundle.ACTIVE, packageNames, null);
BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle);
MockOsgi.sendBundleEvent(bundleContext, event);
@@ -96,7 +98,7 @@ final class ModelAdapterFactoryUtil {
* @param bundleContext Bundle context
* @param classNames Java class names
*/
- public static void addModelsForClasses(BundleContext bundleContext, String... classNames) {
+ public static void addModelsForClasses(@NotNull BundleContext bundleContext, @NotNull String... classNames) {
Bundle bundle = new RegisterModelsBundle(bundleContext, Bundle.ACTIVE, null, classNames);
BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle);
MockOsgi.sendBundleEvent(bundleContext, event);
@@ -107,7 +109,7 @@ final class ModelAdapterFactoryUtil {
* @param bundleContext Bundle context
* @param classNames Java class names
*/
- public static void addModelsForClasses(BundleContext bundleContext, Class... classes) {
+ public static void addModelsForClasses(@NotNull BundleContext bundleContext, @NotNull Class... classes) {
String[] classNames = new String[classes.length];
for (int i = 0; i < classes.length; i++) {
classNames[i] = classes[i].getName();
@@ -119,7 +121,7 @@ final class ModelAdapterFactoryUtil {
* Scan MANIFEST.MF in the classpath and automatically register all sling model classes found.
* @param bundleContext Bundle context
*/
- public static void addModelsForManifestEntries(BundleContext bundleContext) {
+ public static void addModelsForManifestEntries(@NotNull BundleContext bundleContext) {
if (MODELS_PACKAGES_FROM_MANIFEST.length > 0) {
addModelsForPackages(bundleContext, MODELS_PACKAGES_FROM_MANIFEST);
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index 247fe9a..7b97f44 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -50,6 +50,8 @@ import org.apache.sling.testing.mock.sling.services.MockSlingSettingService;
import org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo;
import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ConsumerType;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
@@ -67,9 +69,10 @@ import com.google.common.collect.ImmutableSet;
public class SlingContextImpl extends OsgiContextImpl {
// default to publish instance run mode
- static final Set<String> DEFAULT_RUN_MODES = ImmutableSet.<String> builder().add("publish").build();
+ @SuppressWarnings("null")
+ static final @NotNull Set<String> DEFAULT_RUN_MODES = ImmutableSet.<String> builder().add("publish").build();
- private static final String RESOURCERESOLVERFACTORYACTIVATOR_PID = "org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl";
+ private static final @NotNull String RESOURCERESOLVERFACTORYACTIVATOR_PID = "org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl";
protected ResourceResolverFactory resourceResolverFactory;
protected ResourceResolverType resourceResolverType;
@@ -89,11 +92,16 @@ public class SlingContextImpl extends OsgiContextImpl {
/**
* @param resourceResolverType Resource resolver type
*/
- protected void setResourceResolverType(final ResourceResolverType resourceResolverType) {
- this.resourceResolverType = resourceResolverType;
+ protected void setResourceResolverType(@Nullable final ResourceResolverType resourceResolverType) {
+ if (resourceResolverType == null) {
+ this.resourceResolverType = MockSling.DEFAULT_RESOURCERESOLVER_TYPE;
+ }
+ else {
+ this.resourceResolverType = resourceResolverType;
+ }
}
- protected void setResourceResolverFactoryActivatorProps(Map<String, Object> props) {
+ protected void setResourceResolverFactoryActivatorProps(@Nullable Map<String, Object> props) {
this.resourceResolverFactoryActivatorProps = props;
}
@@ -126,11 +134,12 @@ public class SlingContextImpl extends OsgiContextImpl {
* Initialize mocked resource resolver factory.
* @return Resource resolver factory
*/
- protected ResourceResolverFactory newResourceResolverFactory() {
+ protected @NotNull ResourceResolverFactory newResourceResolverFactory() {
return ContextResourceResolverFactory.get(this.resourceResolverType, bundleContext());
}
- private ResourceResolverFactory resourceResolverFactory() {
+ @SuppressWarnings("null")
+ private @NotNull ResourceResolverFactory resourceResolverFactory() {
if (this.resourceResolverFactory == null) {
this.resourceResolverFactory = newResourceResolverFactory();
}
@@ -175,7 +184,8 @@ public class SlingContextImpl extends OsgiContextImpl {
}
}
- private void registerInjectActivateServiceByClassName(String... classNames) {
+ @SuppressWarnings("null")
+ private void registerInjectActivateServiceByClassName(@NotNull String... classNames) {
for (String className : classNames) {
try {
Class<?> clazz = Class.forName(className);
@@ -238,7 +248,8 @@ public class SlingContextImpl extends OsgiContextImpl {
/**
* @return Resource resolver type
*/
- public final ResourceResolverType resourceResolverType() {
+ @SuppressWarnings("null")
+ public final @NotNull ResourceResolverType resourceResolverType() {
return this.resourceResolverType;
}
@@ -247,7 +258,8 @@ public class SlingContextImpl extends OsgiContextImpl {
* It is automatically closed after the test.
* @return Resource resolver
*/
- public final ResourceResolver resourceResolver() {
+ @SuppressWarnings({ "deprecation", "null" })
+ public final @NotNull ResourceResolver resourceResolver() {
if (this.resourceResolver == null) {
try {
this.resourceResolver = this.resourceResolverFactory().getAdministrativeResourceResolver(null);
@@ -261,7 +273,8 @@ public class SlingContextImpl extends OsgiContextImpl {
/**
* @return Sling request
*/
- public final MockSlingHttpServletRequest request() {
+ @SuppressWarnings("null")
+ public final @NotNull MockSlingHttpServletRequest request() {
if (this.request == null) {
this.request = new MockSlingHttpServletRequest(this.resourceResolver(), this.bundleContext());
@@ -278,14 +291,16 @@ public class SlingContextImpl extends OsgiContextImpl {
/**
* @return Request path info
*/
- public final MockRequestPathInfo requestPathInfo() {
- return (MockRequestPathInfo) request().getRequestPathInfo();
+ @SuppressWarnings("null")
+ public final @NotNull MockRequestPathInfo requestPathInfo() {
+ return (MockRequestPathInfo)request().getRequestPathInfo();
}
/**
* @return Sling response
*/
- public final MockSlingHttpServletResponse response() {
+ @SuppressWarnings("null")
+ public final @NotNull MockSlingHttpServletResponse response() {
if (this.response == null) {
this.response = new MockSlingHttpServletResponse();
}
@@ -295,7 +310,8 @@ public class SlingContextImpl extends OsgiContextImpl {
/**
* @return Sling script helper
*/
- public final SlingScriptHelper slingScriptHelper() {
+ @SuppressWarnings("null")
+ public final @NotNull SlingScriptHelper slingScriptHelper() {
if (this.slingScriptHelper == null) {
this.slingScriptHelper = MockSling.newSlingScriptHelper(this.request(), this.response(),
this.bundleContext());
@@ -306,7 +322,7 @@ public class SlingContextImpl extends OsgiContextImpl {
/**
* @return Content loader
*/
- public ContentLoader load() {
+ public @NotNull ContentLoader load() {
return load(true);
}
@@ -314,7 +330,8 @@ public class SlingContextImpl extends OsgiContextImpl {
* @param autoCommit Automatically commit changes after loading content (default: true)
* @return Content loader
*/
- public ContentLoader load(boolean autoCommit) {
+ @SuppressWarnings("null")
+ public @NotNull ContentLoader load(boolean autoCommit) {
if (autoCommit) {
if (this.contentLoaderAutoCommit == null) {
this.contentLoaderAutoCommit = new ContentLoader(resourceResolver(), bundleContext(), true);
@@ -335,7 +352,8 @@ public class SlingContextImpl extends OsgiContextImpl {
* You can use alternatively the {@link #build()} method and use the {@link ResourceBuilder} API.
* @return Content builder for building test content
*/
- public ContentBuilder create() {
+ @SuppressWarnings("null")
+ public @NotNull ContentBuilder create() {
if (this.contentBuilder == null) {
this.contentBuilder = new ContentBuilder(resourceResolver());
}
@@ -348,7 +366,8 @@ public class SlingContextImpl extends OsgiContextImpl {
* You can use alternatively the {@link #create()} method to use the {@link ContentBuilder} API.
* @return Resource builder for building test content.
*/
- public ResourceBuilder build() {
+ @SuppressWarnings("null")
+ public @NotNull ResourceBuilder build() {
if (this.resourceBuilder == null) {
this.resourceBuilder = getService(ResourceBuilderFactory.class).forResolver(this.resourceResolver());
}
@@ -358,7 +377,7 @@ public class SlingContextImpl extends OsgiContextImpl {
/**
* @return Current resource
*/
- public final Resource currentResource() {
+ public final @Nullable Resource currentResource() {
return request().getResource();
}
@@ -367,7 +386,7 @@ public class SlingContextImpl extends OsgiContextImpl {
* @param resourcePath Resource path
* @return Current resource
*/
- public final Resource currentResource(String resourcePath) {
+ public final @Nullable Resource currentResource(@Nullable String resourcePath) {
if (resourcePath != null) {
Resource resource = resourceResolver().getResource(resourcePath);
if (resource == null) {
@@ -375,7 +394,7 @@ public class SlingContextImpl extends OsgiContextImpl {
}
return currentResource(resource);
} else {
- return currentResource((Resource) null);
+ return currentResource((Resource)null);
}
}
@@ -384,7 +403,7 @@ public class SlingContextImpl extends OsgiContextImpl {
* @param resource Resource
* @return Current resource
*/
- public final Resource currentResource(Resource resource) {
+ public final @Nullable Resource currentResource(@Nullable Resource resource) {
request().setResource(resource);
return resource;
}
@@ -394,7 +413,7 @@ public class SlingContextImpl extends OsgiContextImpl {
* register all classes with @Model annotation.
* @param packageName Java package name
*/
- public final void addModelsForPackage(String packageName) {
+ public final void addModelsForPackage(@NotNull String packageName) {
ModelAdapterFactoryUtil.addModelsForPackages(bundleContext(), packageName);
}
@@ -403,7 +422,7 @@ public class SlingContextImpl extends OsgiContextImpl {
* register all classes with @Model annotation.
* @param packageNames Java package names
*/
- public final void addModelsForPackage(String... packageNames) {
+ public final void addModelsForPackage(@NotNull String... packageNames) {
ModelAdapterFactoryUtil.addModelsForPackages(bundleContext(), packageNames);
}
@@ -411,7 +430,7 @@ public class SlingContextImpl extends OsgiContextImpl {
* Search classpath for given class names to scan for and register all classes with @Model annotation.
* @param classNames Java class names
*/
- public final void addModelsForClasses(String... classNames) {
+ public final void addModelsForClasses(@NotNull String... classNames) {
ModelAdapterFactoryUtil.addModelsForClasses(bundleContext(), classNames);
}
@@ -419,7 +438,7 @@ public class SlingContextImpl extends OsgiContextImpl {
* Search classpath for given class names to scan for and register all classes with @Model annotation.
* @param classes Java classes
*/
- public final void addModelsForClasses(Class... classes) {
+ public final void addModelsForClasses(@NotNull Class... classes) {
ModelAdapterFactoryUtil.addModelsForClasses(bundleContext(), classes);
}
@@ -427,7 +446,8 @@ public class SlingContextImpl extends OsgiContextImpl {
* Set current run mode(s).
* @param runModes Run mode(s).
*/
- public final void runMode(String... runModes) {
+ @SuppressWarnings("null")
+ public final void runMode(@NotNull String... runModes) {
Set<String> newRunModes = ImmutableSet.<String> builder().add(runModes).build();
ServiceReference<SlingSettingsService> ref = bundleContext().getServiceReference(SlingSettingsService.class);
if (ref != null) {
@@ -440,7 +460,8 @@ public class SlingContextImpl extends OsgiContextImpl {
* Create unique root paths for unit tests (and clean them up after the test run automatically).
* @return Unique root path helper
*/
- public UniqueRoot uniqueRoot() {
+ @SuppressWarnings("null")
+ public @NotNull UniqueRoot uniqueRoot() {
if (uniqueRoot == null) {
uniqueRoot = new UniqueRoot(this);
}
@@ -456,11 +477,11 @@ public class SlingContextImpl extends OsgiContextImpl {
* @param <T1> Adaptable type
* @param <T2> Adapter type
*/
- public final <T1, T2> void registerAdapter(final Class<T1> adaptableClass, final Class<T2> adapterClass,
- final T2 adapter) {
+ public final <T1, T2> void registerAdapter(@NotNull final Class<T1> adaptableClass, @NotNull final Class<T2> adapterClass,
+ @NotNull final T2 adapter) {
registerAdapter(adaptableClass, adapterClass, new Function<T1, T2>() {
@Override
- public T2 apply(T1 input) {
+ public T2 apply(@Nullable T1 input) {
return adapter;
}
});
@@ -475,12 +496,12 @@ public class SlingContextImpl extends OsgiContextImpl {
* @param <T1> Adaptable type
* @param <T2> Adapter type
*/
- public final <T1, T2> void registerAdapter(final Class<T1> adaptableClass, final Class<T2> adapterClass,
- final Function<T1,T2> adaptHandler) {
+ public final <T1, T2> void registerAdapter(@NotNull final Class<T1> adaptableClass, @NotNull final Class<T2> adapterClass,
+ @NotNull final Function<T1,T2> adaptHandler) {
AdapterFactory adapterFactory = new AdapterFactory() {
@SuppressWarnings("unchecked")
@Override
- public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
+ public <AdapterType> AdapterType getAdapter(@NotNull Object adaptable, @NotNull Class<AdapterType> type) {
return (AdapterType)adaptHandler.apply((T1)adaptable);
}
};
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java b/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
index f5f68d3..4afa6ba 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.JcrConstants;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
+import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ConsumerType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,7 +50,7 @@ public class UniqueRoot {
private static final Logger log = LoggerFactory.getLogger(UniqueRoot.class);
- protected UniqueRoot(SlingContextImpl context) {
+ protected UniqueRoot(@NotNull SlingContextImpl context) {
this.context = context;
// generate unique path part by using a UUID
uniquePathPart = UUID.randomUUID().toString();
@@ -61,7 +62,7 @@ public class UniqueRoot {
* @param primaryType JCR primary type
* @return Resource (never null)
*/
- protected final Resource getOrCreateResource(String path, String primaryType) {
+ protected final Resource getOrCreateResource(@NotNull String path, @NotNull String primaryType) {
try {
return ResourceUtil.getOrCreateResource(context.resourceResolver(), path,
ImmutableMap.<String,Object>of(JcrConstants.JCR_PRIMARYTYPE, primaryType),
@@ -77,7 +78,7 @@ public class UniqueRoot {
* The path (incl. all children) is automatically removed when the unit test completes.
* @return Unique content path
*/
- public final String content() {
+ public final @NotNull String content() {
if (contentRoot == null) {
contentRoot = getOrCreateResource("/content/" + uniquePathPart, "sling:OrderedFolder");
}
@@ -89,7 +90,7 @@ public class UniqueRoot {
* The path (incl. all children) is automatically removed when the unit test completes.
* @return Unique content path
*/
- public final String apps() {
+ public final @NotNull String apps() {
if (appsRoot == null) {
appsRoot = getOrCreateResource("/apps/" + uniquePathPart, "sling:OrderedFolder");
}
@@ -101,7 +102,7 @@ public class UniqueRoot {
* The path (incl. all children) is automatically removed when the unit test completes.
* @return Unique content path
*/
- public final String libs() {
+ public final @NotNull String libs() {
if (libsRoot == null) {
libsRoot = getOrCreateResource("/libs/" + uniquePathPart, "sling:OrderedFolder");
}
@@ -120,7 +121,7 @@ public class UniqueRoot {
* Deletes the given set of resources and commits afterwards.
* @param resources Resources to be deleted
*/
- protected final void deleteResources(Resource... resources) {
+ protected final void deleteResources(@NotNull Resource... resources) {
for (Resource resource : resources) {
if (resource != null && context.resourceResolver.getResource(resource.getPath()) != null) {
try {
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
index aef0cd0..5e25f5b 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
@@ -19,5 +19,5 @@
/**
* Sling context implementation for unit tests.
*/
-@org.osgi.annotation.versioning.Version("3.6")
+@org.osgi.annotation.versioning.Version("3.6.1")
package org.apache.sling.testing.mock.sling.context;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContext.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContext.java
index 3239c5f..9ceda62 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContext.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContext.java
@@ -25,6 +25,8 @@ import org.apache.sling.testing.mock.osgi.context.ContextPlugins;
import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.apache.sling.testing.mock.sling.context.SlingContextImpl;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.junit.rules.ExternalResource;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
@@ -54,7 +56,7 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* Initialize Sling context with resource resolver type.
* @param resourceResolverType Resource resolver type.
*/
- public SlingContext(final ResourceResolverType resourceResolverType) {
+ public SlingContext(@NotNull final ResourceResolverType resourceResolverType) {
this(new ContextPlugins(), null, resourceResolverType);
}
@@ -64,7 +66,7 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* @param <T> context type
* @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
*/
- public <T extends OsgiContextImpl> SlingContext(final ContextCallback<T> afterSetUpCallback) {
+ public <T extends OsgiContextImpl> SlingContext(@NotNull final ContextCallback<T> afterSetUpCallback) {
this(new ContextPlugins(afterSetUpCallback), null, null);
}
@@ -74,7 +76,7 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
* @param resourceResolverType Resource resolver type.
*/
- public <T extends OsgiContextImpl> SlingContext(final ContextCallback<T> afterSetUpCallback, final ResourceResolverType resourceResolverType) {
+ public <T extends OsgiContextImpl> SlingContext(@NotNull final ContextCallback<T> afterSetUpCallback, @NotNull final ResourceResolverType resourceResolverType) {
this(new ContextPlugins(afterSetUpCallback), null, resourceResolverType);
}
@@ -86,7 +88,8 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
* @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
*/
- public <U extends OsgiContextImpl, V extends OsgiContextImpl> SlingContext(final ContextCallback<U> afterSetUpCallback, final ContextCallback<V> beforeTearDownCallback) {
+ public <U extends OsgiContextImpl, V extends OsgiContextImpl> SlingContext(@NotNull final ContextCallback<U> afterSetUpCallback,
+ @NotNull final ContextCallback<V> beforeTearDownCallback) {
this(new ContextPlugins(afterSetUpCallback, beforeTearDownCallback), null, null);
}
@@ -98,8 +101,9 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
* @param resourceResolverType Resource resolver type.
*/
- public <U extends OsgiContextImpl, V extends OsgiContextImpl> SlingContext(final ContextCallback<U> afterSetUpCallback, final ContextCallback<V> beforeTearDownCallback,
- final ResourceResolverType resourceResolverType) {
+ public <U extends OsgiContextImpl, V extends OsgiContextImpl> SlingContext(@NotNull final ContextCallback<U> afterSetUpCallback,
+ @NotNull final ContextCallback<V> beforeTearDownCallback,
+ @NotNull final ResourceResolverType resourceResolverType) {
this(new ContextPlugins(afterSetUpCallback, beforeTearDownCallback), null, resourceResolverType);
}
@@ -109,9 +113,9 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* @param resourceResolverFactoryActivatorProps Allows to override OSGi configuration parameters for the Resource Resolver Factory Activator service.
* @param resourceResolverType Resource resolver type.
*/
- SlingContext(final ContextPlugins contextPlugins,
- final Map<String, Object> resourceResolverFactoryActivatorProps,
- final ResourceResolverType resourceResolverType) {
+ SlingContext(@NotNull final ContextPlugins contextPlugins,
+ @Nullable final Map<String, Object> resourceResolverFactoryActivatorProps,
+ @Nullable final ResourceResolverType resourceResolverType) {
this(contextPlugins, resourceResolverFactoryActivatorProps, resourceResolverType, true);
}
@@ -122,9 +126,9 @@ public final class SlingContext extends SlingContextImpl implements TestRule {
* @param resourceResolverType Resource resolver type.
* @param registerSlingModelsFromClassPath Automatic registering of all Sling Models found in the classpath on startup.
*/
- SlingContext(final ContextPlugins contextPlugins,
- final Map<String, Object> resourceResolverFactoryActivatorProps,
- final ResourceResolverType resourceResolverType,
+ SlingContext(@NotNull final ContextPlugins contextPlugins,
+ @Nullable final Map<String, Object> resourceResolverFactoryActivatorProps,
+ @Nullable final ResourceResolverType resourceResolverType,
final boolean registerSlingModelsFromClassPath) {
this.plugins = contextPlugins;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextBuilder.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextBuilder.java
index 0a2ccc7..e7fe3f6 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextBuilder.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/SlingContextBuilder.java
@@ -25,6 +25,7 @@ import org.apache.sling.testing.mock.osgi.context.ContextPlugin;
import org.apache.sling.testing.mock.osgi.context.ContextPlugins;
import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ProviderType;
/**
@@ -33,7 +34,7 @@ import org.osgi.annotation.versioning.ProviderType;
@ProviderType
public final class SlingContextBuilder {
- private final ContextPlugins plugins = new ContextPlugins();
+ private final @NotNull ContextPlugins plugins = new ContextPlugins();
private ResourceResolverType resourceResolverType;
private Map<String, Object> resourceResolverFactoryActivatorProps;
private boolean registerSlingModelsFromClassPath = true;
@@ -47,7 +48,7 @@ public final class SlingContextBuilder {
* Create builder with given resource resolver type.
* @param resourceResolverType Resource resolver type.
*/
- public SlingContextBuilder(ResourceResolverType resourceResolverType) {
+ public SlingContextBuilder(@NotNull ResourceResolverType resourceResolverType) {
this.resourceResolverType(resourceResolverType);
}
@@ -55,7 +56,7 @@ public final class SlingContextBuilder {
* @param resourceResolverType Resource resolver type.
* @return this
*/
- public SlingContextBuilder resourceResolverType(ResourceResolverType resourceResolverType) {
+ public @NotNull SlingContextBuilder resourceResolverType(@NotNull ResourceResolverType resourceResolverType) {
this.resourceResolverType = resourceResolverType;
return this;
}
@@ -66,7 +67,7 @@ public final class SlingContextBuilder {
* @return this
*/
@SafeVarargs
- public final <T extends OsgiContextImpl> SlingContextBuilder plugin(ContextPlugin<T>... plugin) {
+ public final @NotNull <T extends OsgiContextImpl> SlingContextBuilder plugin(@NotNull ContextPlugin<T>... plugin) {
plugins.addPlugin(plugin);
return this;
}
@@ -77,7 +78,7 @@ public final class SlingContextBuilder {
* @return this
*/
@SafeVarargs
- public final <T extends OsgiContextImpl> SlingContextBuilder beforeSetUp(ContextCallback<T>... beforeSetUpCallback) {
+ public final @NotNull <T extends OsgiContextImpl> SlingContextBuilder beforeSetUp(@NotNull ContextCallback<T>... beforeSetUpCallback) {
plugins.addBeforeSetUpCallback(beforeSetUpCallback);
return this;
}
@@ -88,7 +89,7 @@ public final class SlingContextBuilder {
* @return this
*/
@SafeVarargs
- public final <T extends OsgiContextImpl> SlingContextBuilder afterSetUp(ContextCallback<T>... afterSetUpCallback) {
+ public final @NotNull <T extends OsgiContextImpl> SlingContextBuilder afterSetUp(@NotNull ContextCallback<T>... afterSetUpCallback) {
plugins.addAfterSetUpCallback(afterSetUpCallback);
return this;
}
@@ -99,7 +100,7 @@ public final class SlingContextBuilder {
* @return this
*/
@SafeVarargs
- public final <T extends OsgiContextImpl> SlingContextBuilder beforeTearDown(ContextCallback<T>... beforeTearDownCallback) {
+ public final @NotNull <T extends OsgiContextImpl> SlingContextBuilder beforeTearDown(@NotNull ContextCallback<T>... beforeTearDownCallback) {
plugins.addBeforeTearDownCallback(beforeTearDownCallback);
return this;
}
@@ -110,7 +111,7 @@ public final class SlingContextBuilder {
* @return this
*/
@SafeVarargs
- public final <T extends OsgiContextImpl> SlingContextBuilder afterTearDown(ContextCallback<T>... afterTearDownCallback) {
+ public final @NotNull <T extends OsgiContextImpl> SlingContextBuilder afterTearDown(@NotNull ContextCallback<T>... afterTearDownCallback) {
plugins.addAfterTearDownCallback(afterTearDownCallback);
return this;
}
@@ -120,7 +121,7 @@ public final class SlingContextBuilder {
* @param props Configuration properties
* @return this
*/
- public SlingContextBuilder resourceResolverFactoryActivatorProps(Map<String, Object> props) {
+ public @NotNull SlingContextBuilder resourceResolverFactoryActivatorProps(@NotNull Map<String, Object> props) {
this.resourceResolverFactoryActivatorProps = props;
return this;
}
@@ -130,7 +131,7 @@ public final class SlingContextBuilder {
* @param registerSlingModelsFromClassPath If set to false Sling Models are not registered automatically from the classpath on startup.
* @return this
*/
- public SlingContextBuilder registerSlingModelsFromClassPath(boolean registerSlingModelsFromClassPath) {
+ public @NotNull SlingContextBuilder registerSlingModelsFromClassPath(boolean registerSlingModelsFromClassPath) {
this.registerSlingModelsFromClassPath = registerSlingModelsFromClassPath;
return this;
}
@@ -138,7 +139,7 @@ public final class SlingContextBuilder {
/**
* @return Build {@link SlingContext} instance.
*/
- public SlingContext build() {
+ public @NotNull SlingContext build() {
return new SlingContext(this.plugins,
this.resourceResolverFactoryActivatorProps,
this.resourceResolverType,
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
index ae9cd05..a578651 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
@@ -19,5 +19,5 @@
/**
* Rule for providing easy access to Sling context in JUnit tests.
*/
-@org.osgi.annotation.versioning.Version("4.2")
+@org.osgi.annotation.versioning.Version("4.2.1")
package org.apache.sling.testing.mock.sling.junit;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java b/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
index f62a1f1..ba7f822 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
@@ -38,6 +38,8 @@ import org.apache.sling.jcr.contentparser.ContentType;
import org.apache.sling.jcr.contentparser.JsonParserFeature;
import org.apache.sling.jcr.contentparser.ParseException;
import org.apache.sling.jcr.contentparser.ParserOptions;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -77,7 +79,7 @@ public final class ContentLoader {
/**
* @param resourceResolver Resource resolver
*/
- public ContentLoader(ResourceResolver resourceResolver) {
+ public ContentLoader(@NotNull ResourceResolver resourceResolver) {
this(resourceResolver, null);
}
@@ -85,7 +87,7 @@ public final class ContentLoader {
* @param resourceResolver Resource resolver
* @param bundleContext Bundle context
*/
- public ContentLoader(ResourceResolver resourceResolver, BundleContext bundleContext) {
+ public ContentLoader(@NotNull ResourceResolver resourceResolver, @Nullable BundleContext bundleContext) {
this (resourceResolver, bundleContext, true);
}
@@ -94,7 +96,7 @@ public final class ContentLoader {
* @param bundleContext Bundle context
* @param autoCommit Automatically commit changes after loading content (default: true)
*/
- public ContentLoader(ResourceResolver resourceResolver, BundleContext bundleContext, boolean autoCommit) {
+ public ContentLoader(@NotNull ResourceResolver resourceResolver, @Nullable BundleContext bundleContext, boolean autoCommit) {
this.resourceResolver = resourceResolver;
this.bundleContext = bundleContext;
this.autoCommit = autoCommit;
@@ -107,7 +109,7 @@ public final class ContentLoader {
* @param childName Name of child resource to create with JSON content
* @return Resource
*/
- public Resource json(String classpathResource, Resource parentResource, String childName) {
+ public @NotNull Resource json(@NotNull String classpathResource, @NotNull Resource parentResource, @NotNull String childName) {
InputStream is = ContentLoader.class.getResourceAsStream(classpathResource);
if (is == null) {
throw new IllegalArgumentException("Classpath resource not found: " + classpathResource);
@@ -130,7 +132,7 @@ public final class ContentLoader {
* @param destPath Path to import the JSON content to
* @return Resource
*/
- public Resource json(String classpathResource, String destPath) {
+ public @NotNull Resource json(@NotNull String classpathResource, @NotNull String destPath) {
InputStream is = ContentLoader.class.getResourceAsStream(classpathResource);
if (is == null) {
throw new IllegalArgumentException("Classpath resource not found: " + classpathResource);
@@ -153,7 +155,7 @@ public final class ContentLoader {
* @param childName Name of child resource to create with JSON content
* @return Resource
*/
- public Resource json(InputStream inputStream, Resource parentResource, String childName) {
+ public @NotNull Resource json(@NotNull InputStream inputStream, @NotNull Resource parentResource, @NotNull String childName) {
return json(inputStream, parentResource.getPath() + "/" + childName);
}
@@ -164,10 +166,15 @@ public final class ContentLoader {
* @param destPath Path to import the JSON content to
* @return Resource
*/
- public Resource json(InputStream inputStream, String destPath) {
+ @SuppressWarnings("null")
+ public @NotNull Resource json(@NotNull InputStream inputStream, @NotNull String destPath) {
try {
String parentPath = ResourceUtil.getParent(destPath);
String childName = ResourceUtil.getName(destPath);
+
+ if (parentPath == null) {
+ throw new IllegalArgumentException("Path has no parent: " + destPath);
+ }
Resource parentResource = resourceResolver.getResource(parentPath);
if (parentResource == null) {
@@ -190,10 +197,10 @@ public final class ContentLoader {
}
}
- private Resource createResourceHierarchy(String path) {
+ private @NotNull Resource createResourceHierarchy(@NotNull String path) {
String parentPath = ResourceUtil.getParent(path);
if (parentPath == null) {
- return null;
+ throw new IllegalArgumentException("Path has no parent: " + path);
}
Resource parentResource = resourceResolver.getResource(parentPath);
if (parentResource == null) {
@@ -217,7 +224,7 @@ public final class ContentLoader {
* automatically)
* @return Resource with binary data
*/
- public Resource binaryFile(String classpathResource, String path) {
+ public @NotNull Resource binaryFile(@NotNull String classpathResource, @NotNull String path) {
InputStream is = ContentLoader.class.getResourceAsStream(classpathResource);
if (is == null) {
throw new IllegalArgumentException("Classpath resource not found: " + classpathResource);
@@ -242,7 +249,7 @@ public final class ContentLoader {
* @param mimeType Mime type of binary data
* @return Resource with binary data
*/
- public Resource binaryFile(String classpathResource, String path, String mimeType) {
+ public @NotNull Resource binaryFile(@NotNull String classpathResource, @NotNull String path, @NotNull String mimeType) {
InputStream is = ContentLoader.class.getResourceAsStream(classpathResource);
if (is == null) {
throw new IllegalArgumentException("Classpath resource not found: " + classpathResource);
@@ -267,7 +274,7 @@ public final class ContentLoader {
* automatically)
* @return Resource with binary data
*/
- public Resource binaryFile(InputStream inputStream, String path) {
+ public @NotNull Resource binaryFile(@NotNull InputStream inputStream, @NotNull String path) {
return binaryFile(inputStream, path, detectMimeTypeFromNames(path));
}
@@ -280,9 +287,12 @@ public final class ContentLoader {
* @param mimeType Mime type of binary data
* @return Resource with binary data
*/
- public Resource binaryFile(InputStream inputStream, String path, String mimeType) {
+ public @NotNull Resource binaryFile(@NotNull InputStream inputStream, @NotNull String path, @NotNull String mimeType) {
String parentPath = ResourceUtil.getParent(path, 1);
String name = ResourceUtil.getName(path);
+ if (parentPath == null) {
+ throw new IllegalArgumentException("Path has no parent: " + path);
+ }
Resource parentResource = resourceResolver.getResource(parentPath);
if (parentResource == null) {
parentResource = createResourceHierarchy(parentPath);
@@ -299,7 +309,7 @@ public final class ContentLoader {
* @param name Resource name for nt:file
* @return Resource with binary data
*/
- public Resource binaryFile(InputStream inputStream, Resource parentResource, String name) {
+ public @NotNull Resource binaryFile(@NotNull InputStream inputStream, @NotNull Resource parentResource, @NotNull String name) {
return binaryFile(inputStream, parentResource, name, detectMimeTypeFromNames(name));
}
@@ -312,7 +322,8 @@ public final class ContentLoader {
* @param mimeType Mime type of binary data
* @return Resource with binary data
*/
- public Resource binaryFile(InputStream inputStream, Resource parentResource, String name, String mimeType) {
+ @SuppressWarnings("null")
+ public @NotNull Resource binaryFile(@NotNull InputStream inputStream, @NotNull Resource parentResource, @NotNull String name, @NotNull String mimeType) {
try {
Resource file = resourceResolver.create(parentResource, name,
ImmutableMap.<String, Object> builder().put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_FILE)
@@ -338,7 +349,7 @@ public final class ContentLoader {
* automatically)
* @return Resource with binary data
*/
- public Resource binaryResource(String classpathResource, String path) {
+ public @NotNull Resource binaryResource(@NotNull String classpathResource, @NotNull String path) {
InputStream is = ContentLoader.class.getResourceAsStream(classpathResource);
if (is == null) {
throw new IllegalArgumentException("Classpath resource not found: " + classpathResource);
@@ -363,7 +374,7 @@ public final class ContentLoader {
* @param mimeType Mime type of binary data
* @return Resource with binary data
*/
- public Resource binaryResource(String classpathResource, String path, String mimeType) {
+ public @NotNull Resource binaryResource(@NotNull String classpathResource, @NotNull String path, @NotNull String mimeType) {
InputStream is = ContentLoader.class.getResourceAsStream(classpathResource);
if (is == null) {
throw new IllegalArgumentException("Classpath resource not found: " + classpathResource);
@@ -388,7 +399,7 @@ public final class ContentLoader {
* automatically)
* @return Resource with binary data
*/
- public Resource binaryResource(InputStream inputStream, String path) {
+ public @NotNull Resource binaryResource(@NotNull InputStream inputStream, @NotNull String path) {
return binaryResource(inputStream, path, detectMimeTypeFromNames(path));
}
@@ -401,9 +412,12 @@ public final class ContentLoader {
* @param mimeType Mime type of binary data
* @return Resource with binary data
*/
- public Resource binaryResource(InputStream inputStream, String path, String mimeType) {
+ public @NotNull Resource binaryResource(@NotNull InputStream inputStream, @NotNull String path, @NotNull String mimeType) {
String parentPath = ResourceUtil.getParent(path, 1);
String name = ResourceUtil.getName(path);
+ if (parentPath == null) {
+ throw new IllegalArgumentException("Path has no parent: " + path);
+ }
Resource parentResource = resourceResolver.getResource(parentPath);
if (parentResource == null) {
parentResource = createResourceHierarchy(parentPath);
@@ -420,7 +434,7 @@ public final class ContentLoader {
* @param name Resource name for nt:resource
* @return Resource with binary data
*/
- public Resource binaryResource(InputStream inputStream, Resource parentResource, String name) {
+ public @NotNull Resource binaryResource(@NotNull InputStream inputStream, @NotNull Resource parentResource, @NotNull String name) {
return binaryResource(inputStream, parentResource, name, detectMimeTypeFromNames(name));
}
@@ -433,7 +447,7 @@ public final class ContentLoader {
* @param mimeType Mime type of binary data
* @return Resource with binary data
*/
- public Resource binaryResource(InputStream inputStream, Resource parentResource, String name, String mimeType) {
+ public @NotNull Resource binaryResource(@NotNull InputStream inputStream, @NotNull Resource parentResource, @NotNull String name, @NotNull String mimeType) {
try {
Resource resource = resourceResolver.create(parentResource, name,
ImmutableMap.<String, Object> builder().put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_RESOURCE)
@@ -453,7 +467,8 @@ public final class ContentLoader {
* @param names The names from which to derive the mime type
* @return Mime type (never null)
*/
- private String detectMimeTypeFromNames(String... names) {
+ @SuppressWarnings("null")
+ private @NotNull String detectMimeTypeFromNames(@NotNull String... names) {
String mimeType = null;
for (String name : names) {
String fileExtension = StringUtils.substringAfterLast(name, ".");
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java b/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java
index 9077cd4..93beb2d 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java
@@ -30,15 +30,17 @@ import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.jcr.contentparser.ContentHandler;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
final class LoaderContentHandler implements ContentHandler {
private static final String JCR_DATA_PLACEHOLDER = ":jcr:data";
- private final String rootPath;
- private final ResourceResolver resourceResolver;
+ private final @NotNull String rootPath;
+ private final @NotNull ResourceResolver resourceResolver;
- public LoaderContentHandler(String rootPath, ResourceResolver resourceResolver) {
+ public LoaderContentHandler(@NotNull String rootPath, @NotNull ResourceResolver resourceResolver) {
this.rootPath = rootPath;
this.resourceResolver = resourceResolver;
}
@@ -52,6 +54,10 @@ final class LoaderContentHandler implements ContentHandler {
String parentPath = ResourceUtil.getParent(fullPath);
String name = ResourceUtil.getName(fullPath);
+ if (parentPath == null) {
+ throw new IllegalArgumentException("Path has no parent: " + fullPath);
+ }
+
Resource parentResource = resourceResolver.getResource(parentPath);
if (parentResource == null) {
throw new RuntimeException("Parent resource '" + parentPath + "' not found.");
@@ -64,18 +70,20 @@ final class LoaderContentHandler implements ContentHandler {
}
}
- private Resource createResource(Resource parentResource, String childName, Map<String,Object> content) throws PersistenceException {
+ private Resource createResource(@NotNull Resource parentResource, @NotNull String childName, @Nullable Map<String,Object> content) throws PersistenceException {
// collect all properties first
boolean hasJcrData = false;
Map<String, Object> props = new HashMap<String, Object>();
- for (Map.Entry<String,Object> entry : content.entrySet()) {
- final String name = entry.getKey();
- if (StringUtils.equals(name, JCR_DATA_PLACEHOLDER)) {
- hasJcrData = true;
- }
- else {
- props.put(name, entry.getValue());
+ if (content != null) {
+ for (Map.Entry<String,Object> entry : content.entrySet()) {
+ final String name = entry.getKey();
+ if (StringUtils.equals(name, JCR_DATA_PLACEHOLDER)) {
+ hasJcrData = true;
+ }
+ else {
+ props.put(name, entry.getValue());
+ }
}
}
@@ -85,7 +93,9 @@ final class LoaderContentHandler implements ContentHandler {
if (hasJcrData) {
ModifiableValueMap valueMap = resource.adaptTo(ModifiableValueMap.class);
// we cannot import binary data here - but to avoid complaints by JCR we create it with empty binary data
- valueMap.put(JcrConstants.JCR_DATA, new ByteArrayInputStream(new byte[0]));
+ if (valueMap != null) {
+ valueMap.put(JcrConstants.JCR_DATA, new ByteArrayInputStream(new byte[0]));
+ }
}
return resource;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/loader/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/loader/package-info.java
index 92b8da5..5ac8bb3 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/loader/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/loader/package-info.java
@@ -19,5 +19,5 @@
/**
* Helpers for importing test content into the mocked repositories / resource hierarchies.
*/
-@org.osgi.annotation.versioning.Version("1.1")
+@org.osgi.annotation.versioning.Version("1.1.1")
package org.apache.sling.testing.mock.sling.loader;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
index 69cd586..507d918 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
@@ -19,5 +19,5 @@
/**
* Mock implementation of selected Sling APIs.
*/
-@org.osgi.annotation.versioning.Version("3.1")
+@org.osgi.annotation.versioning.Version("3.1.1")
package org.apache.sling.testing.mock.sling;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/services/MockSlingSettingService.java b/src/main/java/org/apache/sling/testing/mock/sling/services/MockSlingSettingService.java
index e665609..22a2cf8 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/services/MockSlingSettingService.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/services/MockSlingSettingService.java
@@ -23,6 +23,7 @@ import java.util.Set;
import java.util.UUID;
import org.apache.sling.settings.SlingSettingsService;
+import org.jetbrains.annotations.NotNull;
import com.google.common.collect.ImmutableSet;
@@ -37,6 +38,7 @@ public final class MockSlingSettingService implements SlingSettingsService {
/**
* Instantiate with no default run modes.
*/
+ @SuppressWarnings("null")
public MockSlingSettingService() {
this(ImmutableSet.<String> of());
}
@@ -45,7 +47,7 @@ public final class MockSlingSettingService implements SlingSettingsService {
* Instantiate with given run modes
* @param defaultRunModes Run modes
*/
- public MockSlingSettingService(Set<String> defaultRunModes) {
+ public MockSlingSettingService(@NotNull Set<String> defaultRunModes) {
this.runModes = defaultRunModes;
this.slingId = UUID.randomUUID().toString();
}
@@ -55,7 +57,7 @@ public final class MockSlingSettingService implements SlingSettingsService {
return ImmutableSet.copyOf(this.runModes);
}
- public void setRunModes(Set<String> runModes) {
+ public void setRunModes(@NotNull Set<String> runModes) {
this.runModes = runModes;
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/services/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/services/package-info.java
index 37315a7..802b526 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/services/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/services/package-info.java
@@ -19,5 +19,5 @@
/**
* Mocks for selected Sling services.
*/
-@org.osgi.annotation.versioning.Version("2.0.1")
+@org.osgi.annotation.versioning.Version("2.0.3")
package org.apache.sling.testing.mock.sling.services;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java b/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
index 798ad02..326cdba 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
@@ -24,6 +24,7 @@ import java.util.ResourceBundle;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.i18n.ResourceBundleProvider;
import org.apache.sling.testing.mock.sling.MockSling;
+import org.jetbrains.annotations.NotNull;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -38,7 +39,7 @@ public class MockSlingHttpServletRequest extends org.apache.sling.servlethelpers
* Instantiate with default resource resolver
* @param bundleContext Bundle context
*/
- public MockSlingHttpServletRequest(BundleContext bundleContext) {
+ public MockSlingHttpServletRequest(@NotNull BundleContext bundleContext) {
this(MockSling.newResourceResolver(bundleContext), bundleContext);
}
@@ -46,16 +47,16 @@ public class MockSlingHttpServletRequest extends org.apache.sling.servlethelpers
* @param resourceResolver Resource resolver
* @param bundleContext Bundle context
*/
- public MockSlingHttpServletRequest(ResourceResolver resourceResolver, BundleContext bundleContext) {
+ public MockSlingHttpServletRequest(@NotNull ResourceResolver resourceResolver, @NotNull BundleContext bundleContext) {
super(resourceResolver);
this.bundleContext = bundleContext;
}
- protected MockRequestPathInfo newMockRequestPathInfo() {
+ protected @NotNull MockRequestPathInfo newMockRequestPathInfo() {
return new MockRequestPathInfo();
}
- protected MockHttpSession newMockHttpSession() {
+ protected @NotNull MockHttpSession newMockHttpSession() {
return new MockHttpSession();
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/servlet/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/servlet/package-info.java
index 4d35479..b9c9289 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/servlet/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/servlet/package-info.java
@@ -19,5 +19,5 @@
/**
* Mock implementation of selected Servlet-related Sling APIs.
*/
-@org.osgi.annotation.versioning.Version("3.0")
+@org.osgi.annotation.versioning.Version("3.0.1")
package org.apache.sling.testing.mock.sling.servlet;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/spi/ResourceResolverTypeAdapter.java b/src/main/java/org/apache/sling/testing/mock/sling/spi/ResourceResolverTypeAdapter.java
index cc20279..66bde79 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/spi/ResourceResolverTypeAdapter.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/spi/ResourceResolverTypeAdapter.java
@@ -20,6 +20,7 @@ package org.apache.sling.testing.mock.sling.spi;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.jcr.api.SlingRepository;
+import org.jetbrains.annotations.Nullable;
/**
* SPI interface for resource resolver type implementations to provide a mock
@@ -33,7 +34,7 @@ public interface ResourceResolverTypeAdapter {
* {@link #newSlingRepository()} has to return a value.
* @return Resource resolver factory instance or null
*/
- ResourceResolverFactory newResourceResolverFactory();
+ @Nullable ResourceResolverFactory newResourceResolverFactory();
/**
* Get SlingRepository instance. Can be null if a resource resolver factory
@@ -41,6 +42,6 @@ public interface ResourceResolverTypeAdapter {
* {@link #newResourceResolverFactory()} has to return a value.
* @return Sling repository instance or null
*/
- SlingRepository newSlingRepository();
+ @Nullable SlingRepository newSlingRepository();
}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/spi/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/spi/package-info.java
index 99975db..0e84e95 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/spi/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/spi/package-info.java
@@ -19,5 +19,5 @@
/**
* SPI for hooking in alternative resource type adapter implementations.
*/
-@org.osgi.annotation.versioning.Version("1.0")
+@org.osgi.annotation.versioning.Version("1.0.1")
package org.apache.sling.testing.mock.sling.spi;
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java b/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
index 462044d..d66f554 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
@@ -36,6 +36,7 @@ import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.BundleContext;
+@SuppressWarnings("null")
public class MockSlingScriptHelperTest {
private ResourceResolver resourceResolver;
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/builder/ContentBuilderTest.java b/src/test/java/org/apache/sling/testing/mock/sling/builder/ContentBuilderTest.java
index 7e8ecb5..d92cdeb 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/builder/ContentBuilderTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/builder/ContentBuilderTest.java
@@ -32,6 +32,7 @@ import org.junit.Test;
import com.google.common.collect.ImmutableMap;
+@SuppressWarnings("null")
public class ContentBuilderTest {
@Rule
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
index 5f7de84..97f6d24 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
@@ -42,6 +42,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+@SuppressWarnings("null")
public abstract class AbstractSlingContextImplTest {
@Rule
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/NoResourceResolverTypeTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/NoResourceResolverTypeTest.java
index 5af4d3e..5906a0b 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/NoResourceResolverTypeTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/NoResourceResolverTypeTest.java
@@ -32,6 +32,7 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
+@SuppressWarnings("null")
public class NoResourceResolverTypeTest {
@Rule
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/FindResourcesTest.java b/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/FindResourcesTest.java
index 02099f4..838179c 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/FindResourcesTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/FindResourcesTest.java
@@ -36,6 +36,7 @@ import org.junit.Test;
import com.google.common.collect.ImmutableMap;
+@SuppressWarnings("null")
public class FindResourcesTest {
@Rule
@@ -44,7 +45,7 @@ public class FindResourcesTest {
@Before
public void setUp() {
Resource resource = context.create().resource(
- "test",
+ "/test",
ImmutableMap.<String, Object> builder().put("prop1", "value1")
.put("prop2", "value2").build());
Node node = resource.adaptTo(Node.class);
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java b/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
index 8caef09..8e45452 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
@@ -29,6 +29,7 @@ import org.apache.sling.api.adapter.SlingAdaptable;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.jetbrains.annotations.NotNull;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -39,6 +40,7 @@ import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
@RunWith(MockitoJUnitRunner.class)
+@SuppressWarnings("null")
public class SlingContextTest {
private final SlingContextCallback contextBeforeSetup = mock(SlingContextCallback.class);
@@ -161,7 +163,7 @@ public class SlingContextTest {
AdapterFactory adapterFactory = new AdapterFactory() {
@SuppressWarnings("unchecked")
@Override
- public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
+ public <AdapterType> AdapterType getAdapter(@NotNull Object adaptable, @NotNull Class<AdapterType> type) {
return (AdapterType)(((TestAdaptable)adaptable).getMessage() + "-initial");
}
};
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderAutoCommitTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderAutoCommitTest.java
index b0df5fd..cb14cc6 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderAutoCommitTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderAutoCommitTest.java
@@ -30,6 +30,7 @@ import org.apache.sling.testing.mock.sling.junit.SlingContext;
import org.junit.Rule;
import org.junit.Test;
+@SuppressWarnings("null")
public abstract class AbstractContentLoaderAutoCommitTest {
private static String DEST_RES_NAME = "dest";
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
index 81a2aa8..3e624b2 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
@@ -39,6 +39,7 @@ import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
+@SuppressWarnings("null")
public abstract class AbstractContentLoaderBinaryTest {
private static final int SAMPLE_IMAGE_FILESIZE = 62;
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
index a4ccb6a..ceafc03 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
@@ -44,6 +44,7 @@ import org.junit.Test;
import com.google.common.collect.ImmutableList;
+@SuppressWarnings("null")
public abstract class AbstractContentLoaderJsonDamTest {
@Rule
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
index bf5aa95..40f3319 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
@@ -44,6 +44,7 @@ import org.junit.Test;
import com.google.common.collect.ImmutableList;
+@SuppressWarnings("null")
public abstract class AbstractContentLoaderJsonTest {
@Rule
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
index 3fedcca..75e4f31 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
@@ -38,6 +38,7 @@ import org.osgi.framework.BundleContext;
/**
* Validates correct registering and mapping of JCR namespaces, esp. the sling namespace.
*/
+@SuppressWarnings("null")
public abstract class AbstractJcrNamespaceTest {
@Rule
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
index 8b6251a..8590e46 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
@@ -56,6 +56,7 @@ import com.google.common.collect.ImmutableMap;
* Implements simple write and read resource and values test.
* JCR API is used to create the test data.
*/
+@SuppressWarnings("null")
public abstract class AbstractJcrResourceResolverTest {
@Rule
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java
index cb4e6e2..cf6b167 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java
@@ -36,6 +36,7 @@ import com.google.common.collect.ImmutableMap;
/**
* Tests content access accross multiple resource resolvers.
*/
+@SuppressWarnings("null")
public abstract class AbstractMultipleResourceResolverTest {
private final BundleContext bundleContext = MockOsgi.newBundleContext();
@@ -51,6 +52,7 @@ public abstract class AbstractMultipleResourceResolverTest {
MockOsgi.shutdown(bundleContext);
}
+ @SuppressWarnings("deprecation")
@Test
public void testMultipleResourceResolver() throws Exception {
ResourceResolverFactory factory = newResourceResolerFactory();
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
index 7b0d5e7..a075908 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
@@ -56,6 +56,7 @@ import com.google.common.collect.Lists;
* Implements simple write and read resource and values test. Sling CRUD API is
* used to create the test data.
*/
+@SuppressWarnings("null")
public abstract class AbstractSlingCrudResourceResolverTest {
@Rule
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractUniqueRootTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractUniqueRootTest.java
index 0ddd658..fe2f8c2 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractUniqueRootTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractUniqueRootTest.java
@@ -26,6 +26,7 @@ import org.apache.sling.testing.mock.sling.junit.SlingContext;
import org.junit.Rule;
import org.junit.Test;
+@SuppressWarnings("null")
public abstract class AbstractUniqueRootTest {
@Rule
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/services/MockSlingSettingServiceTest.java b/src/test/java/org/apache/sling/testing/mock/sling/services/MockSlingSettingServiceTest.java
index 4a96b95..1fcdcda 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/services/MockSlingSettingServiceTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/services/MockSlingSettingServiceTest.java
@@ -29,6 +29,7 @@ import org.junit.Test;
import com.google.common.collect.ImmutableSet;
+@SuppressWarnings("null")
public class MockSlingSettingServiceTest {
@Test
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java b/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
index 0f12ed6..c5c14c2 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
@@ -46,6 +46,7 @@ import org.mockito.runners.MockitoJUnitRunner;
import org.osgi.framework.BundleContext;
@RunWith(MockitoJUnitRunner.class)
+@SuppressWarnings("null")
public class MockSlingHttpServletRequestTest {
@Mock