KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > common > RandomGuidTest


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * RandomGuidTest.java
20  *
21  * JUnit based test
22  */

23
24 package com.rift.coad.lib.common;
25
26 import com.rift.coad.lib.common.*;
27 import junit.framework.*;
28 import java.net.InetAddress JavaDoc;
29 import java.net.UnknownHostException JavaDoc;
30 import java.security.SecureRandom JavaDoc;
31 import java.security.MessageDigest JavaDoc;
32
33 /**
34  *
35  * @author mincemeat
36  */

37 public class RandomGuidTest extends TestCase {
38     
39     public RandomGuidTest(String JavaDoc testName) {
40         super(testName);
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44     }
45
46     protected void tearDown() throws Exception JavaDoc {
47     }
48
49     public static Test suite() {
50         TestSuite suite = new TestSuite(RandomGuidTest.class);
51         
52         return suite;
53     }
54     
55     
56     /**
57      * Test of getGuid method, of class com.rift.coad.lib.common.RandomGuid.
58      */

59     public void testGetGuid() throws Exception JavaDoc {
60         System.out.println("getGuid");
61         
62         RandomGuid generator1 = RandomGuid.getInstance();
63         RandomGuid generator2 = RandomGuid.getInstance();
64         
65         // check that generated values from two different object instances are
66
// not the same
67
String JavaDoc id1 = generator1.getGuid();
68         String JavaDoc id2 = generator2.getGuid();
69         
70         if (id1.equals(id2)) {
71             fail("The ids are the same");
72         }
73         
74         // check that the object instance returns the same values.
75
if (!id1.equals(generator1.toString())) {
76             fail("The generated ids from the same object instance are not the same");
77         }
78         
79         if (!id2.equals(generator2.toString())) {
80             fail("The generated ids from the same object instance are not the same");
81         }
82         
83         // print ids
84
System.out.println("ID 1 [" + id1 + "] ID 2 [" + id2 + "]");
85     }
86
87     
88 }
89
Popular Tags