001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.runtime.java.util;
032:
033: import java.util.UUID;
034: import junit.framework.TestCase;
035:
036: /**
037: * @author Taras Puchko
038: */
039: public class UUID_TestCase extends TestCase {
040:
041: public void testRandomUUID() throws Exception {
042: UUID uuid = UUID.randomUUID();
043: assertEquals(2, uuid.variant());
044: assertEquals(4, uuid.version());
045: }
046:
047: public void testNameUUIDFromBytes() throws Exception {
048: UUID uuid = UUID.nameUUIDFromBytes("abc".getBytes());
049: assertEquals(2, uuid.variant());
050: assertEquals(3, uuid.version());
051: }
052:
053: public void testFromString() throws Exception {
054: UUID uuid = UUID
055: .fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6");
056: assertEquals(2, uuid.variant());
057: assertEquals(1, uuid.version());
058: }
059:
060: public void testGetMostSignificantBits() throws Exception {
061: assertEquals(123, new UUID(123, 456).getMostSignificantBits());
062: }
063:
064: public void testGetLeastSignificantBits() throws Exception {
065: assertEquals(456, new UUID(123, 456).getLeastSignificantBits());
066: }
067:
068: public void testVersion() throws Exception {
069: assertEquals(2, UUID.fromString(
070: "e48a5302-524d-2a9f-8203-1fbe19572c42").version());
071: }
072:
073: public void testVariant() throws Exception {
074: assertEquals(0, UUID.fromString(
075: "e48a5302-524d-2a9f-7203-1fbe19572c42").variant());
076: assertEquals(2, UUID.fromString(
077: "e48a5302-524d-2a9f-b203-1fbe19572c42").variant());
078: assertEquals(6, UUID.fromString(
079: "e48a5302-524d-2a9f-d203-1fbe19572c42").variant());
080: assertEquals(7, UUID.fromString(
081: "e48a5302-524d-2a9f-f203-1fbe19572c42").variant());
082: }
083:
084: public void testTimestamp() throws Exception {
085: assertEquals(130742845922168750L, UUID.fromString(
086: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6").timestamp());
087: try {
088: UUID.randomUUID().timestamp();
089: fail();
090: } catch (UnsupportedOperationException e) {
091: //ok
092: }
093: }
094:
095: public void testClockSequence() throws Exception {
096: assertEquals(10085, UUID.fromString(
097: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6").clockSequence());
098: try {
099: UUID.randomUUID().clockSequence();
100: fail();
101: } catch (UnsupportedOperationException e) {
102: //ok
103: }
104: }
105:
106: public void testNode() throws Exception {
107: assertEquals(690568981494L, UUID.fromString(
108: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6").node());
109: try {
110: UUID.randomUUID().node();
111: fail();
112: } catch (UnsupportedOperationException e) {
113: //ok
114: }
115: }
116:
117: public void testToString() throws Exception {
118: assertEquals("112210f4-7de9-8115-e53d-0978c0cc8c54", new UUID(
119: 1234567890123456789L, -1928374651209348012L).toString());
120: }
121:
122: public void testHashCode() throws Exception {
123: assertEquals(1228543181, new UUID(1234567890123456789L,
124: -1928374651209348012L).hashCode());
125: }
126:
127: public void testEquals() throws Exception {
128: assertTrue(new UUID(1234567890123456789L, -1928374651209348012L)
129: .equals(UUID
130: .fromString("112210f4-7de9-8115-e53d-0978c0cc8c54")));
131: assertFalse(new UUID(1234567890123456789L,
132: -1928374651209348012L).equals(UUID
133: .fromString("012210f4-7de9-8115-e53d-0978c0cc8c54")));
134: }
135:
136: public void testCompareTo() throws Exception {
137: assertEquals(0, new UUID(1234567890123456789L,
138: -1928374651209348012L).compareTo(UUID
139: .fromString("112210f4-7de9-8115-e53d-0978c0cc8c54")));
140:
141: assertEquals(1, new UUID(1234567890123456789L,
142: -1928374651209348012L).compareTo(new UUID(
143: 1234567890123456788L, -1928374651209348012L)));
144:
145: assertEquals(1, new UUID(1234567890123456789L,
146: -1928374651209348012L).compareTo(new UUID(
147: 1234567890123456789L, -1928374651209348013L)));
148:
149: assertEquals(-1, new UUID(1234567890123456789L,
150: -1928374651209348012L).compareTo(new UUID(
151: 1234567890123456790L, -1928374651209348012L)));
152:
153: assertEquals(-1, new UUID(1234567890123456789L,
154: -1928374651209348012L).compareTo(new UUID(
155: 1234567890123456789L, -1928374651209348007L)));
156: }
157: }
|