Skip to content

Commit 2a603ae

Browse files
aamotharaldslawekjaranowski
authored andcommitted
Deleted jUnit5 folder and moved the junit5 sample tests over
1 parent b941f68 commit 2a603ae

File tree

3 files changed

+171
-131
lines changed

3 files changed

+171
-131
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.plugin.testing;
20+
21+
import java.io.File;
22+
23+
import org.apache.maven.execution.DefaultMavenExecutionRequest;
24+
import org.apache.maven.execution.MavenExecutionRequest;
25+
import org.apache.maven.execution.MavenSession;
26+
import org.apache.maven.plugin.MojoExecution;
27+
import org.apache.maven.project.MavenProject;
28+
import org.apache.maven.project.ProjectBuilder;
29+
import org.apache.maven.project.ProjectBuildingException;
30+
import org.apache.maven.project.ProjectBuildingRequest;
31+
import org.eclipse.aether.DefaultRepositorySystemSession;
32+
33+
public class ParametersMojoJUnit4Test extends AbstractMojoTestCase {
34+
public void testDefault() throws Exception {
35+
MavenProject project = readMavenProject(new File("src/test/projects/default"));
36+
37+
ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(project, "parameters");
38+
39+
assertNull(mojo.plain);
40+
assertNull(mojo.withProperty);
41+
assertEquals("default", mojo.withDefault);
42+
assertEquals("default", mojo.withPropertyAndDefault);
43+
}
44+
45+
public void testExplicit() throws Exception {
46+
MavenProject project = readMavenProject(new File("src/test/projects/explicit"));
47+
48+
ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(project, "parameters");
49+
50+
assertEquals("explicitValue", mojo.plain);
51+
assertEquals("explicitWithPropertyValue", mojo.withProperty);
52+
assertEquals("explicitWithDefaultValue", mojo.withDefault);
53+
assertEquals("explicitWithPropertyAndDefaultValue", mojo.withPropertyAndDefault);
54+
}
55+
56+
public void testDefaultWithProperty() throws Exception {
57+
MavenProject project = readMavenProject(new File("src/test/projects/default"));
58+
MavenSession session = newMavenSession(project);
59+
MojoExecution execution = newMojoExecution("parameters");
60+
61+
session.getUserProperties().put("property", "propertyValue");
62+
ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(session, execution);
63+
64+
assertNull(mojo.plain);
65+
assertEquals("propertyValue", mojo.withProperty);
66+
assertEquals("default", mojo.withDefault);
67+
assertEquals("propertyValue", mojo.withPropertyAndDefault);
68+
}
69+
70+
public void testExplicitWithProperty() throws Exception {
71+
MavenProject project = readMavenProject(new File("src/test/projects/explicit"));
72+
MavenSession session = newMavenSession(project);
73+
MojoExecution execution = newMojoExecution("parameters");
74+
75+
session.getUserProperties().put("property", "propertyValue");
76+
ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(session, execution);
77+
78+
assertEquals("explicitValue", mojo.plain);
79+
assertEquals("explicitWithPropertyValue", mojo.withProperty);
80+
assertEquals("explicitWithDefaultValue", mojo.withDefault);
81+
assertEquals("explicitWithPropertyAndDefaultValue", mojo.withPropertyAndDefault);
82+
}
83+
84+
protected MavenProject readMavenProject(File basedir) throws ProjectBuildingException, Exception {
85+
File pom = new File(basedir, "pom.xml");
86+
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
87+
request.setBaseDirectory(basedir);
88+
ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
89+
configuration.setRepositorySession(new DefaultRepositorySystemSession());
90+
MavenProject project =
91+
lookup(ProjectBuilder.class).build(pom, configuration).getProject();
92+
assertNotNull(project);
93+
return project;
94+
}
95+
}

maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java

Lines changed: 76 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,78 +18,94 @@
1818
*/
1919
package org.apache.maven.plugin.testing;
2020

21-
import java.io.File;
22-
23-
import org.apache.maven.execution.DefaultMavenExecutionRequest;
24-
import org.apache.maven.execution.MavenExecutionRequest;
25-
import org.apache.maven.execution.MavenSession;
26-
import org.apache.maven.plugin.MojoExecution;
27-
import org.apache.maven.project.MavenProject;
28-
import org.apache.maven.project.ProjectBuilder;
29-
import org.apache.maven.project.ProjectBuildingException;
30-
import org.apache.maven.project.ProjectBuildingRequest;
31-
import org.eclipse.aether.DefaultRepositorySystemSession;
32-
33-
public class ParametersMojoTest extends AbstractMojoTestCase {
34-
public void testDefault() throws Exception {
35-
MavenProject project = readMavenProject(new File("src/test/projects/default"));
36-
37-
ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(project, "parameters");
38-
39-
assertNull(mojo.getPlain());
40-
assertNull(mojo.getWithProperty());
41-
assertEquals("default", mojo.getWithDefault());
42-
assertEquals("default", mojo.getWithPropertyAndDefault());
43-
}
21+
import javax.inject.Inject;
22+
23+
import org.apache.maven.plugin.logging.Log;
24+
import org.apache.maven.plugin.testing.junit5.InjectMojo;
25+
import org.apache.maven.plugin.testing.junit5.MojoParameter;
26+
import org.apache.maven.plugin.testing.junit5.MojoParameters;
27+
import org.apache.maven.plugin.testing.junit5.MojoTest;
28+
import org.junit.jupiter.api.Test;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
31+
32+
import static org.junit.jupiter.api.Assertions.*;
33+
34+
@MojoTest
35+
public class ParametersMojoTest {
36+
37+
private static final Logger logger = LoggerFactory.getLogger(ParametersMojoTest.class);
38+
39+
private static final String DEFAULT_POM = "src/test/projects/default/pom.xml";
4440

45-
public void testExplicit() throws Exception {
46-
MavenProject project = readMavenProject(new File("src/test/projects/explicit"));
41+
private static final String EXPLICIT_POM = "src/test/projects/explicit/pom.xml";
4742

48-
ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(project, "parameters");
43+
private static final String PROPERTY_POM = "src/test/projects/property/pom.xml";
4944

50-
assertEquals("explicitValue", mojo.getPlain());
51-
assertEquals("explicitWithPropertyValue", mojo.getWithProperty());
52-
assertEquals("explicitWithDefaultValue", mojo.getWithDefault());
53-
assertEquals("explicitWithPropertyAndDefaultValue", mojo.getWithPropertyAndDefault());
45+
@Inject
46+
private Log log;
47+
48+
@Test
49+
@InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = DEFAULT_POM)
50+
void testDefaultPom(ParametersMojo mojo) {
51+
assertDoesNotThrow(mojo::execute);
5452
}
5553

56-
public void testDefaultWithProperty() throws Exception {
57-
MavenProject project = readMavenProject(new File("src/test/projects/default"));
58-
MavenSession session = newMavenSession(project);
59-
MojoExecution execution = newMojoExecution("parameters");
54+
@Test
55+
@InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = EXPLICIT_POM)
56+
void testExplicitPom(ParametersMojo mojo) {
57+
assertEquals("explicitValue", mojo.plain);
58+
assertDoesNotThrow(mojo::execute);
59+
}
6060

61-
session.getUserProperties().put("property", "propertyValue");
62-
ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(session, execution);
61+
@Test
62+
@InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = PROPERTY_POM)
63+
void testPropertyPom(ParametersMojo mojo) {
64+
assertDoesNotThrow(mojo::execute);
65+
}
6366

64-
assertNull(mojo.getPlain());
65-
assertEquals("propertyValue", mojo.getWithProperty());
66-
assertEquals("default", mojo.getWithDefault());
67-
assertEquals("propertyValue", mojo.getWithPropertyAndDefault());
67+
@Test
68+
@InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = DEFAULT_POM)
69+
void simpleMojo(ParametersMojo mojo) {
70+
assertEquals(log, mojo.getLog());
71+
assertDoesNotThrow(mojo::execute);
6872
}
6973

70-
public void testExplicitWithProperty() throws Exception {
71-
MavenProject project = readMavenProject(new File("src/test/projects/explicit"));
72-
MavenSession session = newMavenSession(project);
73-
MojoExecution execution = newMojoExecution("parameters");
74+
@Test
75+
@InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = DEFAULT_POM)
76+
@MojoParameter(name = "plain", value = "plainValue")
77+
@MojoParameter(name = "withDefault", value = "withDefaultValue")
78+
void simpleMojoWithParameters(ParametersMojo mojo) {
79+
assertEquals("plainValue", mojo.plain);
80+
assertEquals("withDefaultValue", mojo.withDefault);
81+
assertDoesNotThrow(mojo::execute);
82+
}
7483

75-
session.getUserProperties().put("property", "propertyValue");
76-
ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(session, execution);
84+
@Test
85+
@InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = DEFAULT_POM)
86+
@MojoParameters({
87+
@MojoParameter(name = "plain", value = "plainValue"),
88+
@MojoParameter(name = "withDefault", value = "withDefaultValue")
89+
})
90+
void simpleMojoWithParametersGroupingAnnotation(ParametersMojo mojo) {
91+
assertEquals("plainValue", mojo.plain);
92+
assertEquals("withDefaultValue", mojo.withDefault);
93+
assertDoesNotThrow(mojo::execute);
94+
}
7795

78-
assertEquals("explicitValue", mojo.getPlain());
79-
assertEquals("explicitWithPropertyValue", mojo.getWithProperty());
80-
assertEquals("explicitWithDefaultValue", mojo.getWithDefault());
81-
assertEquals("explicitWithPropertyAndDefaultValue", mojo.getWithPropertyAndDefault());
96+
@Test
97+
@InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = DEFAULT_POM)
98+
@MojoParameter(name = "plain", value = "plainValue")
99+
void simpleMojoWithParameter(ParametersMojo mojo) {
100+
assertEquals("plainValue", mojo.plain);
101+
assertDoesNotThrow(mojo::execute);
82102
}
83103

84-
protected MavenProject readMavenProject(File basedir) throws ProjectBuildingException, Exception {
85-
File pom = new File(basedir, "pom.xml");
86-
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
87-
request.setBaseDirectory(basedir);
88-
ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
89-
configuration.setRepositorySession(new DefaultRepositorySystemSession());
90-
MavenProject project =
91-
lookup(ProjectBuilder.class).build(pom, configuration).getProject();
92-
assertNotNull(project);
93-
return project;
104+
@Test
105+
@MojoParameter(name = "plain", value = "plainValue")
106+
@InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = EXPLICIT_POM)
107+
void simpleMojoWithParameterInjectionWinsOverConfig(ParametersMojo mojo) {
108+
assertEquals("plainValue", mojo.plain);
109+
assertDoesNotThrow(mojo::execute);
94110
}
95111
}
Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +0,0 @@
1-
/*
2-
* Licensed to the Apache Software Foundation (ASF) under one
3-
* or more contributor license agreements. See the NOTICE file
4-
* distributed with this work for additional information
5-
* regarding copyright ownership. The ASF licenses this file
6-
* to you under the Apache License, Version 2.0 (the
7-
* "License"); you may not use this file except in compliance
8-
* with the License. You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing,
13-
* software distributed under the License is distributed on an
14-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-
* KIND, either express or implied. See the License for the
16-
* specific language governing permissions and limitations
17-
* under the License.
18-
*/
19-
package org.apache.maven.plugin.testing.junit5;
20-
21-
import javax.inject.Inject;
22-
23-
import org.apache.maven.plugin.logging.Log;
24-
import org.apache.maven.plugin.testing.ParametersMojo;
25-
import org.junit.jupiter.api.Test;
26-
27-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
28-
import static org.junit.jupiter.api.Assertions.assertEquals;
29-
30-
@MojoTest
31-
class Junit5Test {
32-
33-
private static final String POM = "<project>"
34-
+ "<build>"
35-
+ " <plugins>"
36-
+ " <plugin>"
37-
+ " <artifactId>test-plugin</artifactId>"
38-
+ " <configuration>"
39-
+ " </configuration>"
40-
+ " </plugin>"
41-
+ " </plugins>"
42-
+ "</build>" + "</project>";
43-
44-
@Inject
45-
private Log log;
46-
47-
@Test
48-
@InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = POM)
49-
void simpleMojo(ParametersMojo mojo) {
50-
assertEquals(log, mojo.getLog());
51-
assertDoesNotThrow(mojo::execute);
52-
}
53-
54-
@Test
55-
@InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = POM)
56-
@MojoParameter(name = "plain", value = "plainValue")
57-
@MojoParameter(name = "withDefault", value = "withDefaultValue")
58-
void simpleMojoWithParameters(ParametersMojo mojo) {
59-
assertEquals("plainValue", mojo.getPlain());
60-
assertEquals("withDefaultValue", mojo.getWithDefault());
61-
assertDoesNotThrow(mojo::execute);
62-
}
63-
64-
@Test
65-
@InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = POM)
66-
@MojoParameter(name = "plain", value = "plainValue")
67-
void simpleMojoWithParameter(ParametersMojo mojo) {
68-
assertEquals("plainValue", mojo.getPlain());
69-
assertDoesNotThrow(mojo::execute);
70-
}
71-
}

0 commit comments

Comments
 (0)