1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.util.graph.transformer;
20
21 import java.util.Collection;
22 import java.util.LinkedList;
23 import java.util.List;
24 import java.util.Queue;
25
26 import org.eclipse.aether.collection.DependencyGraphTransformer;
27 import org.eclipse.aether.graph.DependencyNode;
28 import org.eclipse.aether.internal.test.util.DependencyGraphParser;
29 import org.junit.Test;
30
31 import static org.junit.Assert.*;
32
33
34
35 public class ConflictIdSorterTest extends AbstractDependencyGraphTransformerTest {
36
37 @Override
38 protected DependencyGraphTransformer newTransformer() {
39 return new ChainedDependencyGraphTransformer(new SimpleConflictMarker(), new ConflictIdSorter());
40 }
41
42 @Override
43 protected DependencyGraphParser newParser() {
44 return new DependencyGraphParser("transformer/conflict-id-sorter/");
45 }
46
47 private void expectOrder(List<String> sorted, String... ids) {
48 Queue<String> queue = new LinkedList<>(sorted);
49
50 for (String id : ids) {
51 String item = queue.poll();
52 assertNotNull(String.format("not enough conflict groups (no match for '%s'", id), item);
53
54 if (!"*".equals(id)) {
55 assertEquals(id, item);
56 }
57 }
58
59 assertTrue(String.format("leftover conflict groups (remaining: '%s')", queue), queue.isEmpty());
60 }
61
62 private void expectOrder(String... id) {
63 @SuppressWarnings("unchecked")
64 List<String> sorted = (List<String>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS);
65 expectOrder(sorted, id);
66 }
67
68 private void expectCycle(boolean cycle) {
69 Collection<?> cycles = (Collection<?>) context.get(TransformationContextKeys.CYCLIC_CONFLICT_IDS);
70 assertEquals(cycle, !cycles.isEmpty());
71 }
72
73 @Test
74 public void testSimple() throws Exception {
75 DependencyNode node = parseResource("simple.txt");
76 assertSame(node, transform(node));
77
78 expectOrder("gid2:aid::jar", "gid:aid::jar", "gid:aid2::jar");
79 expectCycle(false);
80 }
81
82 @Test
83 public void testCycle() throws Exception {
84 DependencyNode node = parseResource("cycle.txt");
85 assertSame(node, transform(node));
86
87 expectOrder("gid:aid::jar", "gid2:aid::jar");
88 expectCycle(true);
89 }
90
91 @Test
92 public void testCycles() throws Exception {
93 DependencyNode node = parseResource("cycles.txt");
94 assertSame(node, transform(node));
95
96 expectOrder("*", "*", "*", "gid:aid::jar");
97 expectCycle(true);
98 }
99
100 @Test
101 public void testNoConflicts() throws Exception {
102 DependencyNode node = parseResource("no-conflicts.txt");
103 assertSame(node, transform(node));
104
105 expectOrder("gid:aid::jar", "gid3:aid::jar", "gid2:aid::jar", "gid4:aid::jar");
106 expectCycle(false);
107 }
108 }