1 32 package net.sf.retrotranslator.runtime.java.util; 33 34 import java.util.UUID ; 35 import junit.framework.TestCase; 36 37 40 public class UUID_TestCase extends TestCase { 41 42 public void testRandomUUID() throws Exception { 43 UUID uuid = UUID.randomUUID(); 44 assertEquals(2, uuid.variant()); 45 assertEquals(4, uuid.version()); 46 } 47 48 public void testNameUUIDFromBytes() throws Exception { 49 UUID uuid = UUID.nameUUIDFromBytes("abc".getBytes()); 50 assertEquals(2, uuid.variant()); 51 assertEquals(3, uuid.version()); 52 } 53 54 public void testFromString() throws Exception { 55 UUID 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 { 61 assertEquals(123, new UUID (123, 456).getMostSignificantBits()); 62 } 63 64 public void testGetLeastSignificantBits() throws Exception { 65 assertEquals(456, new UUID (123, 456).getLeastSignificantBits()); 66 } 67 68 public void testVersion() throws Exception { 69 assertEquals(2, UUID.fromString("e48a5302-524d-2a9f-8203-1fbe19572c42").version()); 70 } 71 72 public void testVariant() throws Exception { 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 { 80 assertEquals(130742845922168750L, UUID.fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6").timestamp()); 81 try { 82 UUID.randomUUID().timestamp(); 83 fail(); 84 } catch (UnsupportedOperationException e) { 85 } 87 } 88 89 public void testClockSequence() throws Exception { 90 assertEquals(10085, UUID.fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6").clockSequence()); 91 try { 92 UUID.randomUUID().clockSequence(); 93 fail(); 94 } catch (UnsupportedOperationException e) { 95 } 97 } 98 99 public void testNode() throws Exception { 100 assertEquals(690568981494L, UUID.fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6").node()); 101 try { 102 UUID.randomUUID().node(); 103 fail(); 104 } catch (UnsupportedOperationException e) { 105 } 107 } 108 109 public void testToString() throws Exception { 110 assertEquals("112210f4-7de9-8115-e53d-0978c0cc8c54", 111 new UUID (1234567890123456789L, -1928374651209348012L).toString()); 112 } 113 114 public void testHashCode() throws Exception { 115 assertEquals(1228543181, new UUID (1234567890123456789L, -1928374651209348012L).hashCode()); 116 } 117 118 public void testEquals() throws Exception { 119 assertTrue(new UUID (1234567890123456789L, -1928374651209348012L).equals( 120 UUID.fromString("112210f4-7de9-8115-e53d-0978c0cc8c54"))); 121 assertFalse(new UUID (1234567890123456789L, -1928374651209348012L).equals( 122 UUID.fromString("012210f4-7de9-8115-e53d-0978c0cc8c54"))); 123 } 124 125 public void testCompareTo() throws Exception { 126 assertEquals(0, new UUID (1234567890123456789L, -1928374651209348012L).compareTo( 127 UUID.fromString("112210f4-7de9-8115-e53d-0978c0cc8c54"))); 128 129 assertEquals(1, new UUID (1234567890123456789L, -1928374651209348012L).compareTo( 130 new UUID (1234567890123456788L, -1928374651209348012L))); 131 132 assertEquals(1, new UUID (1234567890123456789L, -1928374651209348012L).compareTo( 133 new UUID (1234567890123456789L, -1928374651209348013L))); 134 135 assertEquals(-1, new UUID (1234567890123456789L, -1928374651209348012L).compareTo( 136 new UUID (1234567890123456790L, -1928374651209348012L))); 137 138 assertEquals(-1, new UUID (1234567890123456789L, -1928374651209348012L).compareTo( 139 new UUID (1234567890123456789L, -1928374651209348007L))); 140 } 141 } | Popular Tags |