View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
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.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   * This class tests the GUID (Globally Unique Id) methods.
27   */
28  public class GuidTest extends KNSTestCase {
29  
30      private final static int count = 100000; // This passed at 1 million
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  }