-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Affected version
3.4.0
Bug description
The mocked maven project created when using @InjectMojo is quite unsafe, only the properties are usable.
Lines 294 to 298 in 3d28d1e
| private MavenProject mockMavenProject() { | |
| MavenProject mavenProject = Mockito.mock(MavenProject.class); | |
| lenient().when(mavenProject.getProperties()).thenReturn(new Properties()); | |
| return mavenProject; | |
| } |
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:
@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 it also hints that certain properties are resolved
@MojoParameter(name = "outputDirectory", value = "${project.build.directory}/generated")But that does not happen at all.
mjog
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working