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