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