Merge branch 'master' into feature/SLING-7803-junit5
diff --git a/.gitignore b/.gitignore
index 12746f7..e2d791c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-/target
+target
.idea
.classpath
.metadata
diff --git a/core/pom.xml b/core/pom.xml
new file mode 100644
index 0000000..cdc223e
--- /dev/null
+++ b/core/pom.xml
@@ -0,0 +1,242 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock.parent</artifactId>
+ <version>2.4.0-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.sling.testing.osgi-mock.core</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Apache Sling Testing OSGi Mock Core</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>15.0</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.3.2</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.reflections</groupId>
+ <artifactId>reflections</artifactId>
+ <!-- Do not use version 0.9.10, it created threading issues when running junit tests in parallel (see SLING-5002) -->
+ <version>0.9.9</version>
+ <scope>compile</scope>
+ <!-- exclude all optional dependencies -->
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>annotations</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <!-- Artifact is shaded and inlined, only some classes included (see below) -->
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.osgi</artifactId>
+ <version>2.4.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <!-- Artifact is shaded and inlined, only some classes included (see below) -->
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>5.0.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <!-- Artifact is shaded and inlined, only some classes included (see below) -->
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr</artifactId>
+ <version>2.0.4</version>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>animal-sniffer-annotations</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.logging-mock</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+
+ <!-- Publish test artifact -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>src/test/resources/META-INF/test.txt</exclude>
+ <exclude>src/test/resources/bundleData/nested/first.txt</exclude>
+ <exclude>src/test/resources/bundleData/nested/second.txt</exclude>
+ <exclude>dependency-reduced-pom.xml</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <createSourcesJar>true</createSourcesJar>
+ <shadeSourcesContent>true</shadeSourcesContent>
+ <artifactSet>
+ <includes>
+ <include>org.apache.sling:org.apache.sling.commons.osgi</include>
+ <include>org.apache.felix:org.apache.felix.framework</include>
+ <include>org.apache.felix:org.apache.felix.scr</include>
+ </includes>
+ </artifactSet>
+ <relocations>
+ <relocation>
+ <pattern>org.apache.sling.commons.osgi</pattern>
+ <shadedPattern>osgimock.org.apache.sling.commons.osgi</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>org.apache.felix.framework</pattern>
+ <shadedPattern>osgimock.org.apache.felix.framework</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>org.apache.felix.scr.impl</pattern>
+ <shadedPattern>osgimock.org.apache.felix.scr.impl</shadedPattern>
+ </relocation>
+ </relocations>
+ <filters>
+ <filter>
+ <artifact>org.apache.sling:org.apache.sling.commons.osgi</artifact>
+ <includes>
+ <include>org/apache/sling/commons/osgi/ServiceUtil*</include>
+ <include>org/apache/sling/commons/osgi/Order*</include>
+ </includes>
+ </filter>
+ <filter>
+ <artifact>org.apache.felix:org.apache.felix.framework</artifact>
+ <includes>
+ <include>org/apache/felix/framework/**</include>
+ </includes>
+ </filter>
+ <filter>
+ <artifact>org.apache.felix:org.apache.felix.scr</artifact>
+ <includes>
+ <include>org/apache/felix/scr/impl/inject/Annotations*</include>
+ <include>org/apache/felix/scr/impl/helper/Coercions*</include>
+ </includes>
+ </filter>
+ </filters>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/ComponentContextBuilder.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/ComponentContextBuilder.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/ComponentContextBuilder.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/ComponentContextBuilder.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/ManifestScanner.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/ManifestScanner.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/ManifestScanner.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/ManifestScanner.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MapMergeUtil.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MapMergeUtil.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MapMergeUtil.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MapMergeUtil.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MapUtil.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MatchAllFilter.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MatchAllFilter.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MatchAllFilter.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MatchAllFilter.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockComponentContext.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockComponentContext.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MockComponentContext.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MockComponentContext.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockConfiguration.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockConfiguration.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MockConfiguration.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MockConfiguration.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdmin.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdmin.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdmin.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdmin.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockEventAdmin.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockEventAdmin.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MockEventAdmin.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MockEventAdmin.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockLogService.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockLogService.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MockLogService.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MockLogService.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceReference.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceReference.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MockServiceReference.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceReference.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/NoScrMetadataException.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/NoScrMetadataException.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/NoScrMetadataException.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/NoScrMetadataException.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
similarity index 99%
rename from src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
index 1e0b8d3..1bee861 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtil.java
@@ -254,7 +254,7 @@
* @return Cleaned up class name
*/
public static final String cleanupClassName(String className) {
- return StringUtils.substringBefore(className, "$$Enhancer");
+ return StringUtils.substringBefore(StringUtils.substringBefore(className, "$MockitoMock$"), "$$Enhancer");
}
private static String getComponentName(Class clazz, Document metadata) {
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtil.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtil.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtil.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtil.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/ReferenceViolationException.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/ReferenceViolationException.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/ReferenceViolationException.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/ReferenceViolationException.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/AbstractContextPlugin.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/context/AbstractContextPlugin.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/context/AbstractContextPlugin.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/context/AbstractContextPlugin.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextCallback.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextCallback.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/context/ContextCallback.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextCallback.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugin.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugin.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugin.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugin.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/package-info.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/context/package-info.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/context/package-info.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/context/package-info.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
rename to core/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/ManifestScannerTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/ManifestScannerTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/ManifestScannerTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/ManifestScannerTest.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MapUtilTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MapUtilTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MapUtilTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MapUtilTest.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesOsgiR6Test.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesOsgiR6Test.java
similarity index 99%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesOsgiR6Test.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesOsgiR6Test.java
index 9de52ce..a23fd9a 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesOsgiR6Test.java
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesOsgiR6Test.java
@@ -32,7 +32,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesTest.java
similarity index 99%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesTest.java
index 4fcd531..5437e23 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesTest.java
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferencesTest.java
@@ -32,7 +32,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextStaticGreedyReferencesTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextStaticGreedyReferencesTest.java
similarity index 99%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextStaticGreedyReferencesTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextStaticGreedyReferencesTest.java
index a78ad3c..503b0c4 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextStaticGreedyReferencesTest.java
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextStaticGreedyReferencesTest.java
@@ -32,7 +32,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
similarity index 99%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
index 0359040..dc425b0 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
@@ -25,7 +25,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -38,7 +38,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockComponentContextTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockComponentContextTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MockComponentContextTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MockComponentContextTest.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdminTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdminTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdminTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MockConfigurationAdminTest.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockEventAdminTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockEventAdminTest.java
similarity index 91%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MockEventAdminTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MockEventAdminTest.java
index e8004d0..9e1ca1d 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/MockEventAdminTest.java
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockEventAdminTest.java
@@ -23,8 +23,8 @@
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.List;
+import java.util.Objects;
-import org.apache.commons.lang3.ObjectUtils;
import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
import org.junit.Before;
import org.junit.Rule;
@@ -110,10 +110,10 @@
// wait until result is as expected (with timeout)
boolean expectedResult = false;
while (!expectedResult) {
- expectedResult = ObjectUtils.equals(ImmutableList.of(), eventHandler1.getReceivedEvents())
- && ObjectUtils.equals(ImmutableList.of(EVENT_SAMPLE_2), eventHandler12.getReceivedEvents())
- && ObjectUtils.equals(ImmutableList.of(EVENT_SAMPLE_2), eventHandlerSampleAll.getReceivedEvents())
- && ObjectUtils.equals(ImmutableList.of(EVENT_SAMPLE_2, EVENT_OTHER_3), eventHandlerAll.getReceivedEvents());
+ expectedResult = Objects.equals(ImmutableList.of(), eventHandler1.getReceivedEvents())
+ && Objects.equals(ImmutableList.of(EVENT_SAMPLE_2), eventHandler12.getReceivedEvents())
+ && Objects.equals(ImmutableList.of(EVENT_SAMPLE_2), eventHandlerSampleAll.getReceivedEvents())
+ && Objects.equals(ImmutableList.of(EVENT_SAMPLE_2, EVENT_OTHER_3), eventHandlerAll.getReceivedEvents());
}
}
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockLogServiceTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockLogServiceTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MockLogServiceTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MockLogServiceTest.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferenceTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferenceTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferenceTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferenceTest.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferencesSortTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferencesSortTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferencesSortTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/MockServiceReferencesSortTest.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtilTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtilTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtilTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/OsgiMetadataUtilTest.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilActivateDeactivateTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilActivateDeactivateTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilActivateDeactivateTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilActivateDeactivateTest.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java
similarity index 98%
rename from src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java
index 1a97478..e3983fb 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/context/ContextPluginsTest.java
@@ -27,7 +27,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
@SuppressWarnings({"unchecked","null"})
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
similarity index 100%
rename from src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
rename to core/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
diff --git a/core/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java
new file mode 100644
index 0000000..f6a25b2
--- /dev/null
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.osgi.junit;
+
+import org.apache.sling.testing.mock.osgi.context.ContextCallback;
+import org.apache.sling.testing.mock.osgi.context.ContextPlugins;
+import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
+import org.jetbrains.annotations.NotNull;
+import org.junit.rules.ExternalResource;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+import org.osgi.annotation.versioning.ProviderType;
+
+/*
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * PLEASE NOTE: this file is copied from osgi-mock.junit4 project to ease the unit tests in the core project.
+ * If you need change it in osgi-mock.junit4, please update it her as well (and vice versa).
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ */
+
+/**
+ * JUnit rule for setting up and tearing down OSGi context for unit tests.
+ */
+@ProviderType
+public final class OsgiContext extends OsgiContextImpl implements TestRule {
+
+ private final ContextPlugins plugins;
+ private final TestRule delegate;
+
+ /**
+ * Initialize OSGi context.
+ */
+ public OsgiContext() {
+ this(new ContextPlugins());
+ }
+
+ /**
+ * Initialize OSGi context.
+ * @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> OsgiContext(@NotNull final ContextCallback<T> afterSetUpCallback) {
+ this(new ContextPlugins(afterSetUpCallback));
+ }
+
+ /**
+ * Initialize OSGi context.
+ * @param <U> context type
+ * @param <V> context type
+ * @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> OsgiContext(@NotNull final ContextCallback<U> afterSetUpCallback, @NotNull final ContextCallback<V> beforeTearDownCallback) {
+ this(new ContextPlugins(afterSetUpCallback, beforeTearDownCallback));
+ }
+
+ /**
+ * Initialize OSGi context with resource resolver type.
+ * @param contextPlugins Context plugins
+ */
+ OsgiContext(@NotNull final ContextPlugins contextPlugins) {
+ this.plugins = contextPlugins;
+
+ // wrap {@link ExternalResource} rule executes each test method once
+ this.delegate = new ExternalResource() {
+ @Override
+ protected void before() {
+ plugins.executeBeforeSetUpCallback(OsgiContext.this);
+ OsgiContext.this.setUp();
+ plugins.executeAfterSetUpCallback(OsgiContext.this);
+ }
+
+ @Override
+ protected void after() {
+ plugins.executeBeforeTearDownCallback(OsgiContext.this);
+ OsgiContext.this.tearDown();
+ plugins.executeAfterTearDownCallback(OsgiContext.this);
+ }
+ };
+ }
+
+ @Override
+ public Statement apply(final Statement base, final Description description) {
+ return this.delegate.apply(base, description);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
similarity index 90%
copy from src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
copy to core/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
index 81bd569..ea29c87 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
@@ -25,6 +25,13 @@
import org.apache.sling.testing.mock.osgi.context.ContextPlugin;
import org.osgi.annotation.versioning.ProviderType;
+/*
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * PLEASE NOTE: this file is copied from osgi-mock.junit4 project to ease the unit tests in the core project.
+ * If you need change it in osgi-mock.junit4, please update it her as well (and vice versa).
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ */
+
/**
* Builder class for creating {@link OsgiContext} instances with different sets of parameters.
*/
diff --git a/core/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
new file mode 100644
index 0000000..c37a583
--- /dev/null
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.osgi.junit;
+
+import org.apache.sling.testing.mock.osgi.context.ContextCallback;
+import org.osgi.annotation.versioning.ConsumerType;
+
+/*
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * PLEASE NOTE: this file is copied from osgi-mock.junit4 project to ease the unit tests in the core project.
+ * If you need change it in osgi-mock.junit4, please update it her as well (and vice versa).
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ */
+
+/**
+ * Callback interface for application-specific setup and teardown operations to
+ * customize the {@link OsgiContext} JUnit rule.
+ */
+@ConsumerType
+public interface OsgiContextCallback extends ContextCallback<OsgiContext> {
+
+ // specialized version of ContextCallback
+
+}
diff --git a/src/test/resources/META-INF/test.txt b/core/src/test/resources/META-INF/test.txt
similarity index 100%
rename from src/test/resources/META-INF/test.txt
rename to core/src/test/resources/META-INF/test.txt
diff --git a/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.OsgiServiceUtilActivateDeactivateTest.xml b/core/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.OsgiServiceUtilActivateDeactivateTest.xml
similarity index 100%
rename from src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.OsgiServiceUtilActivateDeactivateTest.xml
rename to core/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.OsgiServiceUtilActivateDeactivateTest.xml
diff --git a/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.OsgiServiceUtilTest.xml b/core/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.OsgiServiceUtilTest.xml
similarity index 100%
rename from src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.OsgiServiceUtilTest.xml
rename to core/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.OsgiServiceUtilTest.xml
diff --git a/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.context.OsgiContextImplTest.xml b/core/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.context.OsgiContextImplTest.xml
similarity index 100%
rename from src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.context.OsgiContextImplTest.xml
rename to core/src/test/resources/OSGI-INF/org.apache.sling.testing.mock.osgi.context.OsgiContextImplTest.xml
diff --git a/src/test/resources/OSGI-INF/serviceComponents.xml b/core/src/test/resources/OSGI-INF/serviceComponents.xml
similarity index 100%
rename from src/test/resources/OSGI-INF/serviceComponents.xml
rename to core/src/test/resources/OSGI-INF/serviceComponents.xml
diff --git a/src/test/resources/bundleData/nested/first.txt b/core/src/test/resources/bundleData/nested/first.txt
similarity index 100%
rename from src/test/resources/bundleData/nested/first.txt
rename to core/src/test/resources/bundleData/nested/first.txt
diff --git a/src/test/resources/bundleData/nested/second.txt b/core/src/test/resources/bundleData/nested/second.txt
similarity index 100%
rename from src/test/resources/bundleData/nested/second.txt
rename to core/src/test/resources/bundleData/nested/second.txt
diff --git a/src/test/resources/simplelogger.properties b/core/src/test/resources/simplelogger.properties
similarity index 100%
rename from src/test/resources/simplelogger.properties
rename to core/src/test/resources/simplelogger.properties
diff --git a/junit4/pom.xml b/junit4/pom.xml
new file mode 100644
index 0000000..008a108
--- /dev/null
+++ b/junit4/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock.parent</artifactId>
+ <version>2.4.0-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.sling.testing.osgi-mock.junit4</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Apache Sling Testing OSGi Mock JUnit 4</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock.core</artifactId>
+ <version>2.4.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock.core</artifactId>
+ <version>2.4.0-SNAPSHOT</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.logging-mock</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java b/junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java
rename to junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContext.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java b/junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
similarity index 98%
rename from src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
rename to junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
index 81bd569..cdd293e 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
+++ b/junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
@@ -34,7 +34,7 @@
private final @NotNull ContextPlugins plugins = new ContextPlugins();
/**
- * Create builder with default resource resolver type.
+ * Create builder.
*/
public OsgiContextBuilder() {}
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java b/junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
rename to junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextCallback.java
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/package-info.java b/junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/package-info.java
similarity index 100%
rename from src/main/java/org/apache/sling/testing/mock/osgi/junit/package-info.java
rename to junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/package-info.java
diff --git a/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextTest.java b/junit4/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextTest.java
similarity index 97%
rename from src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextTest.java
rename to junit4/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextTest.java
index e374516..9c6c401 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextTest.java
+++ b/junit4/src/test/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextTest.java
@@ -26,7 +26,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
@SuppressWarnings("null")
diff --git a/junit5/pom.xml b/junit5/pom.xml
new file mode 100644
index 0000000..c6989ad
--- /dev/null
+++ b/junit5/pom.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock.parent</artifactId>
+ <version>2.4.0-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.sling.testing.osgi-mock.junit5</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Apache Sling Testing OSGi Mock JUnit 5</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock.core</artifactId>
+ <version>2.4.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock.core</artifactId>
+ <version>2.4.0-SNAPSHOT</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.logging-mock</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- JUnit 5 -->
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.vintage</groupId>
+ <artifactId>junit-vintage-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <dependencyManagement>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>junit-bom</artifactId>
+ <version>5.2.0</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
diff --git a/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContext.java b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContext.java
new file mode 100644
index 0000000..f57ddaa
--- /dev/null
+++ b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContext.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.osgi.junit5;
+
+import org.apache.sling.testing.mock.osgi.context.ContextPlugins;
+import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
+import org.jetbrains.annotations.NotNull;
+import org.osgi.annotation.versioning.ConsumerType;
+
+/**
+ * OSGi Mock parameter object.
+ * <p>
+ * Additionally you can subclass this class and provide further parameters via
+ * {@link OsgiContextBuilder}.
+ * </p>
+ */
+@ConsumerType
+public final class OsgiContext extends OsgiContextImpl {
+
+ private final ContextPlugins plugins;
+ private boolean isSetUp;
+
+ /**
+ * Initialize OSGi context.
+ */
+ public OsgiContext() {
+ this(new ContextPlugins());
+ }
+
+ /**
+ * Initialize OSGi context.
+ * @param contextPlugins Context plugins
+ */
+ OsgiContext(@NotNull final ContextPlugins contextPlugins) {
+ this.plugins = contextPlugins;
+ }
+
+ /**
+ * This is called by {@link OsgiContextExtension} to set up context.
+ */
+ protected void setUpContext() {
+ isSetUp = true;
+ plugins.executeBeforeSetUpCallback(this);
+ super.setUp();
+ }
+
+ /**
+ * This is called by {@link OsgiContextExtension} to tear down context.
+ */
+ protected void tearDownContext() {
+ super.tearDown();
+ }
+
+ ContextPlugins getContextPlugins() {
+ return plugins;
+ }
+
+ boolean isSetUp() {
+ return this.isSetUp;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextBuilder.java
similarity index 66%
copy from src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
copy to junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextBuilder.java
index 81bd569..8a90f81 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
+++ b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextBuilder.java
@@ -16,79 +16,88 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.testing.mock.osgi.junit;
+package org.apache.sling.testing.mock.osgi.junit5;
+import org.apache.sling.testing.mock.osgi.context.ContextCallback;
+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.jetbrains.annotations.NotNull;
-import org.apache.sling.testing.mock.osgi.context.ContextCallback;
-import org.apache.sling.testing.mock.osgi.context.ContextPlugin;
import org.osgi.annotation.versioning.ProviderType;
/**
- * Builder class for creating {@link OsgiContext} instances with different sets of parameters.
+ * Builder class for creating {@link OsgiContext} instances with different sets
+ * of parameters.
*/
@ProviderType
public final class OsgiContextBuilder {
-
+
private final @NotNull ContextPlugins plugins = new ContextPlugins();
-
+
/**
- * Create builder with default resource resolver type.
+ * Create builder.
*/
public OsgiContextBuilder() {}
-
+
/**
* @param <T> context type
* @param plugin Context plugin which listens to context lifecycle events.
* @return this
*/
@SafeVarargs
- public final @NotNull <T extends OsgiContextImpl> OsgiContextBuilder plugin(@NotNull ContextPlugin<T> @NotNull ... plugin) {
+ public final <T extends OsgiContextImpl> OsgiContextBuilder plugin(@NotNull ContextPlugin<T> @NotNull ... plugin) {
plugins.addPlugin(plugin);
return this;
}
/**
* @param <T> context type
- * @param beforeSetUpCallback Allows the application to register an own callback function that is called before the built-in setup rules are executed.
+ * @param beforeSetUpCallback Allows the application to register an own
+ * callback function that is called before the built-in setup
+ * rules are executed.
* @return this
*/
@SafeVarargs
- public final @NotNull <T extends OsgiContextImpl> OsgiContextBuilder beforeSetUp(@NotNull ContextCallback<T> @NotNull ... beforeSetUpCallback) {
+ public final <T extends OsgiContextImpl> OsgiContextBuilder beforeSetUp(@NotNull ContextCallback<T> @NotNull ... beforeSetUpCallback) {
plugins.addBeforeSetUpCallback(beforeSetUpCallback);
return this;
}
/**
* @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.
+ * @param afterSetUpCallback Allows the application to register an own
+ * callback function that is called after the built-in setup
+ * rules are executed.
* @return this
*/
@SafeVarargs
- public final @NotNull <T extends OsgiContextImpl> OsgiContextBuilder afterSetUp(@NotNull ContextCallback<T> @NotNull ... afterSetUpCallback) {
+ public final <T extends OsgiContextImpl> OsgiContextBuilder afterSetUp(@NotNull ContextCallback<T> @NotNull ... afterSetUpCallback) {
plugins.addAfterSetUpCallback(afterSetUpCallback);
return this;
}
/**
* @param <T> context type
- * @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown 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.
* @return this
*/
@SafeVarargs
- public final @NotNull <T extends OsgiContextImpl> OsgiContextBuilder beforeTearDown(@NotNull ContextCallback<T> @NotNull ... beforeTearDownCallback) {
+ public final <T extends OsgiContextImpl> OsgiContextBuilder beforeTearDown(@NotNull ContextCallback<T> @NotNull ... beforeTearDownCallback) {
plugins.addBeforeTearDownCallback(beforeTearDownCallback);
return this;
}
/**
* @param <T> context type
- * @param afterTearDownCallback Allows the application to register an own callback function that is after before the built-in teardown rules are executed.
+ * @param afterTearDownCallback Allows the application to register an own
+ * callback function that is after before the built-in teardown
+ * rules are executed.
* @return this
*/
@SafeVarargs
- public final @NotNull <T extends OsgiContextImpl> OsgiContextBuilder afterTearDown(@NotNull ContextCallback<T> @NotNull ... afterTearDownCallback) {
+ public final <T extends OsgiContextImpl> OsgiContextBuilder afterTearDown(@NotNull ContextCallback<T> @NotNull ... afterTearDownCallback) {
plugins.addAfterTearDownCallback(afterTearDownCallback);
return this;
}
@@ -97,7 +106,7 @@
* @return Build {@link OsgiContext} instance.
*/
public @NotNull OsgiContext build() {
- return new OsgiContext(plugins);
+ return new OsgiContext(this.plugins);
}
-
+
}
diff --git a/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextCallback.java b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextCallback.java
new file mode 100644
index 0000000..afe42a9
--- /dev/null
+++ b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextCallback.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.osgi.junit5;
+
+import org.apache.sling.testing.mock.osgi.context.ContextCallback;
+import org.osgi.annotation.versioning.ConsumerType;
+
+/**
+ * Callback interface for application-specific setup and teardown operations to
+ * customize the {@link OsgiContext} JUnit parameter context.
+ */
+@ConsumerType
+public interface OsgiContextCallback extends ContextCallback<OsgiContext> {
+
+ // specialized version of ContextCallback
+
+}
diff --git a/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextExtension.java b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextExtension.java
new file mode 100644
index 0000000..608238f
--- /dev/null
+++ b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextExtension.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.osgi.junit5;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.function.Consumer;
+
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolver;
+import org.junit.jupiter.api.extension.TestInstancePostProcessor;
+
+/**
+ * JUnit 5 extension that allows to inject {@link OsgiContext} (or subclasses of
+ * it) parameters in test methods, and ensures that the context is set up and
+ * teared down properly for each test method.
+ */
+public final class OsgiContextExtension implements ParameterResolver, TestInstancePostProcessor, BeforeEachCallback,
+ AfterEachCallback, AfterTestExecutionCallback {
+
+ /**
+ * Checks if test class has a {@link OsgiContext} or derived field. If it has
+ * and is not instantiated, create an new {@link OsgiContext} and store it in
+ * the field. If it is already instantiated reuse this instance and use it
+ * for all test methods.
+ */
+ @Override
+ public void postProcessTestInstance(Object testInstance, ExtensionContext extensionContext) throws Exception {
+ Field osgiContextField = getFieldFromTestInstance(testInstance, OsgiContext.class);
+ if (osgiContextField != null) {
+ OsgiContext context = (OsgiContext)osgiContextField.get(testInstance);
+ if (context != null) {
+ if (!context.isSetUp()) {
+ context.setUpContext();
+ }
+ OsgiContextStore.storeOsgiContext(extensionContext, testInstance, context);
+ } else {
+ context = OsgiContextStore.getOrCreateOsgiContext(extensionContext, testInstance);
+ osgiContextField.set(testInstance, context);
+ }
+ }
+ }
+
+ /**
+ * Support parameter injection for test methods of parameter type is derived from {@link OsgiContext}.
+ */
+ @Override
+ public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
+ return OsgiContext.class.isAssignableFrom(parameterContext.getParameter().getType());
+ }
+
+ /**
+ * Resolve (or create) {@link OsgiContext} instance for test method parameter.
+ */
+ @Override
+ public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
+ return OsgiContextStore.getOrCreateOsgiContext(extensionContext, extensionContext.getRequiredTestInstance());
+ }
+
+ @Override
+ public void beforeEach(ExtensionContext extensionContext) throws Exception {
+ applyOsgiContext(extensionContext, osgiContext -> {
+ // call context plugins setup after all @BeforeEach methods were called
+ osgiContext.getContextPlugins().executeAfterSetUpCallback(osgiContext);
+ });
+ }
+
+ @Override
+ public void afterTestExecution(ExtensionContext extensionContext) throws Exception {
+ applyOsgiContext(extensionContext, osgiContext -> {
+ // call context plugins setup before any @AfterEach method is called
+ osgiContext.getContextPlugins().executeBeforeTearDownCallback(osgiContext);
+ });
+ }
+
+ @Override
+ public void afterEach(ExtensionContext extensionContext) {
+ applyOsgiContext(extensionContext, osgiContext -> {
+ // call context plugins setup after all @AfterEach methods were called
+ osgiContext.getContextPlugins().executeAfterTearDownCallback(osgiContext);
+
+ // Tear down {@link OsgiContext} after test is complete.
+ osgiContext.tearDownContext();
+ OsgiContextStore.removeOsgiContext(extensionContext, extensionContext.getRequiredTestInstance());
+ });
+ }
+
+ private void applyOsgiContext(ExtensionContext extensionContext, Consumer<OsgiContext> consumer) {
+ OsgiContext osgiContext = OsgiContextStore.getOsgiContext(extensionContext,
+ extensionContext.getRequiredTestInstance());
+ if (osgiContext != null) {
+ consumer.accept(osgiContext);
+ }
+ }
+
+ private Field getFieldFromTestInstance(Object testInstance, Class<?> type) {
+ Field contextField = Arrays.stream(testInstance.getClass().getDeclaredFields())
+ .filter(field -> type.isAssignableFrom(field.getType())).findFirst().orElse(null);
+ if (contextField != null) {
+ contextField.setAccessible(true);
+ }
+ return contextField;
+ }
+
+}
diff --git a/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextStore.java b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextStore.java
new file mode 100644
index 0000000..f7f31d3
--- /dev/null
+++ b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextStore.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.osgi.junit5;
+
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
+import org.junit.jupiter.api.extension.ExtensionContext.Store;
+
+/**
+ * Helper class managing storage of {@link OsgiContext} in extension context
+ * store.
+ */
+final class OsgiContextStore {
+
+ private static final Namespace OSGi_CONTEXT_NAMESPACE = Namespace.create(OsgiContextExtension.class);
+
+ private OsgiContextStore() {
+ // static methods only
+ }
+
+ /**
+ * Get {@link OsgiContext} from extension context store.
+ * @param extensionContext Extension context
+ * @param testInstance Test instance
+ * @return OsgiContext or null
+ */
+ public static OsgiContext getOsgiContext(ExtensionContext extensionContext, Object testInstance) {
+ return getStore(extensionContext).get(testInstance, OsgiContext.class);
+ }
+
+ /**
+ * Get {@link OsgiContext} from extension context store - if it does not
+ * exist create a new one and store it.
+ * @param extensionContext Extension context
+ * @param testInstance Test instance
+ * @return OsgiContext (never null)
+ */
+ public static OsgiContext getOrCreateOsgiContext(ExtensionContext extensionContext, Object testInstance) {
+ OsgiContext context = getOsgiContext(extensionContext, testInstance);
+ if (context == null) {
+ context = createOsgiContext(extensionContext);
+ storeOsgiContext(extensionContext, testInstance, context);
+ }
+ return context;
+ }
+
+ /**
+ * Removes {@link OsgiContext} from extension context store (if it exists).
+ * @param extensionContext Extension context
+ * @param testInstance Test instance
+ */
+ public static void removeOsgiContext(ExtensionContext extensionContext, Object testInstance) {
+ getStore(extensionContext).remove(testInstance);
+ }
+
+ /**
+ * Store {@link OsgiContext} in extension context store.
+ * @param extensionContext Extension context
+ * @param testInstance Test instance
+ * @param osgiContext OSGi context
+ */
+ public static void storeOsgiContext(ExtensionContext extensionContext, Object testInstance, OsgiContext osgiContext) {
+ getStore(extensionContext).put(testInstance, osgiContext);
+ }
+
+ private static Store getStore(ExtensionContext context) {
+ return context.getStore(OSGi_CONTEXT_NAMESPACE);
+ }
+
+ private static OsgiContext createOsgiContext(ExtensionContext extensionContext) {
+ OsgiContext osgiContext = new OsgiContext();
+ osgiContext.setUpContext();
+ return osgiContext;
+ }
+
+}
diff --git a/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/package-info.java b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/package-info.java
new file mode 100644
index 0000000..7cb00c7
--- /dev/null
+++ b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * JUnit 5 extensions for OSGi context.
+ */
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.sling.testing.mock.osgi.junit5;
diff --git a/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextMemberInstantiatedTest.java b/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextMemberInstantiatedTest.java
new file mode 100644
index 0000000..07a98b2
--- /dev/null
+++ b/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextMemberInstantiatedTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.osgi.junit5;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Test with {@link OsgiContext} as class member variable already instantiated.
+ */
+@ExtendWith(OsgiContextExtension.class)
+class OsgiContextMemberInstantiatedTest {
+
+ OsgiContext context = new OsgiContext();
+
+ @Test
+ void testSimpleService() {
+ context.registerInjectActivateService(new Integer(5));
+
+ Integer service = context.getService(Integer.class);
+ assertEquals((Integer)5, service);
+ }
+
+}
diff --git a/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextMemberTest.java b/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextMemberTest.java
new file mode 100644
index 0000000..e1cf9c1
--- /dev/null
+++ b/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextMemberTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.osgi.junit5;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Test with {@link OsgiContext} as class member variable.
+ */
+@ExtendWith(OsgiContextExtension.class)
+class OsgiContextMemberTest {
+
+ OsgiContext context;
+
+ @Test
+ void testSimpleService() {
+ context.registerInjectActivateService(new Integer(5));
+
+ Integer service = context.getService(Integer.class);
+ assertEquals((Integer)5, service);
+ }
+
+}
diff --git a/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextPluginTest.java b/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextPluginTest.java
new file mode 100644
index 0000000..111d6d6
--- /dev/null
+++ b/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextPluginTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.osgi.junit5;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.jetbrains.annotations.NotNull;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Test with {@link OsgiContext} with context plugins.
+ */
+@ExtendWith(OsgiContextExtension.class)
+class OsgiContextPluginTest {
+
+ private final @NotNull OsgiContextCallback contextBeforeSetup = mock(OsgiContextCallback.class);
+ private final @NotNull OsgiContextCallback contextAfterSetup = mock(OsgiContextCallback.class);
+ private final @NotNull OsgiContextCallback contextBeforeTeardown = mock(OsgiContextCallback.class);
+ private final @NotNull OsgiContextCallback contextAfterTeardown = mock(OsgiContextCallback.class);
+
+ private final @NotNull OsgiContext context = new OsgiContextBuilder()
+ .beforeSetUp(contextBeforeSetup)
+ .afterSetUp(contextAfterSetup)
+ .beforeTearDown(contextBeforeTeardown)
+ .afterTearDown(contextAfterTeardown)
+ .build();
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ verify(contextBeforeSetup).execute(context);
+ }
+
+ @Test
+ public void testRequest() throws Exception {
+ verify(contextAfterSetup).execute(context);
+ }
+
+ @Test
+ public void testResourceResolverFactoryActivatorProps() throws Exception {
+ verify(contextAfterSetup).execute(context);
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception {
+ verify(contextBeforeTeardown).execute(context);
+ }
+
+}
diff --git a/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextTest.java b/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextTest.java
new file mode 100644
index 0000000..40785f5
--- /dev/null
+++ b/junit5/src/test/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.osgi.junit5;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Test with {@link OsgiContext} as test method parameter.
+ */
+@ExtendWith(OsgiContextExtension.class)
+class OsgiContextTest {
+
+ @Test
+ void testSimpleService(OsgiContext context) {
+ context.registerInjectActivateService(new Integer(5));
+
+ Integer service = context.getService(Integer.class);
+ assertEquals((Integer)5, service);
+ }
+
+}
diff --git a/parent/pom.xml b/parent/pom.xml
new file mode 100644
index 0000000..ea8ce05
--- /dev/null
+++ b/parent/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>34</version>
+ <relativePath />
+ </parent>
+
+ <artifactId>org.apache.sling.testing.osgi-mock.parent</artifactId>
+ <version>2.4.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <name>Apache Sling Testing OSGi Mock Parent</name>
+ <description>Mock implementation of selected OSGi APIs.</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.annotation.versioning</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.cmpn</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Nullability annotations -->
+ <dependency>
+ <groupId>org.jetbrains</groupId>
+ <artifactId>annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ </dependencies>
+
+ <dependencyManagement>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.21.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.logging-mock</artifactId>
+ <version>2.0.0</version>
+ </dependency>
+
+ </dependencies>
+ </dependencyManagement>
+
+</project>
diff --git a/pom.xml b/pom.xml
index 33cd699..fe86d43 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,243 +22,29 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>34</version>
- <relativePath />
+ <artifactId>org.apache.sling.testing.osgi-mock.parent</artifactId>
+ <version>2.4.0-SNAPSHOT</version>
+ <relativePath>parent/pom.xml</relativePath>
</parent>
- <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
- <version>2.3.11-SNAPSHOT</version>
- <packaging>bundle</packaging>
+ <artifactId>org.apache.sling.testing.osgi-mock.root</artifactId>
+ <packaging>pom</packaging>
<name>Apache Sling Testing OSGi Mock</name>
- <description>Mock implementation of selected OSGi APIs.</description>
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git</developerConnection>
<url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-testing-osgi-mock.git</url>
- <tag>HEAD</tag>
- </scm>
+ <tag>HEAD</tag>
+ </scm>
- <dependencies>
-
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.annotation.versioning</artifactId>
- <scope>provided</scope>
- </dependency>
+ <modules>
+ <module>parent</module>
+ <module>core</module>
+ <module>junit4</module>
+ <module>junit5</module>
+ <module>relocate</module>
+ </modules>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.core</artifactId>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.cmpn</artifactId>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>15.0</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.0.1</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.4</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.reflections</groupId>
- <artifactId>reflections</artifactId>
- <!-- Do not use version 0.9.10, it created threading issues when running junit tests in parallel (see SLING-5002) -->
- <version>0.9.9</version>
- <scope>compile</scope>
- <!-- exclude all optional dependencies -->
- <exclusions>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>dom4j</groupId>
- <artifactId>dom4j</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.google.code.findbugs</groupId>
- <artifactId>annotations</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <!-- Artifact is shaded and inlined, only some classes included (see below) -->
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.osgi</artifactId>
- <version>2.4.0</version>
- <scope>compile</scope>
- </dependency>
- <!-- Artifact is shaded and inlined, only some classes included (see below) -->
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.framework</artifactId>
- <version>5.0.0</version>
- <scope>compile</scope>
- </dependency>
- <!-- Artifact is shaded and inlined, only some classes included (see below) -->
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.scr</artifactId>
- <version>2.0.4</version>
- <scope>compile</scope>
- <exclusions>
- <exclusion>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>animal-sniffer-annotations</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <!-- Nullability annotations -->
- <dependency>
- <groupId>org.jetbrains</groupId>
- <artifactId>annotations</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <version>1.9.5</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.testing.logging-mock</artifactId>
- <version>2.0.0</version>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-
- <build>
- <plugins>
-
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- </plugin>
-
- <plugin>
- <groupId>org.apache.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <configuration>
- <excludes>
- <exclude>src/test/resources/META-INF/test.txt</exclude>
- <exclude>src/test/resources/bundleData/nested/first.txt</exclude>
- <exclude>src/test/resources/bundleData/nested/second.txt</exclude>
- <exclude>dependency-reduced-pom.xml</exclude>
- </excludes>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <createSourcesJar>true</createSourcesJar>
- <shadeSourcesContent>true</shadeSourcesContent>
- <artifactSet>
- <includes>
- <include>org.apache.sling:org.apache.sling.commons.osgi</include>
- <include>org.apache.felix:org.apache.felix.framework</include>
- <include>org.apache.felix:org.apache.felix.scr</include>
- </includes>
- </artifactSet>
- <relocations>
- <relocation>
- <pattern>org.apache.sling.commons.osgi</pattern>
- <shadedPattern>osgimock.org.apache.sling.commons.osgi</shadedPattern>
- </relocation>
- <relocation>
- <pattern>org.apache.felix.framework</pattern>
- <shadedPattern>osgimock.org.apache.felix.framework</shadedPattern>
- </relocation>
- <relocation>
- <pattern>org.apache.felix.scr.impl</pattern>
- <shadedPattern>osgimock.org.apache.felix.scr.impl</shadedPattern>
- </relocation>
- </relocations>
- <filters>
- <filter>
- <artifact>org.apache.sling:org.apache.sling.commons.osgi</artifact>
- <includes>
- <include>org/apache/sling/commons/osgi/ServiceUtil*</include>
- <include>org/apache/sling/commons/osgi/Order*</include>
- </includes>
- </filter>
- <filter>
- <artifact>org.apache.felix:org.apache.felix.framework</artifact>
- <includes>
- <include>org/apache/felix/framework/**</include>
- </includes>
- </filter>
- <filter>
- <artifact>org.apache.felix:org.apache.felix.scr</artifact>
- <includes>
- <include>org/apache/felix/scr/impl/inject/Annotations*</include>
- <include>org/apache/felix/scr/impl/helper/Coercions*</include>
- </includes>
- </filter>
- </filters>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
- </plugins>
- </build>
-
</project>
diff --git a/relocate/pom.xml b/relocate/pom.xml
new file mode 100644
index 0000000..9d7b006
--- /dev/null
+++ b/relocate/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock.parent</artifactId>
+ <version>2.4.0-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
+ <packaging>pom</packaging>
+
+ <name>Apache Sling Testing OSGi Mock Relocation</name>
+ <description>Please use artifact 'org.apache.sling.testing.osgi-mock.junit4' instead.</description>
+
+ <distributionManagement>
+ <relocation>
+ <artifactId>org.apache.sling.testing.osgi-mock.junit4</artifactId>
+ </relocation>
+ </distributionManagement>
+
+</project>