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.eclipse.aether.internal.impl.synccontext.named;
20  
21  import java.util.Collection;
22  import java.util.Iterator;
23  
24  import org.eclipse.aether.artifact.DefaultArtifact;
25  import org.eclipse.aether.metadata.DefaultMetadata;
26  import org.eclipse.aether.metadata.Metadata;
27  import org.junit.jupiter.api.Test;
28  
29  import static java.util.Collections.emptyList;
30  import static java.util.Collections.singletonList;
31  import static org.junit.jupiter.api.Assertions.assertEquals;
32  import static org.junit.jupiter.api.Assertions.assertTrue;
33  
34  public class GAVNameMapperTest extends NameMapperTestSupport {
35      NameMapper mapper = GAVNameMapper.fileGav();
36  
37      @Test
38      void nullsAndEmptyInputs() {
39          Collection<String> names;
40  
41          names = mapper.nameLocks(session, null, null);
42          assertTrue(names.isEmpty());
43  
44          names = mapper.nameLocks(session, null, emptyList());
45          assertTrue(names.isEmpty());
46  
47          names = mapper.nameLocks(session, emptyList(), null);
48          assertTrue(names.isEmpty());
49  
50          names = mapper.nameLocks(session, emptyList(), emptyList());
51          assertTrue(names.isEmpty());
52      }
53  
54      @Test
55      void singleArtifact() {
56          DefaultArtifact artifact = new DefaultArtifact("group:artifact:1.0");
57          Collection<String> names = mapper.nameLocks(session, singletonList(artifact), null);
58          assertEquals(names.size(), 1);
59          assertEquals(names.iterator().next(), "artifact~group~artifact~1.0.lock");
60      }
61  
62      @Test
63      void singleMetadata() {
64          DefaultMetadata metadata =
65                  new DefaultMetadata("group", "artifact", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
66          Collection<String> names = mapper.nameLocks(session, null, singletonList(metadata));
67          assertEquals(names.size(), 1);
68          assertEquals(names.iterator().next(), "metadata~group~artifact.lock");
69      }
70  
71      @Test
72      void oneAndOne() {
73          DefaultArtifact artifact = new DefaultArtifact("agroup:artifact:1.0");
74          DefaultMetadata metadata =
75                  new DefaultMetadata("bgroup", "artifact", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
76          Collection<String> names = mapper.nameLocks(session, singletonList(artifact), singletonList(metadata));
77  
78          assertEquals(names.size(), 2);
79          Iterator<String> namesIterator = names.iterator();
80  
81          // they are sorted as well
82          assertEquals(namesIterator.next(), "artifact~agroup~artifact~1.0.lock");
83          assertEquals(namesIterator.next(), "metadata~bgroup~artifact.lock");
84      }
85  }