01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.core.util;
17:
18: import java.util.HashSet;
19: import java.util.Set;
20:
21: import org.kuali.kfs.context.KualiTestBase;
22:
23: /**
24: * This class tests the GUID (Globally Unique Id) methods.
25: */
26: public class GuidTest extends KualiTestBase {
27:
28: private final static int count = 100000; // This passed at 1 million
29:
30: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
31: .getLogger(Guid.class);
32:
33: public void testGuidGeneration() {
34: Guid guid = new Guid();
35: assertNotNull(guid);
36: assertNotNull(guid.toString());
37: }
38:
39: public void testGuidUniqueness() {
40: Set<String> seen = new HashSet();
41:
42: for (int i = 0; i < count; i++) {
43: Guid guid = new Guid();
44: String nextGuid = guid.toString();
45: assertFalse("guids should probably be unique: " + i + ","
46: + nextGuid, seen.contains(nextGuid));
47: seen.add(nextGuid);
48: }
49: }
50:
51: public void testGuidHexConversion() throws Exception {
52: assertTrue("FF".equals(Guid.toHex((byte) 255)));
53: assertEquals("83", Guid.toHex((byte) 0x83));
54: assertEquals("83", Guid.toHex((byte) -125));
55:
56: }
57:
58: }
|