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