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