1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.util;
17
18 import java.util.HashSet;
19 import java.util.Set;
20
21 import org.junit.Test;
22 import org.kuali.rice.kns.util.Guid;
23 import org.kuali.test.KNSTestCase;
24
25
26
27
28 public class GuidTest extends KNSTestCase {
29
30 private final static int count = 100000;
31
32 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(Guid.class);
33
34 @Test public void testGuidGeneration() {
35 Guid guid = new Guid();
36 assertNotNull(guid);
37 assertNotNull(guid.toString());
38 }
39
40
41 @Test public void testGuidUniqueness() {
42 Set<String> seen = new HashSet();
43
44 for (int i = 0; i < count; i++) {
45 Guid guid = new Guid();
46 String nextGuid = guid.toString();
47 assertFalse("guids should probably be unique: " + i + "," + nextGuid, seen.contains(nextGuid));
48 seen.add(nextGuid);
49 }
50 }
51
52
53 @Test public void testGuidHexConversion() throws Exception {
54 assertTrue("FF".equals(Guid.toHex((byte) 255)));
55 assertEquals("83", Guid.toHex((byte) 0x83));
56 assertEquals("83", Guid.toHex((byte) -125));
57
58 }
59
60
61 }