90 throw new Exception("byte UUID collision very unlikely"); 91 list.add(u1); 92 } 93 } 94 95 private static void stringTest() throws Exception { 96 for (int i=0; i<100; i++) { 97 UUID u1 = UUID.randomUUID(); 98 UUID u2 = UUID.fromString(u1.toString()); 99 if (!u1.equals(u2)) 100 throw new Exception("UUID -> string -> UUID failed"); 101 } 102 103 testFromStringError("-0"); 104 testFromStringError("x"); 105 testFromStringError("----"); 106 testFromStringError("-0-0-0-0"); 107 testFromStringError("0-0-0-0-"); 108 testFromStringError("0-0-0-0-0-"); 109 testFromStringError("0-0-0-0-x"); 110 } 111 112 private static void testFromStringError(String str) { 113 try { 114 UUID test = UUID.fromString(str); 115 throw new RuntimeException("Should have thrown IAE"); 116 } catch (IllegalArgumentException iae) { 117 // pass 118 } 119 } 120 121 private static void versionTest() throws Exception { 122 UUID test = UUID.randomUUID(); 123 if (test.version() != 4) 124 throw new Exception("randomUUID not type 4"); 125 Random byteSource = new Random(); 126 byte[] someBytes = new byte[12]; 127 byteSource.nextBytes(someBytes); 128 test = UUID.nameUUIDFromBytes(someBytes); 129 if (test.version() != 3) | 90 throw new Exception("byte UUID collision very unlikely"); 91 list.add(u1); 92 } 93 } 94 95 private static void stringTest() throws Exception { 96 for (int i=0; i<100; i++) { 97 UUID u1 = UUID.randomUUID(); 98 UUID u2 = UUID.fromString(u1.toString()); 99 if (!u1.equals(u2)) 100 throw new Exception("UUID -> string -> UUID failed"); 101 } 102 103 testFromStringError("-0"); 104 testFromStringError("x"); 105 testFromStringError("----"); 106 testFromStringError("-0-0-0-0"); 107 testFromStringError("0-0-0-0-"); 108 testFromStringError("0-0-0-0-0-"); 109 testFromStringError("0-0-0-0-x"); 110 testFromStringError("123456789-1234-1234-1234-123456789012"); 111 testFromStringError("123456789-2-3-4-5"); 112 testFromStringError("1-12345-3-4-5"); 113 testFromStringError("1-2-12345-4-5"); 114 testFromStringError("1-2-3-12345-5"); 115 testFromStringError("1-2-3-4-1234567890123"); 116 } 117 118 private static void testFromStringError(String str) { 119 try { 120 UUID test = UUID.fromString(str); 121 throw new RuntimeException("Should have thrown IAE"); 122 } catch (IllegalArgumentException iae) { 123 // pass 124 } 125 } 126 127 private static void versionTest() throws Exception { 128 UUID test = UUID.randomUUID(); 129 if (test.version() != 4) 130 throw new Exception("randomUUID not type 4"); 131 Random byteSource = new Random(); 132 byte[] someBytes = new byte[12]; 133 byteSource.nextBytes(someBytes); 134 test = UUID.nameUUIDFromBytes(someBytes); 135 if (test.version() != 3) |