### Question:
IdGenerator { public String newId(String type, String text) { if (type == null) { type = ""; } Integer current = idGenerators.get(type); if (current == null) { current = 0; } current = current + 1; idGenerators.put(type, current); String id = null; if (text != null) { id = generationStrategy.generateId(text.trim()); if (id == null || id.length() == 0) { id = type + '-' + current; } } else { id = type + '-' + current; } String template = id; int suffix = 1; while (!anchorNames.add(id)) { id = template + (++suffix); } return id; } IdGenerator(); boolean reserveId(String id); String newId(String type, String text); Set<String> getAnchorNames(); boolean hasAnchorNames(); IdGenerationStrategy getGenerationStrategy(); void setGenerationStrategy(IdGenerationStrategy generationStrategy);  }### Answer:
@Test public void newId() { assertEquals("abc", generator.newId("h1", "abc")); assertEquals("abc2", generator.newId("h1", "abc")); assertEquals("abc3", generator.newId("h2", "abc")); assertEquals("def", generator.newId("h1", "def")); assertTrue(generator.hasAnchorNames()); assertEquals(ImmutableSet.of("abc", "abc2", "abc3", "def"), generator.getAnchorNames()); }
@Test public void newIdNull() { assertEquals("h1-1", generator.newId("h1", null)); assertEquals("h1-2", generator.newId("h1", null)); assertEquals("h2-1", generator.newId("h2", null)); }