@Test public void testLengthAlwaysEqual() throws Exception { Field f = UUIDGeneratorImpl.class.getDeclaredField("count"); f.setAccessible(true); AtomicLong c = (AtomicLong)f.get(null); c.set(0); int referenceLength = new UUIDGeneratorImpl().getNextUUID().length(); int numUUIDsCreated = 0; long lastVal = -1; while (true) { UUIDGenerator uuid = new UUIDGeneratorImpl(); ++numUUIDsCreated; assertTrue("Bad uuid: "+ uuid , uuid.getNextUUID().length() == referenceLength); c.set(c.get() * 2); long thisVal = Long.parseLong(uuid.getNextUUID().substring(uuid.getNextUUID().lastIndexOf("-")+1), 16); if (thisVal < lastVal) { if (c.get() < 0xFFFFFFFFFFL) { Assert.fail("Cycled after "+numUUIDsCreated+" uuids. lastVal was "+lastVal+", thisVal is "+thisVal); } else { break; } } else { lastVal = thisVal; } } System.out.println("Length tested OK after "+ numUUIDsCreated+ "iterations"); }
@Override public String getNextUUID() { return randomUUID(); }
UUIDGeneratorImpl implements UUIDGenerator { @Override public String getNextUUID() { return randomUUID(); } }
UUIDGeneratorImpl implements UUIDGenerator { @Override public String getNextUUID() { return randomUUID(); }  }
UUIDGeneratorImpl implements UUIDGenerator { @Override public String getNextUUID() { return randomUUID(); }  @Override String getNextUUID(); @Override String[] validateUuid(String uuid); }
UUIDGeneratorImpl implements UUIDGenerator { @Override public String getNextUUID() { return randomUUID(); }  @Override String getNextUUID(); @Override String[] validateUuid(String uuid); static final String DEFAULT_HOSTNAME; }