KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > retrotranslator > runtime > java > util > UUID_TestCase


1 /***
2  * Retrotranslator: a Java bytecode transformer that translates Java classes
3  * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
4  *
5  * Copyright (c) 2005 - 2007 Taras Puchko
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the copyright holders nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30  * THE POSSIBILITY OF SUCH DAMAGE.
31  */

32 package net.sf.retrotranslator.runtime.java.util;
33
34 import java.util.UUID JavaDoc;
35 import junit.framework.TestCase;
36
37 /**
38  * @author Taras Puchko
39  */

40 public class UUID_TestCase extends TestCase {
41
42     public void testRandomUUID() throws Exception JavaDoc {
43         UUID JavaDoc uuid = UUID.randomUUID();
44         assertEquals(2, uuid.variant());
45         assertEquals(4, uuid.version());
46     }
47
48     public void testNameUUIDFromBytes() throws Exception JavaDoc {
49         UUID JavaDoc uuid = UUID.nameUUIDFromBytes("abc".getBytes());
50         assertEquals(2, uuid.variant());
51         assertEquals(3, uuid.version());
52     }
53
54     public void testFromString() throws Exception JavaDoc {
55         UUID JavaDoc uuid = UUID.fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6");
56         assertEquals(2, uuid.variant());
57         assertEquals(1, uuid.version());
58     }
59
60     public void testGetMostSignificantBits() throws Exception JavaDoc {
61         assertEquals(123, new UUID JavaDoc(123, 456).getMostSignificantBits());
62     }
63
64     public void testGetLeastSignificantBits() throws Exception JavaDoc {
65         assertEquals(456, new UUID JavaDoc(123, 456).getLeastSignificantBits());
66     }
67
68     public void testVersion() throws Exception JavaDoc {
69         assertEquals(2, UUID.fromString("e48a5302-524d-2a9f-8203-1fbe19572c42").version());
70     }
71
72     public void testVariant() throws Exception JavaDoc {
73         assertEquals(0, UUID.fromString("e48a5302-524d-2a9f-7203-1fbe19572c42").variant());
74         assertEquals(2, UUID.fromString("e48a5302-524d-2a9f-b203-1fbe19572c42").variant());
75         assertEquals(6, UUID.fromString("e48a5302-524d-2a9f-d203-1fbe19572c42").variant());
76         assertEquals(7, UUID.fromString("e48a5302-524d-2a9f-f203-1fbe19572c42").variant());
77     }
78
79     public void testTimestamp() throws Exception JavaDoc {
80         assertEquals(130742845922168750L, UUID.fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6").timestamp());
81         try {
82             UUID.randomUUID().timestamp();
83             fail();
84         } catch (UnsupportedOperationException JavaDoc e) {
85             //ok
86
}
87     }
88
89     public void testClockSequence() throws Exception JavaDoc {
90         assertEquals(10085, UUID.fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6").clockSequence());
91         try {
92             UUID.randomUUID().clockSequence();
93             fail();
94         } catch (UnsupportedOperationException JavaDoc e) {
95             //ok
96
}
97     }
98
99     public void testNode() throws Exception JavaDoc {
100         assertEquals(690568981494L, UUID.fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6").node());
101         try {
102             UUID.randomUUID().node();
103             fail();
104         } catch (UnsupportedOperationException JavaDoc e) {
105             //ok
106
}
107     }
108
109     public void testToString() throws Exception JavaDoc {
110         assertEquals("112210f4-7de9-8115-e53d-0978c0cc8c54",
111                 new UUID JavaDoc(1234567890123456789L, -1928374651209348012L).toString());
112     }
113
114     public void testHashCode() throws Exception JavaDoc {
115         assertEquals(1228543181, new UUID JavaDoc(1234567890123456789L, -1928374651209348012L).hashCode());
116     }
117
118     public void testEquals() throws Exception JavaDoc {
119         assertTrue(new UUID JavaDoc(1234567890123456789L, -1928374651209348012L).equals(
120                 UUID.fromString("112210f4-7de9-8115-e53d-0978c0cc8c54")));
121         assertFalse(new UUID JavaDoc(1234567890123456789L, -1928374651209348012L).equals(
122                 UUID.fromString("012210f4-7de9-8115-e53d-0978c0cc8c54")));
123     }
124
125     public void testCompareTo() throws Exception JavaDoc {
126         assertEquals(0, new UUID JavaDoc(1234567890123456789L, -1928374651209348012L).compareTo(
127                 UUID.fromString("112210f4-7de9-8115-e53d-0978c0cc8c54")));
128
129         assertEquals(1, new UUID JavaDoc(1234567890123456789L, -1928374651209348012L).compareTo(
130                 new UUID JavaDoc(1234567890123456788L, -1928374651209348012L)));
131
132         assertEquals(1, new UUID JavaDoc(1234567890123456789L, -1928374651209348012L).compareTo(
133                 new UUID JavaDoc(1234567890123456789L, -1928374651209348013L)));
134
135         assertEquals(-1, new UUID JavaDoc(1234567890123456789L, -1928374651209348012L).compareTo(
136                 new UUID JavaDoc(1234567890123456790L, -1928374651209348012L)));
137
138         assertEquals(-1, new UUID JavaDoc(1234567890123456789L, -1928374651209348012L).compareTo(
139                 new UUID JavaDoc(1234567890123456789L, -1928374651209348007L)));
140     }
141 }
Popular Tags