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