From fc14d81d5fde9cd8f1fa47f8483393b2cc7f1514 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Mon, 18 Aug 2025 22:50:46 +0200 Subject: [PATCH 01/10] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2e345f0..ae4feec 100644 --- a/pom.xml +++ b/pom.xml @@ -9,14 +9,14 @@ plexus-testing - 1.6.0 + 1.6.1-SNAPSHOT Plexus Testing scm:git:https://github.com/codehaus-plexus/plexus-testing.git ${project.scm.connection} - plexus-testing-1.6.0 + HEAD https://github.com/codehaus-plexus/plexus-testing @@ -32,7 +32,7 @@ 0.9.0.M4 - 2025-08-18T20:50:39Z + 2025-08-18T20:50:45Z From fde8562250c7162389cc66b9712cfa2a0fa007f3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 17 Sep 2025 23:01:36 +0000 Subject: [PATCH 02/10] Bump com.google.guava:guava from 33.4.8-jre to 33.5.0-jre Bumps [com.google.guava:guava](https://github.com/google/guava) from 33.4.8-jre to 33.5.0-jre. - [Release notes](https://github.com/google/guava/releases) - [Commits](https://github.com/google/guava/commits) --- updated-dependencies: - dependency-name: com.google.guava:guava dependency-version: 33.5.0-jre dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ae4feec..53a8a9e 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ com.google.guava guava - 33.4.8-jre + 33.5.0-jre From c8966aecfee4d7dba01e7e3ca3992e2c058f34bc Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sat, 11 Oct 2025 12:44:16 +0200 Subject: [PATCH 03/10] Use direct dependencies for guava dependencyManagement are not transitive in Maven 3.x --- pom.xml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 53a8a9e..f31ec9e 100644 --- a/pom.xml +++ b/pom.xml @@ -35,18 +35,14 @@ 2025-08-18T20:50:45Z - - - - com.google.guava - guava - - 33.5.0-jre - - - - + + + com.google.guava + guava + + 33.5.0-jre + org.eclipse.sisu org.eclipse.sisu.plexus From 3507852e70c4ecafb80215b6dbf63206016f8551 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 11 Oct 2025 12:25:27 +0000 Subject: [PATCH 04/10] Bump org.codehaus.plexus:plexus from 23 to 24 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 23 to 24. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-version: '24' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f31ec9e..2685d4d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.plexus plexus - 23 + 24 plexus-testing From 001cca10f35eb7fc0cdaa48c09f501136301f9a0 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sat, 11 Oct 2025 16:17:01 +0200 Subject: [PATCH 05/10] Prepare simple site for plugin --- pom.xml | 26 +++++++++++++++++++ src/site/markdown/index.md | 14 ++++++++++ src/site/site.xml | 15 +++++++++++ .../plexus/testing/PlexusTestJavaxTest.java | 3 ++- .../plexus/testing/TestJavaxComponent.java | 2 ++ .../plexus/testing/TestJavaxComponent2.java | 2 ++ 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/site/markdown/index.md create mode 100644 src/site/site.xml diff --git a/pom.xml b/pom.xml index 2685d4d..d6cbdf6 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,8 @@ 1.6.1-SNAPSHOT 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 @@ -19,10 +21,12 @@ HEAD https://github.com/codehaus-plexus/plexus-testing + github https://github.com/codehaus-plexus/plexus-testing/issues + github:gh-pages @@ -70,4 +74,26 @@ + + + + org.apache.maven.plugins + maven-scm-publish-plugin + + ${project.reporting.outputDirectory} + + + + + scm-publish + + + publish-scm + + site-deploy + + + + + diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md new file mode 100644 index 0000000..27da2b2 --- /dev/null +++ b/src/site/markdown/index.md @@ -0,0 +1,14 @@ +# Plexus Testing + +Library to help testing plexus components + +## Example usage + +### Test class + + + +### 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/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 From 4b2ca28c430fa197ee436f23137a1472d2cd372a Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sat, 11 Oct 2025 16:58:32 +0200 Subject: [PATCH 06/10] [maven-release-plugin] prepare release plexus-testing-1.6.1 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index d6cbdf6..e402295 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ plexus-testing - 1.6.1-SNAPSHOT + 1.6.1 Plexus Testing Library to help testing plexus components @@ -18,7 +18,7 @@ scm:git:https://github.com/codehaus-plexus/plexus-testing.git ${project.scm.connection} - HEAD + plexus-testing-1.6.1 https://github.com/codehaus-plexus/plexus-testing @@ -36,7 +36,7 @@ 0.9.0.M4 - 2025-08-18T20:50:45Z + 2025-10-11T14:58:25Z From 586251d3bb8e5595ed2392c776dc8359893f3940 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sat, 11 Oct 2025 16:58:36 +0200 Subject: [PATCH 07/10] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e402295..8ea3462 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ plexus-testing - 1.6.1 + 1.6.2-SNAPSHOT Plexus Testing Library to help testing plexus components @@ -18,7 +18,7 @@ scm:git:https://github.com/codehaus-plexus/plexus-testing.git ${project.scm.connection} - plexus-testing-1.6.1 + HEAD https://github.com/codehaus-plexus/plexus-testing @@ -36,7 +36,7 @@ 0.9.0.M4 - 2025-10-11T14:58:25Z + 2025-10-11T14:58:36Z From 13b3d77e016b4bf79a8f91d5c49dea39a7c2afda Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Mon, 13 Oct 2025 23:13:26 +0200 Subject: [PATCH 08/10] Allow to customize Plexus container by test class --- pom.xml | 17 ++++- .../plexus/testing/PlexusExtension.java | 19 +++++- .../testing/PlexusTestConfiguration.java | 28 ++++++++ src/site/markdown/index.md | 8 +++ .../testing/PlexusTestCustomizeTest.java | 66 +++++++++++++++++++ 5 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/codehaus/plexus/testing/PlexusTestConfiguration.java create mode 100644 src/test/java/org/codehaus/plexus/testing/PlexusTestCustomizeTest.java diff --git a/pom.xml b/pom.xml index 8ea3462..64d3356 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ plexus-testing - 1.6.2-SNAPSHOT + 1.7.0-SNAPSHOT Plexus Testing Library to help testing plexus components @@ -36,7 +36,7 @@ 0.9.0.M4 - 2025-10-11T14:58:36Z + 2025-10-13T21:13:09Z @@ -72,6 +72,19 @@ org.junit.jupiter junit-jupiter-api + + + org.mockito + mockito-core + 4.11.0 + test + + + org.mockito + mockito-junit-jupiter + 4.11.0 + test + diff --git a/src/main/java/org/codehaus/plexus/testing/PlexusExtension.java b/src/main/java/org/codehaus/plexus/testing/PlexusExtension.java index b344041..b4b84e1 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 @@ -94,7 +94,6 @@ protected void setContext(ExtensionContext context) { this.context = context; } - @SuppressWarnings("ResultOfMethodCallIgnored") protected void setupContainer() { // ---------------------------------------------------------------------------- // Context Setup @@ -136,12 +135,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 +156,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() { 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 index 27da2b2..719b5d0 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -8,6 +8,14 @@ Library to help testing plexus components +### 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/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 From 2a0f1d622c2ad50d71d9a6bd79a0f40b51c9f999 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Tue, 14 Oct 2025 08:53:37 +0200 Subject: [PATCH 09/10] Add testBasedir property We have basedir property which is static, we need new filed which will be not static and connected with current test instance. --- .../plexus/testing/PlexusExtension.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/testing/PlexusExtension.java b/src/main/java/org/codehaus/plexus/testing/PlexusExtension.java index b4b84e1..df2ffb9 100644 --- a/src/main/java/org/codehaus/plexus/testing/PlexusExtension.java +++ b/src/main/java/org/codehaus/plexus/testing/PlexusExtension.java @@ -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); @@ -101,7 +105,7 @@ protected void setupContainer() { DefaultContext context = new DefaultContext(); - context.put("basedir", getBasedir()); + context.put("basedir", getTestBasedir()); customizeContext(context); @@ -185,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(); From eee51ec17e0b48a5da08e82c649b5defd679a9b9 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Tue, 14 Oct 2025 23:16:49 +0200 Subject: [PATCH 10/10] [maven-release-plugin] prepare release plexus-testing-1.7.0 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 64d3356..7b7665b 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ plexus-testing - 1.7.0-SNAPSHOT + 1.7.0 Plexus Testing Library to help testing plexus components @@ -18,7 +18,7 @@ scm:git:https://github.com/codehaus-plexus/plexus-testing.git ${project.scm.connection} - HEAD + plexus-testing-1.7.0 https://github.com/codehaus-plexus/plexus-testing @@ -36,7 +36,7 @@ 0.9.0.M4 - 2025-10-13T21:13:09Z + 2025-10-14T21:16:46Z