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.junit3.*; |
39 |
| import org.jmock.lib.legacy.*; |
40 |
| |
41 |
| public class TestFeatureResolver extends MockObjectTestCase { |
42 |
| private FeatureResolver sut; |
43 |
| |
44 |
10
| protected void setUp() throws Exception {
|
45 |
10
| super.setUp();
|
46 |
| |
47 |
10
| setImposteriser(ClassImposteriser.INSTANCE);
|
48 |
| |
49 |
10
| sut = new FeatureResolver();
|
50 |
| } |
51 |
| |
52 |
1
| public void testTraverseNodes() {
|
53 |
1
| final Node mockNode1 = mock(Node.class, "node1");
|
54 |
1
| final Node mockNode2 = mock(Node.class, "node2");
|
55 |
| |
56 |
1
| final Collection<Node> nodes = new LinkedList<Node>();
|
57 |
1
| nodes.add(mockNode1);
|
58 |
1
| nodes.add(mockNode2);
|
59 |
| |
60 |
1
| checking(new Expectations() {{
|
61 |
1
| one (mockNode1).accept(sut);
|
62 |
1
| one (mockNode2).accept(sut);
|
63 |
| }}); |
64 |
| |
65 |
1
| sut.traverseNodes(nodes);
|
66 |
| } |
67 |
| |
68 |
1
| public void testVisitPackageNode() {
|
69 |
1
| final PackageNode mockPackageNode = mock(PackageNode.class);
|
70 |
1
| final ClassNode mockClassNode1 = mock(ClassNode.class, "class1");
|
71 |
1
| final ClassNode mockClassNode2 = mock(ClassNode.class, "class2");
|
72 |
| |
73 |
1
| final Collection<ClassNode> classes = new LinkedList<ClassNode>();
|
74 |
1
| classes.add(mockClassNode1);
|
75 |
1
| classes.add(mockClassNode2);
|
76 |
| |
77 |
1
| checking(new Expectations() {{
|
78 |
1
| one (mockPackageNode).getClasses();
|
79 |
1
| will(returnValue(classes));
|
80 |
1
| one (mockClassNode1).accept(sut);
|
81 |
1
| one (mockClassNode2).accept(sut);
|
82 |
| }}); |
83 |
| |
84 |
1
| sut.visitPackageNode(mockPackageNode);
|
85 |
| } |
86 |
| |
87 |
1
| public void testVisitInboundPackageNode() {
|
88 |
1
| final PackageNode mockPackageNode = mock(PackageNode.class);
|
89 |
1
| sut.visitInboundPackageNode(mockPackageNode);
|
90 |
| } |
91 |
| |
92 |
1
| public void testVisitOutboundPackageNode() {
|
93 |
1
| final PackageNode mockPackageNode = mock(PackageNode.class);
|
94 |
1
| sut.visitOutboundPackageNode(mockPackageNode);
|
95 |
| } |
96 |
| |
97 |
1
| public void testVisitClassNode() {
|
98 |
1
| final ClassNode mockClassNode = mock(ClassNode.class);
|
99 |
1
| final FeatureNode mockFeatureNode1 = mock(FeatureNode.class, "feature1");
|
100 |
1
| final FeatureNode mockFeatureNode2 = mock(FeatureNode.class, "feature2");
|
101 |
| |
102 |
1
| final Collection<FeatureNode> features = new LinkedList<FeatureNode>();
|
103 |
1
| features.add(mockFeatureNode1);
|
104 |
1
| features.add(mockFeatureNode2);
|
105 |
| |
106 |
1
| checking(new Expectations() {{
|
107 |
1
| one (mockClassNode).getFeatures();
|
108 |
1
| will(returnValue(features));
|
109 |
1
| one (mockFeatureNode1).accept(sut);
|
110 |
1
| one (mockFeatureNode2).accept(sut);
|
111 |
| }}); |
112 |
| |
113 |
1
| sut.visitClassNode(mockClassNode);
|
114 |
| } |
115 |
| |
116 |
1
| public void testVisitInboundClassNode() {
|
117 |
1
| final ClassNode mockClassNode = mock(ClassNode.class);
|
118 |
1
| sut.visitInboundClassNode(mockClassNode);
|
119 |
| } |
120 |
| |
121 |
1
| public void testVisitOutboundClassNode() {
|
122 |
1
| final ClassNode mockClassNode = mock(ClassNode.class);
|
123 |
1
| sut.visitOutboundClassNode(mockClassNode);
|
124 |
| } |
125 |
| |
126 |
1
| public void testVisitFeatureNode() {
|
127 |
1
| final String TARGET_SIMPLE_NAME = "target()";
|
128 |
1
| final String CHILD_NAME = "Child";
|
129 |
1
| final String CHILD_TARGET_NAME = CHILD_NAME + "." + TARGET_SIMPLE_NAME;
|
130 |
1
| final String PARENT_NAME = "Parent";
|
131 |
1
| final String PARENT_TARGET_NAME = PARENT_NAME + "." + TARGET_SIMPLE_NAME;
|
132 |
| |
133 |
1
| final FeatureNode mockCallerSource = mock(FeatureNode.class, "Caller.source()");
|
134 |
1
| final FeatureNode mockParentTarget = mock(FeatureNode.class, PARENT_TARGET_NAME);
|
135 |
1
| final ClassNode mockChild = mock(ClassNode.class, CHILD_NAME);
|
136 |
1
| final FeatureNode mockChildTarget = mock(FeatureNode.class, CHILD_TARGET_NAME);
|
137 |
| |
138 |
1
| checking(new Expectations() {{
|
139 |
1
| atLeast(1).of (mockChildTarget).getSimpleName();
|
140 |
1
| will(returnValue(TARGET_SIMPLE_NAME));
|
141 |
1
| atLeast(1).of (mockChildTarget).getClassNode();
|
142 |
1
| will(returnValue(mockChild));
|
143 |
1
| one (mockChild).getInheritedFeatures(TARGET_SIMPLE_NAME);
|
144 |
1
| will(returnValue(Collections.singleton(mockParentTarget)));
|
145 |
1
| one (mockChildTarget).getInboundDependencies();
|
146 |
1
| will(returnValue(Collections.singleton(mockCallerSource)));
|
147 |
1
| one (mockCallerSource).addDependency(mockParentTarget);
|
148 |
| }}); |
149 |
| |
150 |
1
| sut.visitFeatureNode(mockChildTarget);
|
151 |
| } |
152 |
| |
153 |
1
| public void testVisitInboundFeatureNode() {
|
154 |
1
| final FeatureNode mockFeatureNode = mock(FeatureNode.class);
|
155 |
1
| sut.visitInboundFeatureNode(mockFeatureNode);
|
156 |
| } |
157 |
| |
158 |
1
| public void testVisitOutboundFeatureNode() {
|
159 |
1
| final FeatureNode mockFeatureNode = mock(FeatureNode.class);
|
160 |
1
| sut.visitOutboundFeatureNode(mockFeatureNode);
|
161 |
| } |
162 |
| } |