Skip to content

Commit 313eb77

Browse files
committed
Add UT
1 parent 8ae86c8 commit 313eb77

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,41 @@ public void testDeployIfArtifactIsNotJar() throws Exception {
276276
assertTrue(file.exists());
277277
}
278278

279+
public void testDeployFileIfPackagingIsSet() throws Exception {
280+
File testPom = new File(getBasedir(), "target/test-classes/unit/deploy-file-packaging/plugin-config.xml");
281+
mojo = (DeployFileMojo) lookupMojo("deploy-file", testPom);
282+
283+
openMocks = MockitoAnnotations.openMocks(this);
284+
285+
assertNotNull(mojo);
286+
287+
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
288+
repositorySession.setLocalRepositoryManager(
289+
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
290+
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
291+
when(session.getRepositorySession()).thenReturn(repositorySession);
292+
293+
String packaging = (String) getVariableValueFromObject(mojo, "packaging");
294+
295+
String groupId = (String) getVariableValueFromObject(mojo, "groupId");
296+
297+
String artifactId = (String) getVariableValueFromObject(mojo, "artifactId");
298+
299+
String version = (String) getVariableValueFromObject(mojo, "version");
300+
301+
assertEquals("differentpackaging", packaging);
302+
303+
mojo.execute();
304+
305+
File deployedArtifact = new File(
306+
remoteRepo,
307+
"deploy-file-packaging/" + groupId.replace('.', '/') + "/"
308+
+ artifactId + "/" + version + "/" + artifactId + "-"
309+
+ version + "." + packaging);
310+
311+
assertTrue(deployedArtifact.exists());
312+
}
313+
279314
private void addFileToList(File file, List<String> fileList) {
280315
if (!file.isDirectory()) {
281316
fileList.add(file.getName());
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
http://www.apache.org/licenses/LICENSE-2.0
10+
Unless required by applicable law or agreed to in writing,
11+
software distributed under the License is distributed on an
12+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13+
KIND, either express or implied. See the License for the
14+
specific language governing permissions and limitations
15+
under the License.
16+
-->
17+
18+
<project>
19+
<build>
20+
<plugins>
21+
<plugin>
22+
<artifactId>maven-deploy-plugin</artifactId>
23+
<configuration>
24+
<groupId>org.apache.maven.test</groupId>
25+
<artifactId>maven-deploy-file-test</artifactId>
26+
<version>1.0</version>
27+
<packaging>differentpackaging</packaging>
28+
<file>${basedir}/src/test/resources/unit/deploy-file-packaging/target/deploy-test-file-1.0-SNAPSHOT.jar</file>
29+
<repositoryId>deploy-test</repositoryId>
30+
<url>file://${basedir}/target/remote-repo/deploy-file-packaging</url>
31+
<generatePom>true</generatePom>
32+
</configuration>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
</project>

0 commit comments

Comments
 (0)