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.interfaze.model;
30
31 import name.angoca.zemucan.ParameterNullException;
32 import name.angoca.zemucan.tools.test.RandomTestRunner;
33
34 import org.junit.Assert;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 @RunWith(RandomTestRunner.class)
58 public final class ReturnOptionsTest {
59
60
61
62 private static final String CREATE = "create";
63
64
65
66 private static final String TABLE = "table";
67
68
69
70 private static final String TABLE_NAME = "<tableName>";
71
72
73
74 private static final String TABLESPACE = "tablespace";
75
76
77
78
79 public ReturnOptionsTest() {
80
81 }
82
83
84
85
86
87
88
89 @Test
90 public void testCongruent() throws ParameterNullException {
91 final String phrase = "test";
92 final String[] phrases = new String[] { "test1" };
93 final String[] options = new String[] { "test2" };
94
95 final ReturnOptions token = new ReturnOptions(phrase, phrases, options);
96 final int val1 = token.hashCode();
97 final int val2 = token.hashCode();
98
99 final boolean condition = val1 == val2;
100
101 Assert.assertTrue("Two consecutive calls return the same value",
102 condition);
103 }
104
105
106
107
108
109
110
111 @Test
112 public void testEqualsObjectDifferent1() throws ParameterNullException {
113 final String phrase1 = "create table";
114 final String phrase11 = ReturnOptionsTest.TABLESPACE;
115 final String option11 = ReturnOptionsTest.TABLE_NAME;
116
117 final String phrase2 = ReturnOptionsTest.CREATE;
118 final String option21 = ReturnOptionsTest.TABLE;
119 final String option22 = ReturnOptionsTest.TABLESPACE;
120
121 final ReturnOptions object1 = new ReturnOptions(phrase1,
122 new String[] { phrase11 }, new String[] { option11 });
123
124 final ReturnOptions object2 = new ReturnOptions(phrase2,
125 new String[] {}, new String[] { option21, option22 });
126
127 Assert.assertFalse("equals between two different objects",
128 object1.equals(object2));
129 }
130
131
132
133
134
135
136
137 @Test
138 public void testEqualsObjectDifferent2() throws ParameterNullException {
139 final String phrase1 = ReturnOptionsTest.CREATE;
140 final String option1 = ReturnOptionsTest.TABLESPACE;
141
142 final String phrase2 = ReturnOptionsTest.CREATE;
143 final String option2 = ReturnOptionsTest.TABLE;
144
145 final ReturnOptions object1 = new ReturnOptions(phrase1,
146 new String[] {}, new String[] { option1 });
147
148 final ReturnOptions object2 = new ReturnOptions(phrase2,
149 new String[] {}, new String[] { option2 });
150
151 Assert.assertFalse("equals between two different objects",
152 object1.equals(object2));
153 }
154
155
156
157
158
159
160
161 @Test
162 public void testEqualsObjectDifferent3() throws ParameterNullException {
163 final String phrase1 = ReturnOptionsTest.CREATE;
164 final String phrase11 = ReturnOptionsTest.TABLESPACE;
165
166 final String phrase2 = ReturnOptionsTest.CREATE;
167 final String phrase21 = ReturnOptionsTest.TABLE;
168
169 final ReturnOptions object1 = new ReturnOptions(phrase1,
170 new String[] { phrase11 }, new String[] {});
171
172 final ReturnOptions object2 = new ReturnOptions(phrase2,
173 new String[] { phrase21 }, new String[] {});
174
175 Assert.assertFalse("equals between two different objects",
176 object1.equals(object2));
177 }
178
179
180
181
182
183
184
185 @Test
186 public void testEqualsObjectIdentical() throws ParameterNullException {
187 final String phrase = "create table";
188 final String phrase1 = ReturnOptionsTest.TABLESPACE;
189 final String option1 = ReturnOptionsTest.TABLE_NAME;
190
191 final ReturnOptions object1 = new ReturnOptions(phrase,
192 new String[] { phrase1 }, new String[] { option1 });
193
194 final ReturnOptions object2 = new ReturnOptions(phrase,
195 new String[] { phrase1 }, new String[] { option1 });
196
197 Assert.assertTrue("Equals between two identical objects", object1
198 .equals(object2));
199 }
200
201
202
203
204
205
206
207 @Test
208 public void testEqualsObjectNull() throws ParameterNullException {
209 final String phrase = "create table";
210 final String phrase1 = ReturnOptionsTest.TABLESPACE;
211 final String option1 = ReturnOptionsTest.TABLE_NAME;
212
213 final ReturnOptions object = new ReturnOptions(phrase,
214 new String[] { phrase1 }, new String[] { option1 });
215
216 final ReturnOptions nullObject = null;
217
218 final boolean condition = object.equals(nullObject);
219
220 Assert.assertFalse("Equals with null value", condition);
221 }
222
223
224
225
226
227
228
229 @Test
230 public void testGetOptions() throws ParameterNullException {
231 final String phrase = ReturnOptionsTest.CREATE;
232 final String option1 = ReturnOptionsTest.TABLE;
233 final String option2 = ReturnOptionsTest.TABLESPACE;
234
235 final ReturnOptions actual = new ReturnOptions(phrase, new String[] {},
236 new String[] { option1, option2 });
237
238 final String[] expected = { option1, option2 };
239
240 Assert.assertEquals("copy of options - length", expected.length,
241 actual.getOptions().length);
242 Assert.assertEquals("copy of options - 0", expected[0], actual
243 .getOptions()[0]);
244 Assert.assertEquals("copy of options - 1", expected[1], actual
245 .getOptions()[1]);
246 }
247
248
249
250
251
252
253
254 @Test
255 public void testGetPhrases() throws ParameterNullException {
256 final String phrase = "create tab";
257 final String phrase1 = ReturnOptionsTest.TABLE;
258 final String phrase2 = ReturnOptionsTest.TABLESPACE;
259
260 final ReturnOptions actual = new ReturnOptions(phrase, new String[] {
261 phrase1, phrase2 }, new String[] {});
262
263 final String[] expected = { phrase1, phrase2 };
264
265 Assert.assertEquals("copy of phrases - length", expected.length,
266 actual.getPhrases().length);
267 Assert.assertEquals("copy of phrases - 0", expected[0], actual
268 .getPhrases()[0]);
269 Assert.assertEquals("copy of phrases - 1", expected[1], actual
270 .getPhrases()[1]);
271 }
272
273
274
275
276
277
278
279 @Test
280 public void testHashCode() throws ParameterNullException {
281 final String phrase = "create table";
282 final String phrase1 = ReturnOptionsTest.TABLESPACE;
283 final String option1 = ReturnOptionsTest.TABLE_NAME;
284
285 final ReturnOptions object = new ReturnOptions(phrase,
286 new String[] { phrase1 }, new String[] { option1 });
287
288 Assert.assertTrue("hashcode different to 0",
289 object.hashCode() != 0);
290 Assert.assertTrue("hashcode different to 1",
291 object.hashCode() != 1);
292 Assert.assertTrue("hashcode different to -1",
293 object.hashCode() != -1);
294 }
295
296
297
298
299
300
301
302 @Test
303 public void testHashCodeDifferent() throws ParameterNullException {
304 final String phrase1 = "create table";
305 final String phrase11 = ReturnOptionsTest.TABLESPACE;
306 final String option11 = ReturnOptionsTest.TABLE_NAME;
307
308 final String phrase2 = ReturnOptionsTest.CREATE;
309 final String option21 = ReturnOptionsTest.TABLE;
310 final String option22 = ReturnOptionsTest.TABLESPACE;
311
312 final ReturnOptions object1 = new ReturnOptions(phrase1,
313 new String[] { phrase11 }, new String[] { option11 });
314
315 final ReturnOptions object2 = new ReturnOptions(phrase2,
316 new String[] {}, new String[] { option21, option22 });
317
318 final boolean condition = object1.hashCode() != object2.hashCode();
319
320 Assert.assertTrue("hashcode of two different objects",
321 condition);
322 }
323
324
325
326
327
328
329
330 @Test
331 public void testHashCodeIdentical() throws ParameterNullException {
332 final String phrase = "create table";
333 final String phrase1 = ReturnOptionsTest.TABLESPACE;
334 final String option1 = ReturnOptionsTest.TABLE_NAME;
335
336 final ReturnOptions object1 = new ReturnOptions(phrase,
337 new String[] { phrase1 }, new String[] { option1 });
338
339 final ReturnOptions object2 = new ReturnOptions(phrase,
340 new String[] { phrase1 }, new String[] { option1 });
341
342 final boolean condition = object1.hashCode() == object2.hashCode();
343
344 Assert.assertTrue("hashcode of two identical objects",
345 condition);
346 }
347
348
349
350
351
352
353
354 @Test
355 public void testReturnOptionsNullOptions() throws ParameterNullException {
356 final String phrase = "create table";
357 final String phrases = ReturnOptionsTest.TABLESPACE;
358
359 Exception e = null;
360 try {
361 new ReturnOptions(phrase, new String[] { phrases }, null);
362 } catch (final Exception exception) {
363 e = exception;
364 }
365 Assert.assertTrue("ParameterNullException",
366 e instanceof ParameterNullException);
367 }
368
369
370
371
372
373
374
375 @Test
376 public void testReturnOptionsNullPhrase() throws ParameterNullException {
377 final String phrases = ReturnOptionsTest.TABLESPACE;
378 final String options = ReturnOptionsTest.TABLE_NAME;
379
380 Exception e = null;
381 try {
382 new ReturnOptions(null, new String[] { phrases },
383 new String[] { options });
384 } catch (final Exception exception) {
385 e = exception;
386 }
387 Assert.assertTrue("ParameterNullException",
388 e instanceof ParameterNullException);
389 }
390
391
392
393
394
395
396
397 @Test
398 public void testReturnOptionsNullPhrases() throws ParameterNullException {
399 final String phrase = "create table";
400 final String options = ReturnOptionsTest.TABLE_NAME;
401
402 Exception e = null;
403 try {
404 new ReturnOptions(phrase, null, new String[] { options });
405 } catch (final Exception exception) {
406 e = exception;
407 }
408 Assert.assertTrue("ParameterNullException",
409 e instanceof ParameterNullException);
410 }
411
412
413
414
415
416
417
418 @Test
419 public void testReturnOptionsOneNullInOptions()
420 throws ParameterNullException {
421 final String phrase = "create table";
422 final String phrases = ReturnOptionsTest.TABLESPACE;
423
424 Exception e = null;
425 try {
426 new ReturnOptions(phrase, new String[] { phrases },
427 new String[] { null });
428 } catch (final Exception exception) {
429 e = exception;
430 }
431 Assert.assertTrue("ParameterNullException",
432 e instanceof ParameterNullException);
433 }
434
435
436
437
438
439
440
441 @Test
442 public void testReturnOptionsOneNullInPhrases()
443 throws ParameterNullException {
444 final String phrase = "create table";
445 final String options = ReturnOptionsTest.TABLE_NAME;
446
447 Exception e = null;
448 try {
449 new ReturnOptions(phrase, new String[] { null },
450 new String[] { options });
451 } catch (final Exception exception) {
452 e = exception;
453 }
454 Assert.assertTrue("ParameterNullException",
455 e instanceof ParameterNullException);
456 }
457
458
459
460
461
462
463
464 @Test
465 public void testSymmetric() throws ParameterNullException {
466 final String phrase = "test";
467 final String[] phrases = new String[] { "test1" };
468 final String[] options = new String[] { "test2" };
469 final ReturnOptions actual = new ReturnOptions(phrase, phrases, options);
470
471 final boolean value = actual.equals(actual);
472
473 Assert.assertTrue("Symmetry", value);
474 }
475
476
477
478
479
480
481
482 @Test
483 public void testToString1() throws ParameterNullException {
484 final String phrase = ReturnOptionsTest.CREATE;
485 final String option1 = ReturnOptionsTest.TABLE;
486 final String option2 = ReturnOptionsTest.TABLESPACE;
487
488 final ReturnOptions returnOptions = new ReturnOptions(phrase,
489 new String[] {}, new String[] { option1, option2 });
490
491 final String actual = returnOptions.toString();
492
493 final String expected = "[create]{[table][tablespace]}";
494
495 Assert.assertEquals("Method toString", expected, actual);
496 }
497
498
499
500
501
502
503
504 @Test
505 public void testToString2() throws ParameterNullException {
506 final String phrase = "create table";
507 final String phrase1 = ReturnOptionsTest.TABLESPACE;
508 final String option1 = ReturnOptionsTest.TABLE_NAME;
509
510 final ReturnOptions returnOptions = new ReturnOptions(phrase,
511 new String[] { phrase1 }, new String[] { option1 });
512
513 final String actual = returnOptions.toString();
514
515 final String expected = "[create table]<(tablespace)>{[<tableName>]}";
516
517 Assert.assertEquals("Method toString", expected, actual);
518 }
519 }