Re: maven-plugin-test-harness
Slawomir Jaranowski <[email protected]> Sun, 28 Dec 2025 14:52:21 +0100
| Newsgroups | gmane.comp.jakarta.turbine.maven.user |
|---|---|
| Message-ID | <CAGjJkv1Y9fu_jBZVVbZAXPCJ2NjWRZOC5t7478bfTtRPEgvq=g@mail.gmail.com> |
On Sat, 27 Dec 2025 at 00:11, Claude Warren <[email protected]> wrote: > Sławomir, > > I seem to be a bit lost. I am able to generate the test poms in testing > directories. > > I am able to generate POMs and associated test files during the > generate-test-sources phase. My test code looks like: > > > /** > * Generated test for config/withDefaults > */ > @Test > @InjectMojo(goal = "check") > > @Basedir("target/test-classes/org/apache/rat/maven/stubs/config/withDefaults") > public void configWithDefaultsTest(RatCheckMojo mojo) throws > MojoExecutionException { > TestData testData = testDataMap.get("config/withDefaults"); > > > testData.setupFiles(Paths.get("target/test-classes/org/apache/rat/maven/stubs/config/withDefaults")); > if (testData.getExpectedException() != null) { > > > assertThatThrownBy(mojo::execute).hasMessageContaining(testData.getExpectedException().getMessage()); > } else { > mojo.execute(); > ValidatorData validatorData = new ValidatorData(mojo.getOutput(), > "src/test/resources/org/apache/rat/maven/config/noDefaults"); > testData.getValidator().accept(validatorData); > } > } > > > > The RatCheckMojo has a parameter : > > > /** The xml output file. */ > @Parameter(defaultValue = "${project.build.directory}/.rat.xml", readonly = > true) > protected File xmlOutputFile; > > > When the mojo executes, the "xmlOutputFile" is set to > > target/test-classes/org/apache/rat/maven/stubs/config/withDefaults/${project.build.directory}/.rat.xml > So my question is how can I get the ${project.*} properties populated > inside the test mojo under test? > MavenProject created for testing is a mock, which does not have mocked all methods .... https://github.com/apache/maven-plugin-testing/issues/245 You need add mocking for Maven project like: @Inject MavenProject project; .... when(project.getBuild()).thenReturn(mock()); when(project.getBuild().getDirectory()).thenReturn("target/test-classes/projects/run/target"); > > I am trying to maintain a maven implementation that will support Maven 3.x > > The pom in the > target/test-classes/org/apache/rat/maven/stubs/config/withDefaults > directory > would not work unless I added a "<project implementatikon=.../>" element. > But this seems like it may be a bastardization halfway between the JUnit3 > and JUnit5 implementations. > > I am using > <mavenVersion>3.9.12</mavenVersion> > <mavenPluginTestingVersion>3.4.0</mavenPluginTestingVersion> > <mavenPluginToolsVersion>3.15.2</mavenPluginToolsVersion> > > The code is in [1]. The tools submodule generates the test code as well as > a base abstract class for the mojos. > > [1] > > https://github.com/apache/creadur-rat/tree/feature/restructure/apache-rat-plugin-parent > > Any assistance would be appreciated. > > Claude > -- Sławomir Jaranowski