1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
83 assertEquals(namesIterator.next().name(), "artifact~agroup~artifact~1.0.lock");
84 assertEquals(namesIterator.next().name(), "metadata~bgroup~artifact.lock");
85 }
86 }