1 package org.apache.maven.shared.dependency.tree.traversal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.StringWriter;
23
24 import org.apache.maven.shared.dependency.tree.AbstractDependencyNodeTest;
25 import org.apache.maven.shared.dependency.tree.DependencyNode;
26
27
28
29
30
31
32
33
34 public class SerializingDependencyNodeVisitorTest
35 extends AbstractDependencyNodeTest
36 {
37
38
39 private static final String NEWLINE = System.getProperty( "line.separator" );
40
41
42
43 private StringWriter writer;
44
45 private SerializingDependencyNodeVisitor serializer;
46
47
48
49
50
51
52 protected void setUp()
53 throws Exception
54 {
55 writer = new StringWriter();
56
57 serializer = new SerializingDependencyNodeVisitor( writer, SerializingDependencyNodeVisitor.STANDARD_TOKENS );
58 }
59
60
61
62 public void testSingleNode()
63 {
64 DependencyNode rootNode = createNode( "g:p:t:1" );
65
66 assertTree( "g:p:t:1" + NEWLINE, rootNode );
67 }
68
69 public void testNodeWithChild()
70 {
71 DependencyNode rootNode = createNode( "g:p:t:1" );
72 rootNode.addChild( createNode( "g:a:t:1" ) );
73
74 assertTree(
75 "g:p:t:1" + NEWLINE +
76 "\\- g:a:t:1" + NEWLINE,
77 rootNode );
78 }
79
80 public void testNodeWithMultipleChildren()
81 {
82 DependencyNode rootNode = createNode( "g:p:t:1" );
83 rootNode.addChild( createNode( "g:a:t:1" ) );
84 rootNode.addChild( createNode( "g:b:t:1" ) );
85 rootNode.addChild( createNode( "g:c:t:1" ) );
86
87 assertTree(
88 "g:p:t:1" + NEWLINE +
89 "+- g:a:t:1" + NEWLINE +
90 "+- g:b:t:1" + NEWLINE +
91 "\\- g:c:t:1" + NEWLINE,
92 rootNode );
93 }
94
95 public void testNodeWithGrandchild()
96 {
97 DependencyNode rootNode = createNode( "g:p:t:1" );
98 DependencyNode childNode = createNode( "g:a:t:1" );
99 rootNode.addChild( childNode );
100 childNode.addChild( createNode( "g:b:t:1" ) );
101
102 assertTree(
103 "g:p:t:1" + NEWLINE +
104 "\\- g:a:t:1" + NEWLINE +
105 " \\- g:b:t:1" + NEWLINE,
106 rootNode );
107 }
108
109 public void testNodeWithMultipleGrandchildren()
110 {
111 DependencyNode rootNode = createNode( "g:p:t:1" );
112 DependencyNode child1Node = createNode( "g:a:t:1" );
113 rootNode.addChild( child1Node );
114 child1Node.addChild( createNode( "g:b:t:1" ) );
115 DependencyNode child2Node = createNode( "g:c:t:1" );
116 rootNode.addChild( child2Node );
117 child2Node.addChild( createNode( "g:d:t:1" ) );
118
119 assertTree(
120 "g:p:t:1" + NEWLINE +
121 "+- g:a:t:1" + NEWLINE +
122 "| \\- g:b:t:1" + NEWLINE +
123 "\\- g:c:t:1" + NEWLINE +
124 " \\- g:d:t:1" + NEWLINE,
125 rootNode );
126 }
127
128
129
130 private void assertTree( String expectedTree, DependencyNode actualNode )
131 {
132 actualNode.accept( serializer );
133
134 assertEquals( expectedTree, writer.toString() );
135 }
136 }