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);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullStringsAsInput() { reverseSentence.reverse(null); }
@Test public void shouldReturnEmptyIfInputIsEmpty() { assertEquals("", reverseSentence.reverse("")); }
@Test public void shouldReverseOneSentenceWithJustOneWord() { String input = "pedro"; String result = reverseSentence.reverse(input); assertEquals("pedro", result); }
@Test public void shouldReverseSentenceWithMoreThanOneWord() { String input = "pedro vicente gómez"; String result = reverseSentence.reverse(input); assertEquals("gómez vicente pedro", result); }