HaikuReview { public boolean validateHaikuCharacters(String haiku) { String haikuWithoutSlashes = haiku.replace("/", ""); if (haikuWithoutSlashes.length() > 200) { return false; } return haiku.matches("[a-z }  String[] splitHaiku(String haiku); boolean validateHaikuCharacters(String haiku); int getNumberOfSyllables(String line); boolean isAConstantant(char character);  }
@Test public void testOnlyAllowLowercase() throws Exception { String lowercase = "a"; String uppercase = "A"; boolean valid = haikuReview.validateHaikuCharacters(lowercase); assertThat(valid).isTrue(); boolean invalid = haikuReview.validateHaikuCharacters(uppercase); assertThat(invalid).isFalse(); }
@Test public void testForwardSlashIsAValidCharacter() throws Exception { String forwardSlash = "/"; boolean invalid = haikuReview.validateHaikuCharacters(forwardSlash); assertThat(invalid).isTrue(); }
@Test public void testSpaceIsAValidCharacter() throws Exception { String space = " "; boolean invalid = haikuReview.validateHaikuCharacters(space); assertThat(invalid).isTrue(); }
@Test public void testAllow200Characters() throws Exception { String haiku = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaatwohundred"; boolean valid = haikuReview.validateHaikuCharacters(haiku); assertThat(valid).isTrue(); }
@Test public void testDontAllowMoreThan200Characters() throws Exception { String haiku = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaatwohundred1"; boolean valid = haikuReview.validateHaikuCharacters(haiku); assertThat(valid).isFalse(); }
@Test public void testAllowLessThan200Characters() throws Exception { String haiku = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaoneninenine"; boolean valid = haikuReview.validateHaikuCharacters(haiku); assertThat(valid).isTrue(); }
@Test public void testAllowLessThan200CharactersExcludingForwardSlash() throws Exception { String haiku = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaatwohundred/"; boolean valid = haikuReview.validateHaikuCharacters(haiku); assertThat(valid).isTrue(); }