elmuerte opened a new issue, #245: URL: https://github.com/apache/maven-plugin-testing/issues/245
### Affected version 3.4.0 ### Bug description The mocked maven project created when using `@InjectMojo` is quite unsafe, only the properties are usable. https://github.com/apache/maven-plugin-testing/blob/3d28d1ef3f584e27762528de74624e8bf0c234dc/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java#L294-L298 Everything else would return null. This is not documented and thus results in surprises during test executions like an NPE when in the mojo when you do `project.getBuild().getDirectory()` to get the target directory. You can work around this like this: ```java @Inject MavenProject project; @BeforeEach @Basedir("target/test-classes/projects/run") @InjectMojo(goal = "findings") void setUp(FindingsMojo findingsMojo) { when(project.getBuild()).thenReturn(mock()); when(project.getBuild().getDirectory()).thenReturn("target/test-classes/projects/run/target"); } ``` It would be nicer if parts of the project would have more safe to use defaults. But it should be at least documented that basic mocks are being inserted into the resolved mojos. In the Javadoc for [MojoExtension](https://maven.apache.org/plugin-testing/maven-plugin-testing-harness/apidocs/org/apache/maven/api/plugin/testing/MojoExtension.html) it also hints that certain properties are resolved ```java @MojoParameter(name = "outputDirectory", value = "${project.build.directory}/generated") ``` But that does not happen at all. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
