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