1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
package com.jeantessier.dependency; |
34 | |
|
35 | |
import java.util.*; |
36 | |
|
37 | |
import org.jmock.*; |
38 | |
import org.jmock.integration.junit4.*; |
39 | |
import org.jmock.lib.legacy.*; |
40 | |
import org.junit.*; |
41 | |
import org.junit.runner.*; |
42 | |
|
43 | |
@RunWith(JMock.class) |
44 | 34 | public class TestBasicTraversal { |
45 | |
private Mockery context; |
46 | |
|
47 | |
private Visitor delegate; |
48 | |
|
49 | |
private PackageNode packageNode; |
50 | |
private ClassNode classNode; |
51 | |
private FeatureNode featureNode; |
52 | |
|
53 | |
private BasicTraversal sut; |
54 | |
|
55 | |
@Before |
56 | |
public void setUp() { |
57 | 12 | context = new Mockery(); |
58 | 12 | context.setImposteriser(ClassImposteriser.INSTANCE); |
59 | |
|
60 | 12 | delegate = context.mock(Visitor.class); |
61 | |
|
62 | 12 | packageNode = context.mock(PackageNode.class); |
63 | 12 | classNode = context.mock(ClassNode.class); |
64 | 12 | featureNode = context.mock(FeatureNode.class); |
65 | |
|
66 | 12 | sut = new BasicTraversal(); |
67 | 12 | sut.setDelegate(delegate); |
68 | 12 | } |
69 | |
|
70 | |
@Test |
71 | |
public void testTraverseNodes_CallsAcceptDelegateOnNodes() { |
72 | 1 | final Collection<PackageNode> nodes = Collections.singleton(packageNode); |
73 | |
|
74 | 1 | context.checking(new Expectations() {{ |
75 | 1 | one (packageNode).accept(delegate); |
76 | 1 | }}); |
77 | |
|
78 | 1 | sut.traverseNodes(nodes); |
79 | 1 | } |
80 | |
|
81 | |
@Test |
82 | |
public void testTraverseInbound() { |
83 | 1 | final Collection<PackageNode> nodes = Collections.singleton(packageNode); |
84 | |
|
85 | 1 | context.checking(new Expectations() {{ |
86 | 1 | one (packageNode).acceptInbound(delegate); |
87 | 1 | }}); |
88 | |
|
89 | 1 | sut.traverseInbound(nodes); |
90 | 1 | } |
91 | |
|
92 | |
@Test |
93 | |
public void testTraverseOutbound() { |
94 | 1 | final Collection<PackageNode> nodes = Collections.singleton(packageNode); |
95 | |
|
96 | 1 | context.checking(new Expectations() {{ |
97 | 1 | one (packageNode).acceptOutbound(delegate); |
98 | 1 | }}); |
99 | |
|
100 | 1 | sut.traverseOutbound(nodes); |
101 | 1 | } |
102 | |
|
103 | |
@Test |
104 | |
public void testVisitPackageNode_DelegatesTraversalOfInboundsAndOutboundsAndClasses() { |
105 | 1 | final Collection<ClassNode> nodes = Collections.singleton(classNode); |
106 | |
|
107 | 1 | context.checking(new Expectations() {{ |
108 | |
|
109 | 1 | one (packageNode).getInboundDependencies(); |
110 | 1 | will(returnValue(nodes)); |
111 | 1 | one (delegate).traverseInbound(nodes); |
112 | |
|
113 | |
|
114 | 1 | one (packageNode).getOutboundDependencies(); |
115 | 1 | will(returnValue(nodes)); |
116 | 1 | one (delegate).traverseOutbound(nodes); |
117 | |
|
118 | |
|
119 | 1 | one (packageNode).getClasses(); |
120 | 1 | will(returnValue(nodes)); |
121 | 1 | one (delegate).traverseNodes(nodes); |
122 | 1 | }}); |
123 | |
|
124 | 1 | sut.visitPackageNode(packageNode); |
125 | 1 | } |
126 | |
|
127 | |
@Test |
128 | |
public void testVisitInboundPackageNode_DoesNothing() { |
129 | 1 | sut.visitInboundPackageNode(packageNode); |
130 | 1 | } |
131 | |
|
132 | |
@Test |
133 | |
public void testVisitOutboundPackageNode_DoesNothing() { |
134 | 1 | sut.visitOutboundPackageNode(packageNode); |
135 | 1 | } |
136 | |
|
137 | |
@Test |
138 | |
public void testVisitClassNode_DelegatesTraversalOfInboundsAndOutboundsAndClasses() { |
139 | 1 | final Collection<FeatureNode> nodes = Collections.singleton(featureNode); |
140 | |
|
141 | 1 | context.checking(new Expectations() {{ |
142 | |
|
143 | 1 | one (classNode).getInboundDependencies(); |
144 | 1 | will(returnValue(nodes)); |
145 | 1 | one (delegate).traverseInbound(nodes); |
146 | |
|
147 | |
|
148 | 1 | one (classNode).getOutboundDependencies(); |
149 | 1 | will(returnValue(nodes)); |
150 | 1 | one (delegate).traverseOutbound(nodes); |
151 | |
|
152 | |
|
153 | 1 | one (classNode).getFeatures(); |
154 | 1 | will(returnValue(nodes)); |
155 | 1 | one (delegate).traverseNodes(nodes); |
156 | 1 | }}); |
157 | |
|
158 | 1 | sut.visitClassNode(classNode); |
159 | 1 | } |
160 | |
|
161 | |
@Test |
162 | |
public void testVisitInboundClassNode_DoesNothing() { |
163 | 1 | sut.visitInboundClassNode(classNode); |
164 | 1 | } |
165 | |
|
166 | |
@Test |
167 | |
public void testVisitOutboundClassNode_DoesNothing() { |
168 | 1 | sut.visitOutboundClassNode(classNode); |
169 | 1 | } |
170 | |
|
171 | |
@Test |
172 | |
public void testVisitFeatureNode_InScope() { |
173 | 1 | final Collection<ClassNode> nodes = Collections.singleton(classNode); |
174 | |
|
175 | 1 | context.checking(new Expectations() {{ |
176 | |
|
177 | 1 | one (featureNode).getInboundDependencies(); |
178 | 1 | will(returnValue(nodes)); |
179 | 1 | one (delegate).traverseInbound(nodes); |
180 | |
|
181 | |
|
182 | 1 | one (featureNode).getOutboundDependencies(); |
183 | 1 | will(returnValue(nodes)); |
184 | 1 | one (delegate).traverseOutbound(nodes); |
185 | 1 | }}); |
186 | |
|
187 | 1 | sut.visitFeatureNode(featureNode); |
188 | 1 | } |
189 | |
|
190 | |
@Test |
191 | |
public void testVisitInboundFeatureNode_DoesNothing() { |
192 | 1 | sut.visitInboundFeatureNode(featureNode); |
193 | 1 | } |
194 | |
|
195 | |
@Test |
196 | |
public void testVisitOutboundFeatureNode_DoesNothing() { |
197 | 1 | sut.visitOutboundFeatureNode(featureNode); |
198 | 1 | } |
199 | |
} |