@Override
  public int countWords(Note note) {
    int count = 0;
    String[] fields = {note.getTitle(), note.getContent()};
    for (String field : fields) {
      field = sanitizeTextForWordsAndCharsCount(note, field);
      boolean word = false;
      int endOfLine = field.length() - 1;
      for (int i = 0; i < field.length(); i++) {
        // if the char is a letter, word = true.
        if (Character.isLetter(field.charAt(i)) && i != endOfLine) {
          word = true;
          // if char isn't a letter and there have been letters before, counter goes up.
        } else if (!Character.isLetter(field.charAt(i)) && word) {
          count++;
          word = false;
          // last word of String; if it doesn't end with a non letter, it  wouldn't count without this.
        } else if (Character.isLetter(field.charAt(i)) && i == endOfLine) {
          count++;
        }
      }
    }
    return count;
  }
@Test
  public void getWords() {
    Note note = getNote(1L, "one two", "three\n four five");
    assertEquals(5, new DefaultWordCounter().countWords(note));
    note.setTitle("singleword");
    assertEquals(4, new DefaultWordCounter().countWords(note));
  }