FileDAOUtility { public static String padding(String columnString, String fileEncoding, int columnBytes, char paddingChar, PaddingType paddingType) { if (PaddingType.NONE.equals(paddingType)) { return columnString; } if (!isHalfWidthChar(fileEncoding, paddingChar)) { throw new FileException("Padding char is not half-width character."); } try { int paddingSize = columnBytes - columnString.getBytes(fileEncoding).length; if (paddingSize <= 0) { return columnString; } StringBuilder columnBuilder = new StringBuilder(columnBytes); char[] fillChars = new char[paddingSize]; Arrays.fill(fillChars, paddingChar); if (PaddingType.LEFT.equals(paddingType)) { columnBuilder.append(fillChars).append(columnString); return columnBuilder.toString(); } else if (PaddingType.RIGHT.equals(paddingType)) { columnBuilder.append(columnString).append(fillChars); return columnBuilder.toString(); } else { return columnString; } } catch (UnsupportedEncodingException e) { throw new FileException("Specified Encoding : " + fileEncoding + " is not supported", e); } }  static String padding(String columnString, String fileEncoding,
            int columnBytes, char paddingChar, PaddingType paddingType); static String trim(String columnString, String fileEncoding,
            char trimChar, TrimType trimType);  }
@Test public void testPadding01() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; int columnBytes = 0; char paddingChar = ' '; PaddingType paddingType = PaddingType.LEFT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("1", result); }
@Test public void testPadding02() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; int columnBytes = 1; char paddingChar = ' '; PaddingType paddingType = PaddingType.LEFT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("1", result); }
@Test public void testPadding03() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = PaddingType.LEFT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals(" 1", result); }
@Test public void testPadding04() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; int columnBytes = 0; char paddingChar = ' '; PaddingType paddingType = PaddingType.RIGHT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("1", result); }
@Test public void testPadding05() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; int columnBytes = 1; char paddingChar = ' '; PaddingType paddingType = PaddingType.RIGHT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("1", result); }
@Test public void testPadding06() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = PaddingType.RIGHT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("1 ", result); }
@Test public void testPadding07() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = PaddingType.NONE; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("1", result); }
@Test public void testPadding08() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = PaddingType.LEFT; try { FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); fail("FileException例外が発生しませんでした。"); } catch (FileException e) { assertEquals("Padding char is not half-width character.", e .getMessage()); } }
@Test public void testPadding09() throws Exception { String columnString = "1"; String fileEncoding = "XXX"; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = PaddingType.LEFT; try { FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); fail("FileException例外が発生しませんでした。"); } catch (FileException e) { assertEquals("Specified Encoding : XXX is not supported", e .getMessage()); assertTrue(e.getCause() instanceof UnsupportedEncodingException); } }
@Test public void testPadding10() throws Exception { String columnString = "1"; String fileEncoding = "XXX"; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = PaddingType.NONE; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("1", result); }
@Test public void testPadding11() throws Exception { String columnString = ""; String fileEncoding = "Shift_JIS"; int columnBytes = 0; char paddingChar = '!'; PaddingType paddingType = PaddingType.LEFT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("", result); }
@Test public void testPadding12() throws Exception { String columnString = ""; String fileEncoding = "Shift_JIS"; int columnBytes = 0; char paddingChar = '!'; PaddingType paddingType = PaddingType.LEFT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("", result); }
@Test public void testPadding13() throws Exception { String columnString = ""; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = '!'; PaddingType paddingType = PaddingType.LEFT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("!!!", result); }
@Test public void testPadding14() throws Exception { String columnString = ""; String fileEncoding = "Shift_JIS"; int columnBytes = 0; char paddingChar = '!'; PaddingType paddingType = PaddingType.RIGHT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("", result); }
@Test public void testPadding15() throws Exception { String columnString = ""; String fileEncoding = "Shift_JIS"; int columnBytes = 0; char paddingChar = '!'; PaddingType paddingType = PaddingType.RIGHT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("", result); }
@Test public void testPadding16() throws Exception { String columnString = ""; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = '!'; PaddingType paddingType = PaddingType.RIGHT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("!!!", result); }
@Test public void testPadding17() throws Exception { String columnString = ""; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = '!'; PaddingType paddingType = PaddingType.NONE; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("", result); }
@Test public void testPadding18() throws Exception { String columnString = null; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = PaddingType.LEFT; try { FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); fail("NullPointerExceptionが発生しませんでした。"); } catch (NullPointerException e) { assertTrue(e instanceof NullPointerException); } }
@Test public void testPadding19() throws Exception { String columnString = "1"; String fileEncoding = null; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = PaddingType.LEFT; try { FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); fail("NullPointerExceptionが発生しませんでした。"); } catch (NullPointerException e) { assertTrue(e instanceof NullPointerException); } }
@Test public void testPadding20() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; int columnBytes = -3; char paddingChar = ' '; PaddingType paddingType = PaddingType.LEFT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("1", result); }
@Test public void testPadding21() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = null; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("1", result); }
@Test public void testPadding22() throws Exception { String columnString = "１"; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = PaddingType.LEFT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals(" １", result); }
@Test public void testPadding23() throws Exception { String columnString = "１"; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = PaddingType.RIGHT; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("１ ", result); }
@Test public void testPadding24() throws Exception { String columnString = "１"; String fileEncoding = "Shift_JIS"; int columnBytes = 3; char paddingChar = ' '; PaddingType paddingType = PaddingType.NONE; String result = FileDAOUtility.padding(columnString, fileEncoding, columnBytes, paddingChar, paddingType); assertNotNull(result); assertEquals("１", result); }