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.visitor;
20
21 import java.io.File;
22 import java.util.List;
23
24 import org.eclipse.aether.graph.DependencyNode;
25 import org.eclipse.aether.graph.DependencyVisitor;
26 import org.eclipse.aether.internal.test.util.DependencyGraphParser;
27 import org.junit.Test;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertTrue;
31
32 public abstract class AbstractDepthFirstNodeListGeneratorTestSupport {
33
34 protected DependencyNode parse(String resource) throws Exception {
35 return new DependencyGraphParser("visitor/ordered-list/").parseResource(resource);
36 }
37
38 protected void assertSequence(List<DependencyNode> actual, String... expected) {
39 assertEquals(actual.toString(), expected.length, actual.size());
40 for (int i = 0; i < expected.length; i++) {
41 DependencyNode node = actual.get(i);
42 assertEquals(
43 actual.toString(),
44 expected[i],
45 node.getDependency().getArtifact().getArtifactId());
46 }
47 }
48
49 @Test
50 public void testClasspath() throws Exception {
51 DependencyNode root = parse("simple.txt");
52
53 PreorderNodeListGenerator visitor = new PreorderNodeListGenerator();
54 root.accept(visitor);
55
56 assertEquals(visitor.getClassPath(), "");
57 }
58
59 @Test
60 public void testFullyResolverClasspath() throws Exception {
61 DependencyNode root = parse("simple.txt");
62
63 DependencyVisitor fileSetter = new DependencyVisitor() {
64 @Override
65 public boolean visitEnter(DependencyNode node) {
66 node.setArtifact(
67 node.getArtifact().setFile(new File(node.getArtifact().getArtifactId())));
68 return true;
69 }
70
71 @Override
72 public boolean visitLeave(DependencyNode node) {
73 return true;
74 }
75 };
76 root.accept(fileSetter);
77
78 PreorderNodeListGenerator visitor = new PreorderNodeListGenerator();
79 root.accept(visitor);
80
81 String classpath = visitor.getClassPath();
82 assertEquals(5, classpath.split(File.pathSeparator).length);
83 for (File file : visitor.getFiles()) {
84 assertTrue("missing: " + file, classpath.contains(file.getAbsolutePath()));
85 }
86 }
87 }