Candidate for Daily WTF

To cry…or laugh…that’s the question…

@Test
public void spaceFiller() {
   int l = 5;
   String result = MessageUtil.spaceFiller(5);
   if (result.length() == l) {
   } else {
      fail();
   }
}

When I came across the test code above I wondered who on Earth would write such a thing. The answer came shortly after when I had a look at the method it is testing…

/**
 * Space filler.
 * Creates a string filled with spaces of the wanted length
 *
 * @param length the length of the wanted string
 * @return the string
 */
public static String spaceFiller(int length){
   String s = "";
   for(int i=0; i < length; i++)
      s = s.concat(" ");
   return s;
}

The good thing is that they actually wrote a nice and clear JavaDoc explaining their own stupidity…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.