### Question:
IdGenerator { public String generateUniqueId(String text) { return generateUniqueId("I", text); } IdGenerator();  IdGenerator(IdGenerator idGenerator); String generateUniqueId(String text); String generateUniqueId(String prefix, String text); void remove(String id); void reset();  }### Answer:
@Test public void generateUniqueId() { assertEquals("Itext", this.idGenerator.generateUniqueId("text")); assertEquals("Itext-1", this.idGenerator.generateUniqueId("te xt")); }
@Test public void generateUniqueIdWithPrefix() { assertEquals("prefixtext", this.idGenerator.generateUniqueId("prefix", "text")); assertEquals("prefixtext-1", this.idGenerator.generateUniqueId("prefix", "te xt")); }
@Test public void generateUniqueIdFromNonAlphaNum() { assertEquals("I:_.-", this.idGenerator.generateUniqueId(":_.-")); assertEquals("Iwithspace", this.idGenerator.generateUniqueId("with space")); assertEquals("Iwithtab", this.idGenerator.generateUniqueId("with\ttab")); assertEquals("I5BC67801", this.idGenerator.generateUniqueId("\u5BC6\u7801")); assertEquals("I3D", this.idGenerator.generateUniqueId("=")); }
@Test public void generateUniqueIdWhenInvalidEmptyPrefix() { Throwable exception = assertThrows(IllegalArgumentException.class, () -> { this.idGenerator.generateUniqueId("", "whatever"); }); assertEquals("The prefix [] should only contain alphanumerical characters and not be empty.", exception.getMessage()); }
@Test public void generateUniqueIdWhenInvalidNonAlphaPrefix() { Throwable exception = assertThrows(IllegalArgumentException.class, () -> { this.idGenerator.generateUniqueId("a-b", "whatever"); }); assertEquals("The prefix [a-b] should only contain alphanumerical characters and not be empty.", exception.getMessage()); }