diff --git a/pom.xml b/pom.xml
index 2e345f0..7b7665b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,24 +5,28 @@
org.codehaus.plexus
plexus
- 23
+ 24
plexus-testing
- 1.6.0
+ 1.7.0
Plexus Testing
+ Library to help testing plexus components
+ https://codehaus-plexus.github.io/plexus-testing/
scm:git:https://github.com/codehaus-plexus/plexus-testing.git
${project.scm.connection}
- plexus-testing-1.6.0
+ plexus-testing-1.7.0
https://github.com/codehaus-plexus/plexus-testing
+
github
https://github.com/codehaus-plexus/plexus-testing/issues
+
github:gh-pages
@@ -32,21 +36,17 @@
0.9.0.M4
- 2025-08-18T20:50:39Z
+ 2025-10-14T21:16:46Z
-
-
-
- com.google.guava
- guava
-
- 33.4.8-jre
-
-
-
-
+
+
+ com.google.guava
+ guava
+
+ 33.5.0-jre
+
org.eclipse.sisu
org.eclipse.sisu.plexus
@@ -72,6 +72,41 @@
org.junit.jupiter
junit-jupiter-api
+
+
+ org.mockito
+ mockito-core
+ 4.11.0
+ test
+
+
+ org.mockito
+ mockito-junit-jupiter
+ 4.11.0
+ test
+
+
+
+
+ org.apache.maven.plugins
+ maven-scm-publish-plugin
+
+ ${project.reporting.outputDirectory}
+
+
+
+
+ scm-publish
+
+
+ publish-scm
+
+ site-deploy
+
+
+
+
+
diff --git a/src/main/java/org/codehaus/plexus/testing/PlexusExtension.java b/src/main/java/org/codehaus/plexus/testing/PlexusExtension.java
index b344041..df2ffb9 100644
--- a/src/main/java/org/codehaus/plexus/testing/PlexusExtension.java
+++ b/src/main/java/org/codehaus/plexus/testing/PlexusExtension.java
@@ -58,7 +58,7 @@
* This is a slightly modified version of the original plexus class
* available at https://raw.githubusercontent.com/codehaus-plexus/plexus-containers/master/plexus-container-default/
* src/main/java/org/codehaus/plexus/PlexusTestCase.java
- * in order to migrate the tests to JUnit 4.
+ * in order to migrate the tests to JUnit 5.
*
* @author Jason van Zyl
* @author Trygve Laugstøl
@@ -71,6 +71,11 @@ public class PlexusExtension implements BeforeEachCallback, AfterEachCallback {
private static String basedir;
+ /**
+ * The base directory for the test instance
+ */
+ private String testBasedir;
+
static {
if (System.getProperty("guice_custom_class_loading", "").trim().isEmpty()) {
System.setProperty("guice_custom_class_loading", "CHILD");
@@ -79,7 +84,6 @@ public class PlexusExtension implements BeforeEachCallback, AfterEachCallback {
@Override
public void beforeEach(ExtensionContext context) throws Exception {
- basedir = getBasedir();
setContext(context);
@@ -94,7 +98,6 @@ protected void setContext(ExtensionContext context) {
this.context = context;
}
- @SuppressWarnings("ResultOfMethodCallIgnored")
protected void setupContainer() {
// ----------------------------------------------------------------------------
// Context Setup
@@ -102,7 +105,7 @@ protected void setupContainer() {
DefaultContext context = new DefaultContext();
- context.put("basedir", getBasedir());
+ context.put("basedir", getTestBasedir());
customizeContext(context);
@@ -136,12 +139,14 @@ protected void setupContainer() {
}
customizeContainerConfiguration(containerConfiguration);
+ testInstanceCustomizeContainerConfiguration(containerConfiguration);
try {
container = new DefaultPlexusContainer(containerConfiguration);
} catch (PlexusContainerException e) {
throw new IllegalArgumentException("Failed to create plexus container.", e);
}
+ testInstanceCustomizeContainer(container);
}
/**
@@ -155,6 +160,20 @@ protected void customizeContainerConfiguration(ContainerConfiguration containerC
containerConfiguration.setClassPathScanning(PlexusConstants.SCANNING_INDEX);
}
+ private void testInstanceCustomizeContainerConfiguration(ContainerConfiguration containerConfiguration) {
+ Object testInstance = context.getRequiredTestInstance();
+ if (testInstance instanceof PlexusTestConfiguration) {
+ ((PlexusTestConfiguration) testInstance).customizeConfiguration(containerConfiguration);
+ }
+ }
+
+ private void testInstanceCustomizeContainer(PlexusContainer container) {
+ Object testInstance = context.getRequiredTestInstance();
+ if (testInstance instanceof PlexusTestConfiguration) {
+ ((PlexusTestConfiguration) testInstance).customizeContainer(container);
+ }
+ }
+
protected void customizeContext(Context context) {}
protected PlexusConfiguration customizeComponentConfiguration() {
@@ -170,6 +189,29 @@ public void afterEach(ExtensionContext context) throws Exception {
}
}
+ /**
+ * The base directory for the test instance. By default, this is the same as the basedir.
+ *
+ * @return the testBasedir
+ * @since 1.7.0
+ */
+ protected String getTestBasedir() {
+ if (testBasedir == null) {
+ testBasedir = getBasedir();
+ }
+ return testBasedir;
+ }
+
+ /**
+ * Set the base directory for the test instance. By default, this is the same as the basedir.
+ *
+ * @param testBasedir the testBasedir for the test instance
+ * @since 1.7.0
+ */
+ protected void setTestBasedir(String testBasedir) {
+ this.testBasedir = testBasedir;
+ }
+
public PlexusContainer getContainer() {
if (container == null) {
setupContainer();
diff --git a/src/main/java/org/codehaus/plexus/testing/PlexusTestConfiguration.java b/src/main/java/org/codehaus/plexus/testing/PlexusTestConfiguration.java
new file mode 100644
index 0000000..7707902
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/testing/PlexusTestConfiguration.java
@@ -0,0 +1,28 @@
+package org.codehaus.plexus.testing;
+
+import org.codehaus.plexus.ContainerConfiguration;
+import org.codehaus.plexus.PlexusContainer;
+
+/**
+ * Allow to customize the Plexus container by test class.
+ *
+ * @since 1.7.0
+ */
+public interface PlexusTestConfiguration {
+
+ /**
+ * Customize the container configuration before the container is created.
+ *
+ * @param containerConfiguration the container configuration to customize
+ * @since 1.7.0
+ */
+ default void customizeConfiguration(ContainerConfiguration containerConfiguration) {}
+
+ /**
+ * Customize the container after it has been created.
+ *
+ * @param container the container to customize
+ * @since 1.7.0
+ */
+ default void customizeContainer(PlexusContainer container) {}
+}
diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md
new file mode 100644
index 0000000..719b5d0
--- /dev/null
+++ b/src/site/markdown/index.md
@@ -0,0 +1,22 @@
+# Plexus Testing
+
+Library to help testing plexus components
+
+## Example usage
+
+### Test class
+
+
+
+### Customization of the Plexus Container
+
+Test class can customize the Plexus Container used for testing by implementing
+the [`PlexusTestConfiguration`](apidocs/org/codehaus/plexus/testing/PlexusTestConfiguration.html).
+All methods have default empty implementations so you can implement only the ones you need.
+
+
+
+### Used classes in test
+
+
+
diff --git a/src/site/site.xml b/src/site/site.xml
new file mode 100644
index 0000000..67e04d2
--- /dev/null
+++ b/src/site/site.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/java/org/codehaus/plexus/testing/PlexusTestCustomizeTest.java b/src/test/java/org/codehaus/plexus/testing/PlexusTestCustomizeTest.java
new file mode 100644
index 0000000..6e5af9c
--- /dev/null
+++ b/src/test/java/org/codehaus/plexus/testing/PlexusTestCustomizeTest.java
@@ -0,0 +1,66 @@
+package org.codehaus.plexus.testing;
+
+/*
+ * 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.
+ */
+// START SNIPPET: test-customize-class
+import javax.inject.Inject;
+
+import org.codehaus.plexus.PlexusContainer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+// MockitoExtension must be first
+@ExtendWith(MockitoExtension.class)
+@PlexusTest
+class PlexusTestCustomizeTest implements PlexusTestConfiguration {
+
+ @Mock
+ private TestJavaxComponent2 mockComponent2;
+
+ /*
+ Customize the container configuration before it is used to create the container.
+
+ Method has default empty implementation so not need to implement if not used.
+
+ @Override
+ public void customizeConfiguration(ContainerConfiguration containerConfiguration) {
+
+ }
+ */
+
+ @Override
+ public void customizeContainer(PlexusContainer container) {
+ container.addComponent(mockComponent2, TestJavaxComponent2.class.getName());
+ }
+
+ @Inject
+ private TestJavaxComponent testJavaxComponent;
+
+ @Test
+ void dependencyShouldBeInjected() {
+ assertNotNull(testJavaxComponent);
+ assertSame(testJavaxComponent.getTestComponent2(), mockComponent2);
+ }
+}
+// END SNIPPET: test-customize-class
diff --git a/src/test/java/org/codehaus/plexus/testing/PlexusTestJavaxTest.java b/src/test/java/org/codehaus/plexus/testing/PlexusTestJavaxTest.java
index add8490..b2a07b3 100644
--- a/src/test/java/org/codehaus/plexus/testing/PlexusTestJavaxTest.java
+++ b/src/test/java/org/codehaus/plexus/testing/PlexusTestJavaxTest.java
@@ -18,7 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-
+// START SNIPPET: test-class
import javax.inject.Inject;
import org.junit.jupiter.api.Test;
@@ -37,3 +37,4 @@ void dependencyShouldBeInjected() {
assertNotNull(testJavaxComponent.getTestComponent2());
}
}
+// END SNIPPET: test-class
diff --git a/src/test/java/org/codehaus/plexus/testing/TestJavaxComponent.java b/src/test/java/org/codehaus/plexus/testing/TestJavaxComponent.java
index 6ce98b7..5d1d582 100644
--- a/src/test/java/org/codehaus/plexus/testing/TestJavaxComponent.java
+++ b/src/test/java/org/codehaus/plexus/testing/TestJavaxComponent.java
@@ -19,6 +19,7 @@
* under the License.
*/
+// START SNIPPET: test-component
import javax.inject.Inject;
import javax.inject.Named;
@@ -31,3 +32,4 @@ public TestJavaxComponent2 getTestComponent2() {
return testJavaxComponent2;
}
}
+// END SNIPPET: test-component
diff --git a/src/test/java/org/codehaus/plexus/testing/TestJavaxComponent2.java b/src/test/java/org/codehaus/plexus/testing/TestJavaxComponent2.java
index d5afd5b..f5609f2 100644
--- a/src/test/java/org/codehaus/plexus/testing/TestJavaxComponent2.java
+++ b/src/test/java/org/codehaus/plexus/testing/TestJavaxComponent2.java
@@ -19,7 +19,9 @@
* under the License.
*/
+// START SNIPPET: test-component2
import javax.inject.Named;
@Named
public class TestJavaxComponent2 {}
+// END SNIPPET: test-component2