View Javadoc
1   package org.apache.maven.project.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 static org.junit.Assert.assertArrayEquals;
23  
24  import java.util.LinkedHashSet;
25  import java.util.Set;
26  
27  import org.apache.maven.artifact.Artifact;
28  import org.apache.maven.artifact.DefaultArtifact;
29  import org.codehaus.plexus.PlexusTestCase;
30  
31  public class DefaultProjectArtifactsCacheTest extends PlexusTestCase
32  {
33      
34      private ProjectArtifactsCache cache;
35  
36      @Override
37      protected void setUp()
38          throws Exception
39      {
40          super.setUp();
41          cache = lookup( ProjectArtifactsCache.class );
42      }
43      
44      public void testProjectDependencyOrder() throws Exception
45      {
46          ProjectArtifactsCache.Key project1 = new ProjectArtifactsCache.Key(){};
47          
48          Set<Artifact> artifacts = new LinkedHashSet<>( 4 );
49          artifacts.add( new DefaultArtifact( "g", "a1", "v", "compile", "jar", "", null ) );
50          artifacts.add( new DefaultArtifact( "g", "a2", "v", "compile", "jar", "", null ) );
51          artifacts.add( new DefaultArtifact( "g", "a3", "v", "compile", "jar", "", null ) );
52          artifacts.add( new DefaultArtifact( "g", "a4", "v", "compile", "jar", "", null ) );
53          
54          cache.put( project1, artifacts );
55          
56          assertArrayEquals( artifacts.toArray( new Artifact[0] ),
57                             cache.get( project1 ).getArtifacts().toArray( new Artifact[0] ) );
58          
59          ProjectArtifactsCache.Key project2 = new ProjectArtifactsCache.Key(){};
60          
61          Set<Artifact> reversedArtifacts = new LinkedHashSet<>( 4 );
62          artifacts.add( new DefaultArtifact( "g", "a4", "v", "compile", "jar", "", null ) );
63          artifacts.add( new DefaultArtifact( "g", "a3", "v", "compile", "jar", "", null ) );
64          artifacts.add( new DefaultArtifact( "g", "a2", "v", "compile", "jar", "", null ) );
65          artifacts.add( new DefaultArtifact( "g", "a1", "v", "compile", "jar", "", null ) );
66          
67          cache.put( project2, reversedArtifacts );
68          
69          assertArrayEquals( reversedArtifacts.toArray( new Artifact[0] ),
70                             cache.get( project2 ).getArtifacts().toArray( new Artifact[0] ) );
71      }
72  }