@Test public void shouldReverseSentenceWithMoreThanOneWord() { String input = "pedro vicente gómez"; String result = reverseSentence.reverse(input); assertEquals("gómez vicente pedro", result); }
public String reverse(String sentence) { if (sentence == null) { throw new IllegalArgumentException("Input param can't be null."); } StringBuilder stringBuilder = new StringBuilder(); String[] words = sentence.split(WORD_SEPARATOR); for (int i = words.length - 1; i >= 0; i--) { stringBuilder.append(words[i]); if (i != 0) { stringBuilder.append(" "); } } return stringBuilder.toString(); }
ReverseSentence { public String reverse(String sentence) { if (sentence == null) { throw new IllegalArgumentException("Input param can't be null."); } StringBuilder stringBuilder = new StringBuilder(); String[] words = sentence.split(WORD_SEPARATOR); for (int i = words.length - 1; i >= 0; i--) { stringBuilder.append(words[i]); if (i != 0) { stringBuilder.append(" "); } } return stringBuilder.toString(); } }
ReverseSentence { public String reverse(String sentence) { if (sentence == null) { throw new IllegalArgumentException("Input param can't be null."); } StringBuilder stringBuilder = new StringBuilder(); String[] words = sentence.split(WORD_SEPARATOR); for (int i = words.length - 1; i >= 0; i--) { stringBuilder.append(words[i]); if (i != 0) { stringBuilder.append(" "); } } return stringBuilder.toString(); }  }
ReverseSentence { public String reverse(String sentence) { if (sentence == null) { throw new IllegalArgumentException("Input param can't be null."); } StringBuilder stringBuilder = new StringBuilder(); String[] words = sentence.split(WORD_SEPARATOR); for (int i = words.length - 1; i >= 0; i--) { stringBuilder.append(words[i]); if (i != 0) { stringBuilder.append(" "); } } return stringBuilder.toString(); }  String reverse(String sentence); }
ReverseSentence { public String reverse(String sentence) { if (sentence == null) { throw new IllegalArgumentException("Input param can't be null."); } StringBuilder stringBuilder = new StringBuilder(); String[] words = sentence.split(WORD_SEPARATOR); for (int i = words.length - 1; i >= 0; i--) { stringBuilder.append(words[i]); if (i != 0) { stringBuilder.append(" "); } } return stringBuilder.toString(); }  String reverse(String sentence);  }