01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TestUniqueIDGenerator.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.tools;
09:
10: import com.uwyn.rife.tools.UniqueID;
11: import com.uwyn.rife.tools.UniqueIDGenerator;
12: import java.util.Arrays;
13: import junit.framework.TestCase;
14:
15: public class TestUniqueIDGenerator extends TestCase {
16: public TestUniqueIDGenerator(String name) {
17: super (name);
18: }
19:
20: public void testGenerationWithImplicitSeed() {
21: UniqueID uid = UniqueIDGenerator.generate();
22: assertNotNull(uid);
23: assertNotNull(uid.toString());
24: assertTrue(uid.toString().length() > 0);
25: }
26:
27: public void testGenerationWithProvidedSeed() {
28: UniqueID uid = UniqueIDGenerator.generate("uwyn.com/127.0.0.1");
29: assertNotNull(uid);
30: assertNotNull(uid.toString());
31: assertTrue(uid.toString().length() > 0);
32: }
33:
34: public void testIDUnicity() {
35: UniqueID uid1 = UniqueIDGenerator.generate();
36: UniqueID uid2 = UniqueIDGenerator.generate();
37: UniqueID uid3 = UniqueIDGenerator.generate();
38: UniqueID uid4 = UniqueIDGenerator.generate();
39: assertNotNull(uid1);
40: assertNotNull(uid2);
41: assertNotNull(uid3);
42: assertNotNull(uid4);
43: assertTrue(Arrays.equals(uid1.getID(), uid1.getID()));
44: assertFalse(Arrays.equals(uid1.getID(), uid2.getID()));
45: assertFalse(Arrays.equals(uid1.getID(), uid3.getID()));
46: assertFalse(Arrays.equals(uid1.getID(), uid4.getID()));
47: assertTrue(Arrays.equals(uid2.getID(), uid2.getID()));
48: assertFalse(Arrays.equals(uid2.getID(), uid3.getID()));
49: assertFalse(Arrays.equals(uid2.getID(), uid4.getID()));
50: assertTrue(Arrays.equals(uid3.getID(), uid3.getID()));
51: assertFalse(Arrays.equals(uid3.getID(), uid4.getID()));
52: assertTrue(Arrays.equals(uid4.getID(), uid4.getID()));
53: String uid1_string = uid1.toString();
54: String uid2_string = uid2.toString();
55: String uid3_string = uid3.toString();
56: String uid4_string = uid4.toString();
57: assertTrue(0 == uid1_string.compareTo(uid1_string));
58: assertTrue(0 != uid1_string.compareTo(uid2_string));
59: assertTrue(0 != uid1_string.compareTo(uid3_string));
60: assertTrue(0 != uid1_string.compareTo(uid4_string));
61: assertTrue(0 == uid2_string.compareTo(uid2_string));
62: assertTrue(0 != uid2_string.compareTo(uid3_string));
63: assertTrue(0 != uid2_string.compareTo(uid4_string));
64: assertTrue(0 == uid3_string.compareTo(uid3_string));
65: assertTrue(0 != uid3_string.compareTo(uid4_string));
66: assertTrue(0 == uid4_string.compareTo(uid4_string));
67: }
68: }
|