This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 3761953a2b [MNG-8525] Add an integration test with Maven 4 Plugin 
Sample (#2055)
3761953a2b is described below

commit 3761953a2b5201695781a99d5a71eb72bf52c28a
Author: Sandra Parsick <spars...@users.noreply.github.com>
AuthorDate: Tue Jan 28 09:44:28 2025 +0100

    [MNG-8525] Add an integration test with Maven 4 Plugin Sample (#2055)
---
 .../maven/it/MavenITmng8525MavenDIPlugin.java      |  67 +++++++
 .../resources/mng-8525-maven-di-plugin/pom.xml     | 193 +++++++++++++++++++++
 .../src/it/hello-maven-plugin/invoker.properties   |  17 ++
 .../src/it/hello-maven-plugin/pom.xml              |  50 ++++++
 .../src/it/hello-maven-plugin/verify.groovy        |  22 +++
 .../mng-8525-maven-di-plugin/src/it/settings.xml   |  69 ++++++++
 .../java/org/apache/maven/plugins/HelloMojo.java   |  46 +++++
 .../org/apache/maven/plugins/MavenDIComponent.java |  31 ++++
 .../org/apache/maven/plugins/HelloMojoTest.java    |  59 +++++++
 9 files changed, 554 insertions(+)

diff --git 
a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8525MavenDIPlugin.java
 
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8525MavenDIPlugin.java
new file mode 100644
index 0000000000..3a6e6460ef
--- /dev/null
+++ 
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8525MavenDIPlugin.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.it;
+
+import java.io.File;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * This is a test set for <a 
href="https://issues.apache.org/jira/browse/MNG-8525";>MNG-8525</a>.
+ *
+ */
+public class MavenITmng8525MavenDIPlugin extends 
AbstractMavenIntegrationTestCase {
+
+    private File testDir;
+
+    public MavenITmng8525MavenDIPlugin() {
+        super("[4.0.0-rc-2,)");
+    }
+
+    @BeforeEach
+    public void setUp() throws Exception {
+        testDir = extractResources("/mng-8525-maven-di-plugin");
+    }
+
+    @Test
+    public void testMavenDIPlugin() throws Exception {
+        //
+        // Build a plugin that uses a Maven DI plugin
+        //
+        Verifier v0 = newVerifier(testDir.getAbsolutePath());
+        v0.setAutoclean(false);
+        v0.deleteDirectory("target");
+        v0.deleteArtifacts("org.apache.maven.its");
+        v0.addCliArgument("install");
+        v0.execute();
+        v0.verifyErrorFreeLog();
+
+        //
+        // Execute the Maven DI plugin
+        //
+        Verifier v1 = newVerifier(testDir.getAbsolutePath());
+        v1.setAutoclean(false);
+        
v1.addCliArgument("org.apache.maven.its:mavendi-maven-plugin:0.0.1-SNAPSHOT:hello");
+        v1.addCliArgument("-Dname=World");
+        v1.execute();
+        v1.verifyErrorFreeLog();
+        v1.verifyTextInLog("Hello World! I am a component that is being used 
via field injection!");
+    }
+}
diff --git 
a/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/pom.xml 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/pom.xml
new file mode 100644
index 0000000000..5b3dac0ee1
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/pom.xml
@@ -0,0 +1,193 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.1.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 
https://maven.apache.org/xsd/maven-4.1.0.xsd";>
+  <modelVersion>4.1.0</modelVersion>
+
+  <groupId>org.apache.maven.its</groupId>
+  <artifactId>mavendi-maven-plugin</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <packaging>maven-plugin</packaging>
+
+  <name>mavendi-maven-plugin Maven Plugin</name>
+  <url>http://maven.apache.org</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <javaVersion>17</javaVersion>
+    <guiceVersion>6.0.0</guiceVersion>
+    <mavenVersion>4.0.0-beta-5</mavenVersion>
+    <mavenPluginPluginVersion>4.0.0-beta-1</mavenPluginPluginVersion>
+    <mavenPluginTestingVersion>4.0.0-beta-2</mavenPluginTestingVersion>
+    <mavenResolverVersion>2.0.2</mavenResolverVersion>
+  </properties>
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.junit</groupId>
+        <artifactId>junit-bom</artifactId>
+        <version>5.11.4</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+      <dependency>
+        <groupId>org.mockito</groupId>
+        <artifactId>mockito-bom</artifactId>
+        <version>5.15.2</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-api-core</artifactId>
+      <version>${mavenVersion}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-api-di</artifactId>
+      <version>${mavenVersion}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-api-meta</artifactId>
+      <version>${mavenVersion}</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>${mavenVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.resolver</groupId>
+      <artifactId>maven-resolver-api</artifactId>
+      <version>${mavenResolverVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-api-impl</artifactId>
+      <version>${mavenVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.inject</groupId>
+      <artifactId>guice</artifactId>
+      <version>${guiceVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugin-testing</groupId>
+      <artifactId>maven-plugin-testing-harness</artifactId>
+      <version>${mavenPluginTestingVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-api</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-junit-jupiter</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <version>3.27.2</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-plugin-plugin</artifactId>
+        <version>${mavenPluginPluginVersion}</version>
+        <executions>
+          <execution>
+            <id>generate-helpmojo</id>
+            <goals>
+              <goal>helpmojo</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <profiles>
+    <profile>
+      <id>run-its</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-invoker-plugin</artifactId>
+            <version>3.6.1</version>
+            <configuration>
+              <showErrors>true</showErrors>
+              <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+              <cloneClean>true</cloneClean>
+              <pomIncludes>
+                <pomInclude>*/pom.xml</pomInclude>
+              </pomIncludes>
+              <preBuildHookScript>setup</preBuildHookScript>
+              <postBuildHookScript>verify</postBuildHookScript>
+              
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
+              <settingsFile>src/it/settings.xml</settingsFile>
+              <scriptVariables>
+                <remoteRepo>${project.build.directory}/remote-repo</remoteRepo>
+              </scriptVariables>
+              <filterProperties>
+                <remoteRepo>${project.build.directory}/remote-repo</remoteRepo>
+              </filterProperties>
+            </configuration>
+            <executions>
+              <execution>
+                <id>integration-test</id>
+                <goals>
+                  <goal>install</goal>
+                  <goal>integration-test</goal>
+                  <goal>verify</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>
diff --git 
a/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/hello-maven-plugin/invoker.properties
 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/hello-maven-plugin/invoker.properties
new file mode 100644
index 0000000000..1c0f90042f
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/hello-maven-plugin/invoker.properties
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+invoker.goals=initialize
diff --git 
a/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/hello-maven-plugin/pom.xml
 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/hello-maven-plugin/pom.xml
new file mode 100644
index 0000000000..beb9791f69
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/hello-maven-plugin/pom.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.1.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 
https://maven.apache.org/xsd/maven-4.1.0.xsd";>
+  <modelVersion>4.1.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.mvn4.its</groupId>
+  <artifactId>mvn4-plugin-demo</artifactId>
+  <version>1.0</version>
+
+  <description>Test a mvn4 plugin</description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.its</groupId>
+        <artifactId>mavendi-maven-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <name>World</name>
+        </configuration>
+        <executions>
+          <execution>
+            <goals>
+              <goal>hello</goal>
+            </goals>
+            <phase>initialize</phase>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git 
a/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/hello-maven-plugin/verify.groovy
 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/hello-maven-plugin/verify.groovy
new file mode 100644
index 0000000000..593d72f8cb
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/hello-maven-plugin/verify.groovy
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+File buildLog = new File(basedir, 'build.log')
+assert buildLog.exists()
+assert buildLog.text.contains("[INFO] Hello World! I am a component that is 
being used via field injection!")
diff --git 
a/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/settings.xml
 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/settings.xml
new file mode 100644
index 0000000000..7fe15992d8
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/it/settings.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<settings>
+  <profiles>
+    <profile>
+      <id>it-repo</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <repositories>
+        <repository>
+          <id>local.central</id>
+          <url>@localRepositoryUrl@</url>
+          <releases>
+            <enabled>true</enabled>
+            <checksumPolicy>ignore</checksumPolicy>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+            <checksumPolicy>ignore</checksumPolicy>
+          </snapshots>
+        </repository>
+      </repositories>
+      <pluginRepositories>
+        <pluginRepository>
+          <id>local.central</id>
+          <url>@localRepositoryUrl@</url>
+          <releases>
+            <enabled>true</enabled>
+            <checksumPolicy>ignore</checksumPolicy>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+            <checksumPolicy>ignore</checksumPolicy>
+          </snapshots>
+        </pluginRepository>
+        <pluginRepository>
+          <releases>
+            <enabled>false</enabled>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+          </snapshots>
+          <id>apache.snapshots</id>
+          <url>https://repository.apache.org/snapshots/</url>
+        </pluginRepository>
+      </pluginRepositories>
+    </profile>
+  </profiles>
+</settings>
diff --git 
a/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/HelloMojo.java
 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/HelloMojo.java
new file mode 100644
index 0000000000..ed9610735e
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/HelloMojo.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins;
+
+import org.apache.maven.api.Lifecycle.Phase;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.plugin.Log;
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
+
+@Mojo(name = "hello", defaultPhase = Phase.VALIDATE, projectRequired = false)
+public class HelloMojo implements org.apache.maven.api.plugin.Mojo {
+
+    @Inject
+    private MavenDIComponent component;
+
+    @Inject
+    private Log logger;
+
+    @Parameter(property = "name")
+    private String name;
+
+    public void execute() {
+        //
+        // Say hello to the world, my little constructor injected component!
+        //
+        String message = component.hello(name);
+        logger.info(message);
+    }
+}
diff --git 
a/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/MavenDIComponent.java
 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/MavenDIComponent.java
new file mode 100644
index 0000000000..d28c0f2407
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/MavenDIComponent.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins;
+
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+
+@Named
+@Singleton
+public class MavenDIComponent {
+
+    public String hello(String name) {
+        return "Hello " + name + "! I am a component that is being used via 
field injection!";
+    }
+}
diff --git 
a/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/test/java/org/apache/maven/plugins/HelloMojoTest.java
 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/test/java/org/apache/maven/plugins/HelloMojoTest.java
new file mode 100644
index 0000000000..3bf2bc10ce
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/test/java/org/apache/maven/plugins/HelloMojoTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins;
+
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Priority;
+import org.apache.maven.api.di.Provides;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+@MojoTest
+public class HelloMojoTest {
+
+    @Inject
+    private MavenDIComponent componentMock;
+
+    @Test
+    @InjectMojo(goal = "hello")
+    @MojoParameter(name = "name", value = "World")
+    public void testHello(HelloMojo mojoUnderTest) {
+
+        mojoUnderTest.execute();
+
+        ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
+        verify(componentMock).hello(captor.capture());
+        assertThat(captor.getValue()).isEqualTo("World");
+    }
+
+    @Singleton
+    @Provides
+    @Priority(10)
+    private MavenDIComponent createMavenDIComponent() {
+        return mock(MavenDIComponent.class);
+    }
+}

Reply via email to