Skip to content

Commit db50a3a

Browse files
Bump maven-plugin-testing-harness to 3.4.0
1 parent 519c918 commit db50a3a

File tree

6 files changed

+14
-88
lines changed

6 files changed

+14
-88
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ under the License.
171171
<dependency>
172172
<groupId>org.apache.maven.plugin-testing</groupId>
173173
<artifactId>maven-plugin-testing-harness</artifactId>
174-
<version>4.0.0-alpha-2</version>
174+
<version>3.4.0</version>
175175
<scope>test</scope>
176176
</dependency>
177177
<dependency>

src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,21 @@
2020

2121
import java.io.File;
2222
import java.util.Arrays;
23-
import java.util.Collections;
2423
import java.util.HashSet;
2524
import java.util.Set;
2625

26+
import org.apache.maven.api.plugin.testing.InjectMojo;
27+
import org.apache.maven.api.plugin.testing.MojoTest;
2728
import org.apache.maven.artifact.Artifact;
2829
import org.apache.maven.plugin.compiler.stubs.CompilerManagerStub;
2930
import org.apache.maven.plugin.logging.Log;
30-
import org.apache.maven.plugin.testing.junit5.InjectMojo;
31-
import org.apache.maven.plugin.testing.junit5.MojoTest;
3231
import org.apache.maven.plugin.testing.stubs.ArtifactStub;
3332
import org.junit.jupiter.api.Test;
3433

34+
import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
35+
import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
3536
import static org.apache.maven.plugin.compiler.MojoTestUtils.getMockMavenProject;
3637
import static org.apache.maven.plugin.compiler.MojoTestUtils.getMockMavenSession;
37-
import static org.apache.maven.plugin.compiler.MojoTestUtils.getMockMojoExecution;
38-
import static org.apache.maven.plugin.compiler.MojoTestUtils.getVariableValueFromObject;
39-
import static org.apache.maven.plugin.compiler.MojoTestUtils.setVariableValueToObject;
4038
import static org.junit.jupiter.api.Assertions.assertEquals;
4139
import static org.junit.jupiter.api.Assertions.assertFalse;
4240
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -70,7 +68,7 @@ void testCompilerBasic(CompilerMojo compilerMojo) throws Exception {
7068
setVariableValueToObject(compilerMojo, "targetOrReleaseSet", false);
7169
compilerMojo.execute();
7270

73-
Artifact projectArtifact = getVariableValueFromObject(compilerMojo, "projectArtifact");
71+
Artifact projectArtifact = (Artifact) getVariableValueFromObject(compilerMojo, "projectArtifact");
7472
assertNotNull(
7573
projectArtifact.getFile(),
7674
"MCOMPILER-94: artifact file should only be null if there is nothing to compile");
@@ -110,7 +108,7 @@ void testCompilerEmptySource(CompilerMojo compilerMojo) throws Exception {
110108

111109
assertFalse(compilerMojo.getOutputDirectory().exists());
112110

113-
Artifact projectArtifact = getVariableValueFromObject(compilerMojo, "projectArtifact");
111+
Artifact projectArtifact = (Artifact) getVariableValueFromObject(compilerMojo, "projectArtifact");
114112
assertNull(
115113
projectArtifact.getFile(), "MCOMPILER-94: artifact file should be null if there is nothing to compile");
116114
}
@@ -296,11 +294,7 @@ void testCompileSkipTest(CompilerMojo compilerMojo) throws Exception {
296294

297295
private void setUpCompilerMojoTestEnv(CompilerMojo mojo) throws Exception {
298296
setVariableValueToObject(mojo, "projectArtifact", new ArtifactStub());
299-
setVariableValueToObject(mojo, "compilePath", Collections.EMPTY_LIST);
300297
setVariableValueToObject(mojo, "session", getMockMavenSession());
301298
setVariableValueToObject(mojo, "project", getMockMavenProject());
302-
setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
303-
setVariableValueToObject(mojo, "source", AbstractCompilerMojo.DEFAULT_SOURCE);
304-
setVariableValueToObject(mojo, "target", AbstractCompilerMojo.DEFAULT_TARGET);
305299
}
306300
}

src/test/java/org/apache/maven/plugin/compiler/MojoTestUtils.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,14 @@
1818
*/
1919
package org.apache.maven.plugin.compiler;
2020

21-
import java.lang.reflect.Field;
22-
2321
import org.apache.maven.execution.MavenSession;
24-
import org.apache.maven.plugin.MojoExecution;
25-
import org.apache.maven.plugin.descriptor.MojoDescriptor;
26-
import org.apache.maven.plugin.descriptor.PluginDescriptor;
2722
import org.apache.maven.project.MavenProject;
28-
import org.codehaus.plexus.util.ReflectionUtils;
2923

3024
import static org.mockito.Mockito.mock;
3125
import static org.mockito.Mockito.when;
3226

3327
public class MojoTestUtils {
3428

35-
public static <T> T getVariableValueFromObject(Object object, String variable) throws IllegalAccessException {
36-
Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses(variable, object.getClass());
37-
field.setAccessible(true);
38-
return (T) field.get(object);
39-
}
40-
41-
public static <T> void setVariableValueToObject(Object object, String variable, T value)
42-
throws IllegalAccessException {
43-
Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses(variable, object.getClass());
44-
field.setAccessible(true);
45-
field.set(object, value);
46-
}
47-
4829
public static MavenProject getMockMavenProject() {
4930
MavenProject mp = new MavenProject();
5031
mp.getBuild().setDirectory("target");
@@ -61,15 +42,4 @@ public static MavenSession getMockMavenSession() {
6142
when(session.getCurrentProject()).thenReturn(getMockMavenProject());
6243
return session;
6344
}
64-
65-
public static MojoExecution getMockMojoExecution() {
66-
MojoDescriptor md = new MojoDescriptor();
67-
MojoExecution me = new MojoExecution(md);
68-
69-
PluginDescriptor pd = new PluginDescriptor();
70-
pd.setArtifactId("maven-compiler-plugin");
71-
md.setPluginDescriptor(pd);
72-
73-
return me;
74-
}
7545
}

src/test/java/org/apache/maven/plugin/compiler/TestCompilerMojoTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,18 @@
2626
import java.util.Set;
2727
import java.util.stream.Stream;
2828

29+
import org.apache.maven.api.plugin.testing.InjectMojo;
30+
import org.apache.maven.api.plugin.testing.MojoTest;
2931
import org.apache.maven.plugin.compiler.stubs.CompilerManagerStub;
30-
import org.apache.maven.plugin.testing.junit5.InjectMojo;
31-
import org.apache.maven.plugin.testing.junit5.MojoTest;
3232
import org.junit.jupiter.api.Test;
3333
import org.junit.jupiter.params.ParameterizedTest;
3434
import org.junit.jupiter.params.provider.Arguments;
3535
import org.junit.jupiter.params.provider.MethodSource;
3636

37+
import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
38+
import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
3739
import static org.apache.maven.plugin.compiler.MojoTestUtils.getMockMavenProject;
3840
import static org.apache.maven.plugin.compiler.MojoTestUtils.getMockMavenSession;
39-
import static org.apache.maven.plugin.compiler.MojoTestUtils.getMockMojoExecution;
40-
import static org.apache.maven.plugin.compiler.MojoTestUtils.getVariableValueFromObject;
41-
import static org.apache.maven.plugin.compiler.MojoTestUtils.setVariableValueToObject;
4241
import static org.junit.jupiter.api.Assertions.assertEquals;
4342
import static org.junit.jupiter.api.Assertions.assertFalse;
4443
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -171,7 +170,7 @@ void testCompileSkipTest(TestCompilerMojo testCompilerMojo) throws Exception {
171170
}
172171

173172
private void setUpCompilerMojoTestEnv(TestCompilerMojo mojo) throws Exception {
174-
File buildDir = getVariableValueFromObject(mojo, "buildDirectory");
173+
File buildDir = (File) getVariableValueFromObject(mojo, "buildDirectory");
175174
File testClassesDir = new File(buildDir, "test-classes");
176175
setVariableValueToObject(mojo, "outputDirectory", testClassesDir);
177176

@@ -188,9 +187,6 @@ private void setUpCompilerMojoTestEnv(TestCompilerMojo mojo) throws Exception {
188187
setVariableValueToObject(mojo, "compileSourceRoots", Arrays.asList(sourceRoot, testSourceRoot));
189188

190189
setVariableValueToObject(mojo, "session", getMockMavenSession());
191-
setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
192-
setVariableValueToObject(mojo, "source", AbstractCompilerMojo.DEFAULT_SOURCE);
193-
setVariableValueToObject(mojo, "target", AbstractCompilerMojo.DEFAULT_TARGET);
194190
}
195191

196192
static Stream<Arguments> olderThanJDK9() {

src/test/java/org/apache/maven/plugin/compiler/stubs/DebugEnabledLog.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/test/resources/unit/compiler-basic-sourcetarget/plugin-config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
<debug>true</debug>
3131
<outputDirectory>${basedir}/target/test/unit/compiler-basic-test/target/classes</outputDirectory>
3232
<buildDirectory>${basedir}/target/test/unit/compiler-basic-test/target</buildDirectory>
33-
<source>1.6</source>
34-
<target>1.6</target>
33+
<source>1.8</source>
34+
<target>1.8</target>
3535
</configuration>
3636
</plugin>
3737
</plugins>

0 commit comments

Comments
 (0)