We want to implement the following functionality in class StringHelper:

This class should contain a method called reverseLastTwoCharacters that reverses the last 2 characters of a string (received as an argument):

  • If this string is null, then return null;
  • if empty,  return empty;
  • if length of string equal 1 return itself;
  • if length equal to 2, then reverse first character with second;
  • if length greater than 2, then reverse just last two characters
  • Ex: “A” -> “A”, “” -> “”, null ->  null, “AB” ->  “BA”, “RAIN”  ->  “RANI”
Apply TDD to develop this functionality.

You can use the following Maven skeleton project stringhelper.tgz for starting the project.

Attachments