### Question:
RightPadder implements Padder { public String pad(String data, int maxLength) throws ISOException { int len = data.length(); if (len < maxLength) { StringBuilder padded = new StringBuilder(maxLength); padded.append(data); for (; len < maxLength; len++) { padded.append(pad); } data = padded.toString(); } else if (len > maxLength) { throw new ISOException("Data is too long. Max = " + maxLength); } return data; } RightPadder(char pad); String pad(String data, int maxLength); String unpad(String paddedData); static final RightPadder SPACE_PADDER; }### Answer:
@Test public void testPaddingNeeded() throws Exception { assertEquals("123000", padder.pad("123", 6)); }
@Test public void testNoPaddingNeeded() throws Exception { assertEquals("123", padder.pad("123", 3)); }
@Test public void testPadLengthTooShort() throws Exception { try { padder.pad("123", 2); fail("Padding a bigger string into a smaller buffer should throw an exception"); } catch (Exception asIExpected) { } }