slawekjaranowski commented on code in PR #579:
URL: https://github.com/apache/maven-war-plugin/pull/579#discussion_r2535051686
##########
src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java:
##########
@@ -37,47 +37,63 @@
* under the License.
*/
+import org.apache.maven.api.di.Provides;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
+import org.apache.maven.plugins.war.stub.ResourceStub;
+import org.codehaus.plexus.util.FileUtils;
+import org.junit.jupiter.api.Test;
+
+import javax.inject.Inject;
import java.io.BufferedReader;
import java.io.File;
import java.io.StringReader;
-import java.util.LinkedList;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
-import org.apache.maven.plugins.war.stub.ResourceStub;
-import org.codehaus.plexus.util.FileUtils;
+import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.when;
/**
* @author Olivier Lamy
* @since 21 juil. 2008
*/
-public class WarExplodedMojoFilteringTest extends AbstractWarExplodedMojoTest {
+@MojoTest
+public class WarExplodedMojoFilteringTest {
- protected File getPomFile() {
- return new File(getBasedir(),
"/target/test-classes/unit/warexplodedmojo/plugin-config.xml");
- }
+ @Inject
Review Comment:
I'm afraid that for simple types will not working
We can provide it in test pom.xml as standard goal configuration
##########
src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java:
##########
@@ -37,47 +37,63 @@
* under the License.
*/
+import org.apache.maven.api.di.Provides;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
+import org.apache.maven.plugins.war.stub.ResourceStub;
+import org.codehaus.plexus.util.FileUtils;
+import org.junit.jupiter.api.Test;
+
+import javax.inject.Inject;
import java.io.BufferedReader;
import java.io.File;
import java.io.StringReader;
-import java.util.LinkedList;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
-import org.apache.maven.plugins.war.stub.ResourceStub;
-import org.codehaus.plexus.util.FileUtils;
+import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.when;
/**
* @author Olivier Lamy
* @since 21 juil. 2008
*/
-public class WarExplodedMojoFilteringTest extends AbstractWarExplodedMojoTest {
+@MojoTest
+public class WarExplodedMojoFilteringTest {
- protected File getPomFile() {
- return new File(getBasedir(),
"/target/test-classes/unit/warexplodedmojo/plugin-config.xml");
- }
+ @Inject
+ private List<String> filters;
+
+ @Inject
+ private MavenSession mavenSession;
protected File getTestDirectory() {
return new File(getBasedir(),
"target/test-classes/unit/warexplodedmojo/test-dir");
}
- /**
- * @throws Exception in case of an error.
- */
- @SuppressWarnings("checkstyle:MethodLength")
- public void testExplodedWarWithResourceFiltering() throws Exception {
+ @Provides
+ List<String> filters() {
+ List<String> filtersList = new ArrayList<>();
+ filtersList.add("test-filter"); //only for demo, it is temporary
+ return filtersList;
+ }
+
+ @InjectMojo(goal="exploded", pom =
"src/test/resources/unit/warexplodedmojo/plugin-config.xml")
+ @Test
+ public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo)
throws Exception {
// setup test data
String testId = "ExplodedWarWithResourceFiltering";
- MavenProjectBasicStub project = new MavenProjectBasicStub();
File webAppDirectory = new File(getTestDirectory(), testId);
File webAppSource = createWebAppSource(testId);
File classesDir = createClassesDir(testId, false);
File webAppResource = new File(getTestDirectory(), testId +
"-test-data/resources");
File sampleResource = new File(webAppResource, "custom-setting.cfg");
File sampleResourceWDir = new File(webAppResource,
"custom-config/custom-setting.cfg");
Review Comment:
Instead of this many code we can simple crate a needed project structure
with needed files in unit/warexplodedmojo
and simple execute mojo in correct bassedir
--
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]