### Question:
IdGenerator { public String generateId() { StringBuilder sb = new StringBuilder(64); sb.append(prefix); sb.append(UUID.randomUUID()); sb.append(":"); sb.append(sequence.getAndIncrement()); return sb.toString(); } IdGenerator(String prefix);  IdGenerator(); String generateId(); static final String DEFAULT_PREFIX; static final String PROPERTY_IDGENERATOR_HOST_PREFIX; }### Answer:
@Test public void testDefaultPrefix() { String generated = generator.generateId(); assertTrue(generated.startsWith(IdGenerator.DEFAULT_PREFIX)); assertFalse(generated.substring(IdGenerator.DEFAULT_PREFIX.length()).startsWith(":")); }
@Test public void testNonDefaultPrefix() { generator = new IdGenerator("TEST-"); String generated = generator.generateId(); assertFalse(generated.startsWith(IdGenerator.DEFAULT_PREFIX)); assertFalse(generated.substring("TEST-".length()).startsWith(":")); }
@Test public void testIdIndexIncrements() throws Exception { final int COUNT = 5; ArrayList<String> ids = new ArrayList<String>(COUNT); ArrayList<Integer> sequences = new ArrayList<Integer>(); for (int i = 0; i < COUNT; ++i) { ids.add(generator.generateId()); } for (String id : ids) { String[] components = id.split(":"); sequences.add(Integer.parseInt(components[components.length - 1])); } Integer lastValue = null; for (Integer sequence : sequences) { if (lastValue != null) { assertTrue(sequence > lastValue); } lastValue = sequence; } }