StringIdGeneratorAlphaNumericImpl implements StringIdGenerator { @Override public String generateNewId(Object optionalDto) { StringBuilder ret = new StringBuilder(); while (ret.length() < 8) { int next = random.nextInt(alphabet.length()); ret.append(alphabet.charAt(next)); } return ret.toString(); } StringIdGeneratorAlphaNumericImpl();  StringIdGeneratorAlphaNumericImpl(int length); @Override String generateNewId(Object optionalDto); @Override boolean isValidId(String id); int getLength(); void setLength(int length); String getAlphabet(); void setAlphabet(String alphabet);  }
@Test public void testGenerateNewId() { StringIdGenerator f = new StringIdGeneratorAlphaNumericImpl(); String result = f.generateNewId(null); assertNotNull(result); assertEquals(8, result.length()); }