View Javadoc
1   package org.apache.maven.plugins.assembly.artifact;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.DefaultArtifact;
24  import org.apache.maven.artifact.handler.DefaultArtifactHandler;
25  import org.apache.maven.artifact.versioning.VersionRange;
26  import org.junit.Test;
27  
28  import java.util.Arrays;
29  import java.util.Collections;
30  import java.util.HashSet;
31  
32  import static org.junit.Assert.assertEquals;
33  
34  public class ResolutionManagementInfoTest
35  {
36  
37      @Test
38      public void testAddSingleArtifactWithReplacemen()
39          throws Exception
40      {
41          ResolutionManagementInfo rmi = new ResolutionManagementInfo();
42          Artifact a1 = new DefaultArtifact( "groupid", "1", VersionRange.createFromVersion( "1.0" ), "test", "jar", null,
43                                             new DefaultArtifactHandler() );
44          rmi.addArtifacts( Collections.singleton( a1 ) );
45          Artifact a2 =
46              new DefaultArtifact( "groupid", "1", VersionRange.createFromVersion( "1.0" ), "compile", "jar", null,
47                                   new DefaultArtifactHandler() );
48          rmi.addArtifacts( Collections.singleton( a2 ) );
49          assertEquals( 1, rmi.getArtifacts().size() );
50          Artifact next = rmi.getArtifacts().iterator().next();
51          assertEquals( "compile", next.getScope() );
52      }
53  
54      @Test
55      public void testAddMultiArtifactWithReplacemen()
56          throws Exception
57      {
58          ResolutionManagementInfo rmi = new ResolutionManagementInfo();
59          Artifact a1 =
60              new DefaultArtifact( "groupid", "a1", VersionRange.createFromVersion( "1.0" ), "test", "jar", null,
61                                   new DefaultArtifactHandler() );
62          Artifact a2 =
63              new DefaultArtifact( "groupid", "a2", VersionRange.createFromVersion( "1.0" ), "test", "jar", null,
64                                   new DefaultArtifactHandler() );
65          Artifact a3 =
66              new DefaultArtifact( "groupid", "a3", VersionRange.createFromVersion( "1.0" ), "test", "jar", null,
67                                   new DefaultArtifactHandler() );
68          rmi.addArtifacts( new HashSet<>( Arrays.asList( a1, a2, a3 ) ) );
69          Artifact b2 =
70              new DefaultArtifact( "groupid", "a2", VersionRange.createFromVersion( "1.0" ), "compile", "jar", null,
71                                   new DefaultArtifactHandler() );
72          Artifact b3 =
73              new DefaultArtifact( "groupid", "a3", VersionRange.createFromVersion( "1.0" ), "compile", "jar", null,
74                                   new DefaultArtifactHandler() );
75          rmi.addArtifacts( new HashSet<>( Arrays.asList( b2, b3 ) ) );
76          assertEquals( 3, rmi.getArtifacts().size() );
77          int compile = 0;
78          int test = 0;
79          for ( Artifact artifact : rmi.getArtifacts() )
80          {
81              if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) )
82              {
83                  compile++;
84              }
85              else
86              {
87                  test++;
88              }
89          }
90          assertEquals( 2, compile );
91          assertEquals( 1, test );
92      }
93  }