1   package org.apache.maven.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 java.util.ArrayList;
23  import java.util.List;
24  import java.util.Map;
25  
26  import org.apache.maven.artifact.versioning.VersionRange;
27  
28  import junit.framework.TestCase;
29  
30  /**
31   * Tests {@link ArtifactUtils}.
32   * 
33   * @author Benjamin Bentmann
34   * @version $Id: ArtifactUtilsTest.java 742050 2009-02-08 11:03:25Z bentmann $
35   */
36  public class ArtifactUtilsTest
37      extends TestCase
38  {
39  
40      /**
41       * Tests that the ordering of the map resembles the ordering of the input collection of artifacts.
42       */
43      public void testArtifactMapByArtifactIdOrdering()
44          throws Exception
45      {
46          List list = new ArrayList();
47          list.add( newArtifact( "b" ) );
48          list.add( newArtifact( "a" ) );
49          list.add( newArtifact( "c" ) );
50          list.add( newArtifact( "e" ) );
51          list.add( newArtifact( "d" ) );
52  
53          Map map = ArtifactUtils.artifactMapByArtifactId( list );
54          assertNotNull( map );
55          assertEquals( list, new ArrayList( map.values() ) );
56      }
57  
58      /**
59       * Tests that the ordering of the map resembles the ordering of the input collection of artifacts.
60       */
61      public void testArtifactMapByVersionlessIdOrdering()
62          throws Exception
63      {
64          List list = new ArrayList();
65          list.add( newArtifact( "b" ) );
66          list.add( newArtifact( "a" ) );
67          list.add( newArtifact( "c" ) );
68          list.add( newArtifact( "e" ) );
69          list.add( newArtifact( "d" ) );
70  
71          Map map = ArtifactUtils.artifactMapByVersionlessId( list );
72          assertNotNull( map );
73          assertEquals( list, new ArrayList( map.values() ) );
74      }
75  
76      private Artifact newArtifact( String aid )
77      {
78          return new DefaultArtifact( "org.apache.maven.ut", aid, VersionRange.createFromVersion( "1.0" ), "test", "jar",
79                                      "tests", null );
80      }
81  
82  }