ThreePhraseGenerator { public String generate(char separator) { return new StringBuilder().append(select(verbs)).append(separator).append(select(adjectives)) .append(separator).append(select(nouns)).toString(); } ThreePhraseGenerator(); String generate(char separator);  }
@Test public void testGenerate() { final ThreePhraseGenerator tpg = new ThreePhraseGenerator(); final String phrase = tpg.generate('-'); assertNotNull("Generated string is null", phrase); assertNotEquals("Generated string is empty", "", phrase); }
@Test public void testGeneratesOnlyLetters() { final ThreePhraseGenerator tpg = new ThreePhraseGenerator(); for (int attempt = 1; attempt < 50000; ++attempt) { final String phrase = tpg.generate('x'); assertTrue("Generated string does not have at least five characters", 5 <= phrase.length()); for (int index = 0; index < phrase.length(); ++index) { final char c = phrase.charAt(index); assertTrue( "Character in \"" + phrase + "\" at index " + index + ", '" + c + "', is a not letter", Character.isLetter(c)); } } }