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.ParentStartingNodeException;
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 @RunWith(RandomTestRunner.class)
67 public final class StartingNodeTest {
68
69
70
71 public StartingNodeTest() {
72
73 }
74
75
76
77
78
79
80
81 @Test
82 public void testAddParent() throws AbstractZemucanException {
83 final StartingNode actual = new StartingNode(new Graph("test", false));
84
85 Exception e = null;
86 try {
87 actual.addParent(null);
88 } catch (final Exception exception) {
89 e = exception;
90 }
91 Assert.assertTrue("ParentStartingNodeException",
92 e instanceof ParentStartingNodeException);
93 }
94
95
96
97
98
99
100
101 @Test
102 public void testCongruent() throws AbstractZemucanException {
103 final String node = "test";
104
105 final GraphNode node1 = new GraphNode(node, new Graph("test", false));
106 final int val1 = node1.hashCode();
107 final int val2 = node1.hashCode();
108
109 final boolean condition = val1 == val2;
110
111 Assert.assertTrue("Two consecutive calls return the same value",
112 condition);
113 }
114
115
116
117
118
119
120
121 @Test
122 public void testDifferentStartingNodeHashCode()
123 throws AbstractZemucanException {
124 final Graph graph = new Graph("test", false);
125
126 final StartingNode actual = new StartingNode(graph);
127 final EndingNode notExpected = new EndingNode(graph);
128
129 final boolean condition = notExpected.hashCode() == actual.hashCode();
130
131 Assert.assertFalse("hashcode for two different objects", condition);
132 }
133
134
135
136
137
138
139
140 @Test
141 public void testEqualsNodeNotReserved() throws AbstractZemucanException {
142 final String node = "StartingNode";
143 final Graph graph = new Graph("test", false);
144
145 final StartingNode actual = new StartingNode(graph);
146 final GraphNode notExpected = new GraphNode(node, graph);
147
148 Assert.assertFalse("Equals for a non reserved object",
149 actual.equals(notExpected));
150 Assert.assertFalse("Equals for a non reserved object 2",
151 notExpected.equals(actual));
152 }
153
154
155
156
157
158
159
160 @Test
161 public void testEqualsNodeReserved() throws AbstractZemucanException {
162 final String node = "StartingNode";
163 final Graph graph = new Graph("test", false);
164
165 final StartingNode actual = new StartingNode(graph);
166 final GraphNode notExpected = new GraphNode(node, graph);
167
168 Assert.assertFalse("equals for a reserved object",
169 actual.equals(notExpected));
170 Assert.assertFalse("equals for a reserved object 2",
171 notExpected.equals(actual));
172 }
173
174
175
176
177
178
179
180 @Test
181 public void testHashCode() throws AbstractZemucanException {
182 final StartingNode actual = new StartingNode(new Graph("test", false));
183
184 Assert.assertTrue("hashcode different to 1",
185 1 != actual.hashCode());
186 Assert.assertTrue("hashcode different to 0",
187 0 != actual.hashCode());
188 Assert.assertTrue("hashcode different to -1",
189 -1 != actual.hashCode());
190 }
191
192
193
194
195
196
197
198 @Test
199 public void testNullEqualsObject() throws AbstractZemucanException {
200 final StartingNode actual = new StartingNode(new Graph("test", false));
201
202 final StartingNode nullObject = null;
203
204 final boolean condition = actual.equals(nullObject);
205
206 Assert.assertFalse("Equals with a null value", condition);
207 }
208
209
210
211
212
213
214
215 @Test
216 public void testOtherTypeEqualsObject() throws AbstractZemucanException {
217 final Graph graph = new Graph("test", false);
218
219 final StartingNode actual = new StartingNode(graph);
220 final EndingNode notExpected = new EndingNode(graph);
221
222 Assert.assertFalse("equals for two different objects",
223 actual.equals(notExpected));
224 Assert.assertFalse("equals for two different objects 2",
225 notExpected.equals(actual));
226 }
227
228
229
230
231
232
233
234 @Test
235 public void testSameEqualsObject() throws AbstractZemucanException {
236 final Graph graph = new Graph("test", false);
237
238 final StartingNode actual = new StartingNode(graph);
239 final StartingNode expected = new StartingNode(graph);
240
241 Assert.assertTrue("equals fot two identical objects",
242 actual.equals(expected));
243 Assert.assertTrue("equals fot two identical objects 2",
244 expected.equals(actual));
245 }
246
247
248
249
250
251
252
253 @Test
254 public void testSameHashCode() throws AbstractZemucanException {
255 final Graph graph = new Graph("test", false);
256
257 final StartingNode actual = new StartingNode(graph);
258 final StartingNode expected = new StartingNode(graph);
259
260 Assert.assertEquals("hashcode for two identical objects",
261 expected.hashCode(), actual.hashCode());
262 }
263
264
265
266
267
268
269
270 @Test
271 public void testSymmetric() throws AbstractZemucanException {
272 final StartingNode actual = new StartingNode(new Graph("test", false));
273
274 final boolean value = actual.equals(actual);
275
276 Assert.assertTrue("Symmetry", value);
277 }
278
279
280
281
282
283
284
285 @Test
286 public void testToString() throws AbstractZemucanException {
287 final StartingNode actual = new StartingNode(new Graph("test", false));
288 final String expected = '{' + Constants.STARTING_NODE + '}';
289
290 Assert.assertEquals("toString", expected, actual.toString());
291 }
292 }