Test default values and expressions of Mojos using Maven Plugin Testing Harness:
maven, unit-testing
Solution
So it looks like they added `lookupConfiguredMojo` for just this use case. It took me a while to figure out how to call that because you need a properly configured `MavenProject` to use it. Here's what worked for me:
File pomFile = ...
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject();
MyMojo mojo = (MyMojo) this.lookupConfiguredMojo(project, "my-goal");
...
Problem
I have a problem using the Maven Plugin Testing Harness (2.0-alpha1): When I want to test my Mojo, the default values and expressions for parameters are not applicable. I have the following parameter: ``` /** * <p>The output file to write the settings to.</p> * * @parameter default-value="${project.build.directory}/myProperties.properties" expression="${properties.file}" */ private String file; ``` When I run my unit tests this property is always null. I tried to inject a MavenProjectStub which returns `${project.build.directory}` successfully but this is not applied to my Mojo parameter. Is there any way to enable default values and expressions like `${project.build.directory}` inside my Mojos during the tests?