2121import java .io .File ;
2222import java .nio .file .Files ;
2323import java .nio .file .Path ;
24+ import java .nio .file .Paths ;
2425import java .util .ArrayList ;
2526import java .util .List ;
2627import java .util .concurrent .atomic .AtomicReference ;
3334import org .apache .maven .api .Session ;
3435import org .apache .maven .api .model .Model ;
3536import org .apache .maven .api .plugin .testing .InjectMojo ;
37+ import org .apache .maven .api .plugin .testing .MojoExtension ;
38+ import org .apache .maven .api .plugin .testing .MojoParameter ;
3639import org .apache .maven .api .plugin .testing .MojoTest ;
3740import org .apache .maven .api .plugin .testing .stubs .ArtifactStub ;
3841import org .apache .maven .api .plugin .testing .stubs .SessionStub ;
4144import org .apache .maven .api .services .ArtifactManager ;
4245import org .apache .maven .api .services .ProjectBuilder ;
4346import org .apache .maven .api .services .ProjectManager ;
47+ import org .apache .maven .internal .impl .InternalSession ;
4448import org .junit .jupiter .api .Test ;
4549
4650import static org .apache .maven .api .plugin .testing .MojoExtension .getVariableValueFromObject ;
5054import static org .junit .jupiter .api .Assertions .assertTrue ;
5155import static org .mockito .ArgumentMatchers .any ;
5256import static org .mockito .Mockito .doAnswer ;
57+ import static org .mockito .Mockito .when ;
5358
5459/**
5560 * @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
@@ -71,13 +76,25 @@ public class DeployFileMojoTest {
7176 private ArtifactManager artifactManager ;
7277
7378 @ Test
74- @ InjectMojo (goal = "deploy-file" , pom = "classpath:/unit/deploy-file/plugin-config-test.xml" )
79+ @ InjectMojo (goal = "deploy-file" )
7580 public void testDeployTestEnvironment (DeployFileMojo mojo ) {
7681 assertNotNull (mojo );
7782 }
7883
7984 @ Test
80- @ InjectMojo (goal = "deploy-file" , pom = "classpath:/unit/deploy-file/plugin-config-test.xml" )
85+ @ InjectMojo (goal = "deploy-file" )
86+ @ MojoParameter (name = "groupId" , value = "org.apache.maven.test" )
87+ @ MojoParameter (name = "artifactId" , value = "maven-deploy-file-test" )
88+ @ MojoParameter (name = "version" , value = "1.0" )
89+ @ MojoParameter (name = "packaging" , value = "jar" )
90+ @ MojoParameter (
91+ name = "file" ,
92+ value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test-1.0-SNAPSHOT.jar" )
93+ @ MojoParameter (name = "repositoryId" , value = "deploy-test" )
94+ @ MojoParameter (name = "url" , value = "file://${session.topDirectory}/target/remote-repo/deploy-file" )
95+ @ MojoParameter (name = "description" , value = "POM was created from deploy:deploy-file" )
96+ @ MojoParameter (name = "generatePom" , value = "true" )
97+ @ MojoParameter (name = "skip" , value = "snapshots" )
8198 public void testBasicDeployFile (DeployFileMojo mojo ) throws Exception {
8299 assertNotNull (mojo );
83100
@@ -93,9 +110,9 @@ public void testBasicDeployFile(DeployFileMojo mojo) throws Exception {
93110 assertEquals ("maven-deploy-file-test" , artifactId );
94111 assertEquals ("1.0" , version );
95112 assertEquals ("jar" , packaging );
96- assertTrue (Files .exists (file ));
113+ assertTrue (Files .exists (file ), file . toString () );
97114 assertEquals ("deploy-test" , repositoryId );
98- assertEquals ("file://" + getBasedir () + "/target/remote-repo/deploy-file-test " , url );
115+ assertEquals ("file://" + getBasedir () + "/target/remote-repo/deploy-file" , url );
99116
100117 execute (mojo , request -> {
101118 assertNotNull (request );
@@ -128,7 +145,18 @@ public void testBasicDeployFile(DeployFileMojo mojo) throws Exception {
128145 }
129146
130147 @ Test
131- @ InjectMojo (goal = "deploy-file" , pom = "classpath:/unit/deploy-file/plugin-config-classifier.xml" )
148+ @ InjectMojo (goal = "deploy-file" )
149+ @ MojoParameter (name = "groupId" , value = "org.apache.maven.test" )
150+ @ MojoParameter (name = "artifactId" , value = "maven-deploy-file-test" )
151+ @ MojoParameter (name = "version" , value = "1.0" )
152+ @ MojoParameter (name = "packaging" , value = "jar" )
153+ @ MojoParameter (
154+ name = "file" ,
155+ value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test-1.0-SNAPSHOT.jar" )
156+ @ MojoParameter (name = "repositoryId" , value = "deploy-test" )
157+ @ MojoParameter (name = "url" , value = "file://${session.topDirectory}/target/remote-repo/deploy-file" )
158+ @ MojoParameter (name = "classifier" , value = "bin" )
159+ @ MojoParameter (name = "generatePom" , value = "true" )
132160 public void testDeployIfClassifierIsSet (DeployFileMojo mojo ) throws Exception {
133161 assertNotNull (mojo );
134162
@@ -149,7 +177,7 @@ public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception {
149177 assertEquals (new ArtifactStub (groupId , artifactId , "bin" , version , "jar" ), a1 );
150178 Path p1 = artifactManager .getPath (a1 ).orElse (null );
151179 assertNotNull (p1 );
152- assertTrue (p1 .toString ().endsWith ("deploy-test-file -1.0-SNAPSHOT.jar" ));
180+ assertTrue (p1 .toString ().endsWith ("maven- deploy-test-1.0-SNAPSHOT.jar" ));
153181 // second artifact
154182 Artifact a2 = artifacts .get (1 );
155183 assertEquals (new ArtifactStub (groupId , artifactId , "" , version , "pom" ), a2 );
@@ -162,7 +190,14 @@ public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception {
162190 }
163191
164192 @ Test
165- @ InjectMojo (goal = "deploy-file" , pom = "classpath:/unit/deploy-file/plugin-config-artifact-not-jar.xml" )
193+ @ InjectMojo (goal = "deploy-file" )
194+ @ MojoParameter (name = "groupId" , value = "org.apache.maven.test" )
195+ @ MojoParameter (name = "artifactId" , value = "maven-deploy-file-test" )
196+ @ MojoParameter (name = "version" , value = "1.0" )
197+ @ MojoParameter (name = "file" , value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test.zip" )
198+ @ MojoParameter (name = "repositoryId" , value = "deploy-test" )
199+ @ MojoParameter (name = "url" , value = "file://${session.topDirectory}/target/remote-repo/deploy-file" )
200+ @ MojoParameter (name = "generatePom" , value = "true" )
166201 public void testDeployIfArtifactIsNotJar (DeployFileMojo mojo ) throws Exception {
167202 assertNotNull (mojo );
168203
@@ -183,7 +218,7 @@ public void testDeployIfArtifactIsNotJar(DeployFileMojo mojo) throws Exception {
183218 Path p1 = artifactManager .getPath (a1 ).orElse (null );
184219 Path p2 = artifactManager .getPath (a2 ).orElse (null );
185220 assertNotNull (p1 );
186- assertTrue (p1 .toString ().endsWith ("deploy-test-file .zip" ));
221+ assertTrue (p1 .toString ().endsWith ("maven- deploy-test.zip" ));
187222 assertNotNull (p2 );
188223 assertTrue (p2 .toString ().endsWith (".pom" ));
189224
@@ -213,31 +248,33 @@ private void execute(DeployFileMojo mojo, Consumer<ArtifactDeployerRequest> cons
213248 @ Provides
214249 @ Singleton
215250 @ SuppressWarnings ("unused" )
216- private Session getMockSession () {
217- return SessionStub .getMockSession (LOCAL_REPO );
251+ private InternalSession createSession () {
252+ InternalSession session = SessionStub .getMockSession (LOCAL_REPO );
253+ when (session .getTopDirectory ()).thenReturn (Paths .get (MojoExtension .getBasedir ()));
254+ return session ;
218255 }
219256
220257 @ Provides
221258 @ SuppressWarnings ("unused" )
222- private ArtifactDeployer getMockArtifactDeployer (Session session ) {
259+ private ArtifactDeployer createArtifactDeployer (Session session ) {
223260 return session .getService (ArtifactDeployer .class );
224261 }
225262
226263 @ Provides
227264 @ SuppressWarnings ("unused" )
228- private ArtifactManager getMockArtifactManager (Session session ) {
265+ private ArtifactManager createArtifactManager (Session session ) {
229266 return session .getService (ArtifactManager .class );
230267 }
231268
232269 @ Provides
233270 @ SuppressWarnings ("unused" )
234- private ProjectManager getMockProjectManager (Session session ) {
271+ private ProjectManager createProjectManager (Session session ) {
235272 return session .getService (ProjectManager .class );
236273 }
237274
238275 @ Provides
239276 @ SuppressWarnings ("unused" )
240- private ProjectBuilder getMockProjectBuilder (Session session ) {
277+ private ProjectBuilder createProjectBuilder (Session session ) {
241278 return session .getService (ProjectBuilder .class );
242279 }
243280}
0 commit comments