View Javadoc
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.plugins.assembly.artifact;
20  
21  import java.util.Arrays;
22  import java.util.Collections;
23  import java.util.HashSet;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.artifact.DefaultArtifact;
27  import org.apache.maven.artifact.handler.DefaultArtifactHandler;
28  import org.apache.maven.artifact.versioning.VersionRange;
29  import org.junit.Test;
30  
31  import static org.junit.Assert.assertEquals;
32  
33  public class ResolutionManagementInfoTest {
34  
35      @Test
36      public void testAddSingleArtifactWithReplacemen() throws Exception {
37          ResolutionManagementInfo rmi = new ResolutionManagementInfo();
38          Artifact a1 = new DefaultArtifact(
39                  "groupid",
40                  "1",
41                  VersionRange.createFromVersion("1.0"),
42                  "test",
43                  "jar",
44                  null,
45                  new DefaultArtifactHandler());
46          rmi.addArtifacts(Collections.singleton(a1));
47          Artifact a2 = new DefaultArtifact(
48                  "groupid",
49                  "1",
50                  VersionRange.createFromVersion("1.0"),
51                  "compile",
52                  "jar",
53                  null,
54                  new DefaultArtifactHandler());
55          rmi.addArtifacts(Collections.singleton(a2));
56          assertEquals(1, rmi.getArtifacts().size());
57          Artifact next = rmi.getArtifacts().iterator().next();
58          assertEquals("compile", next.getScope());
59      }
60  
61      @Test
62      public void testAddMultiArtifactWithReplacemen() throws Exception {
63          ResolutionManagementInfo rmi = new ResolutionManagementInfo();
64          Artifact a1 = new DefaultArtifact(
65                  "groupid",
66                  "a1",
67                  VersionRange.createFromVersion("1.0"),
68                  "test",
69                  "jar",
70                  null,
71                  new DefaultArtifactHandler());
72          Artifact a2 = new DefaultArtifact(
73                  "groupid",
74                  "a2",
75                  VersionRange.createFromVersion("1.0"),
76                  "test",
77                  "jar",
78                  null,
79                  new DefaultArtifactHandler());
80          Artifact a3 = new DefaultArtifact(
81                  "groupid",
82                  "a3",
83                  VersionRange.createFromVersion("1.0"),
84                  "test",
85                  "jar",
86                  null,
87                  new DefaultArtifactHandler());
88          rmi.addArtifacts(new HashSet<>(Arrays.asList(a1, a2, a3)));
89          Artifact b2 = new DefaultArtifact(
90                  "groupid",
91                  "a2",
92                  VersionRange.createFromVersion("1.0"),
93                  "compile",
94                  "jar",
95                  null,
96                  new DefaultArtifactHandler());
97          Artifact b3 = new DefaultArtifact(
98                  "groupid",
99                  "a3",
100                 VersionRange.createFromVersion("1.0"),
101                 "compile",
102                 "jar",
103                 null,
104                 new DefaultArtifactHandler());
105         rmi.addArtifacts(new HashSet<>(Arrays.asList(b2, b3)));
106         assertEquals(3, rmi.getArtifacts().size());
107         int compile = 0;
108         int test = 0;
109         for (Artifact artifact : rmi.getArtifacts()) {
110             if (Artifact.SCOPE_COMPILE.equals(artifact.getScope())) {
111                 compile++;
112             } else {
113                 test++;
114             }
115         }
116         assertEquals(2, compile);
117         assertEquals(1, test);
118     }
119 }