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 package name.angoca.zemucan.core.graph.model;
30
31 import name.angoca.zemucan.AbstractZemucanException;
32 import name.angoca.zemucan.core.graph.api.ChildEndingNodeException;
33 import name.angoca.zemucan.tools.Constants;
34 import name.angoca.zemucan.tools.test.RandomTestRunner;
35
36 import org.junit.Assert;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 @RunWith(RandomTestRunner.class)
70 public final class EndingNodeTest {
71
72
73
74 private static final String ENDING_NODE = "EndingNode";
75
76
77
78
79 public EndingNodeTest() {
80
81 }
82
83
84
85
86
87
88
89 @Test
90 public void testAddWay() throws AbstractZemucanException {
91 final EndingNode actual = new EndingNode(new Graph("test", false));
92
93 Exception e = null;
94 try {
95 actual.addChild(null);
96 } catch (final Exception exception) {
97 e = exception;
98 }
99 Assert.assertTrue("ChildEndingNodeException",
100 e instanceof ChildEndingNodeException);
101 }
102
103
104
105
106
107
108
109 @Test
110 public void testCongruent() throws AbstractZemucanException {
111 final Graph graph = new Graph("test", false);
112
113 final EndingNode node1 = new EndingNode(graph);
114 final int val1 = node1.hashCode();
115 final int val2 = node1.hashCode();
116
117 final boolean val = val1 == val2;
118
119 Assert.assertTrue("Two consecutive calls return the same value", val);
120 }
121
122
123
124
125
126
127
128 @Test
129 public void testDifferentStartingNodeHashCode()
130 throws AbstractZemucanException {
131 final Graph graph = new Graph("test", false);
132
133 final EndingNode actual = new EndingNode(graph);
134 final StartingNode notExpected = new StartingNode(graph);
135
136 final boolean condition = notExpected.hashCode() == actual.hashCode();
137
138 Assert.assertFalse(
139 "EndingNode has a hashcode different to StartingNode",
140 condition);
141 }
142
143
144
145
146
147
148
149 @Test
150 public void testEqualsNodeNotReserved() throws AbstractZemucanException {
151 final String node = EndingNodeTest.ENDING_NODE;
152 final Graph graph = new Graph("test", false);
153
154 final EndingNode actual = new EndingNode(graph);
155 final GraphNode notExpected = new GraphNode(node, graph);
156
157 Assert.assertFalse(
158 "Equals between EndingNode and a non reserved GraphNode",
159 actual.equals(notExpected));
160 Assert.assertFalse(
161 "Equals between EndingNode and a non reserved GraphNode 2",
162 notExpected.equals(actual));
163 }
164
165
166
167
168
169
170
171 @Test
172 public void testEqualsNodeReserved() throws AbstractZemucanException {
173 final String node = EndingNodeTest.ENDING_NODE;
174 final Graph graph = new Graph("test", false);
175
176 final EndingNode actual = new EndingNode(graph);
177 final GraphNode notExpected = new GraphNode(node, graph);
178
179 Assert.assertFalse(
180 "Equals between EndingNode and a reserved GraphNode",
181 actual.equals(notExpected));
182 Assert.assertFalse(
183 "Equals between EndingNode and a reserved GraphNode 2",
184 notExpected.equals(actual));
185 }
186
187
188
189
190
191
192
193 @Test
194 public void testHashCode() throws AbstractZemucanException {
195 final EndingNode actual = new EndingNode(new Graph("test", false));
196
197 Assert.assertTrue("HashCode different to 1",
198 1 != actual.hashCode());
199 Assert.assertTrue("HashCode different to 0",
200 0 != actual.hashCode());
201 Assert.assertTrue("HashCode different to -1",
202 -1 != actual.hashCode());
203 }
204
205
206
207
208
209
210
211 @Test
212 public void testNullEqualsObject() throws AbstractZemucanException {
213 final EndingNode actual = new EndingNode(new Graph("test", false));
214
215 final EndingNode nullObject = null;
216
217 final boolean condition = actual.equals(nullObject);
218
219 Assert.assertFalse("Equals in EndingNode with null", condition);
220 }
221
222
223
224
225
226
227
228 @Test
229 public void testOtherTypeEqualsObject() throws AbstractZemucanException {
230 final Graph graph = new Graph("test", false);
231
232 final EndingNode actual = new EndingNode(graph);
233 final StartingNode notExpected = new StartingNode(graph);
234
235 Assert.assertFalse("Equals between EndingNode and StartingNode",
236 actual.equals(notExpected));
237 Assert.assertFalse("Equals between EndingNode and StartingNode 2",
238 notExpected.equals(actual));
239 }
240
241
242
243
244
245
246
247 @Test
248 public void testSameEqualsObject() throws AbstractZemucanException {
249 final Graph graph = new Graph("test", false);
250
251 final EndingNode actual = new EndingNode(graph);
252 final EndingNode expected = new EndingNode(graph);
253
254 Assert.assertTrue("Two EndingNode are equals",
255 actual.equals(expected));
256 Assert.assertTrue("Two EndingNode are equals 2",
257 expected.equals(actual));
258 }
259
260
261
262
263
264
265
266 @Test
267 public void testSameHashCode() throws AbstractZemucanException {
268 final Graph graph = new Graph("test", false);
269
270 final EndingNode actual = new EndingNode(graph);
271 final EndingNode expected = new EndingNode(graph);
272
273 Assert.assertEquals(
274 "Two endingNode have the prodcue the same hashcode.",
275 expected.hashCode(), actual.hashCode());
276 }
277
278
279
280
281
282
283
284 @Test
285 public void testSymmetric() throws AbstractZemucanException {
286 final EndingNode actual = new EndingNode(new Graph("test", false));
287
288 final boolean value = actual.equals(actual);
289
290 Assert.assertTrue("Symmetry", value);
291 }
292
293
294
295
296
297
298
299 @Test
300 public void testToString() throws AbstractZemucanException {
301 final EndingNode actual = new EndingNode(new Graph("test", false));
302 final String expected = '{' + Constants.ENDING_NODE + '}';
303
304 Assert.assertEquals("Description of an EndingNode", expected,
305 actual.toString());
306 }
307 }