Justify { public static String trailing(String s, int len, char pad) { String input = s == null ? "" : s; StringBuffer sb = new StringBuffer(input); sb.setLength(len); if (input.length() < len) { for (int i = input.length(); i < len; i++) { sb.setCharAt(i, pad); } } return sb.toString(); } private  Justify(); static String left(String s, int len); static String trailing(String s, int len, char pad); static String right(String input, int size); static String leading(String s, int size, char pad);  }
@Test public void testTrailing() { assertEquals(TRAILING_PADDED, Justify.left(UNPADDED, 10)); assertEquals(TRAILING_PADDED, Justify.trailing(UNPADDED, 10, ' ')); assertEquals(" ", Justify.trailing(null, 10, ' ')); assertEquals(" ", Justify.trailing("", 10, ' ')); assertEquals("ABCDEFGHIJ", Justify.left("ABCDEFGHIJKLM", 10)); }