FileDAOUtility { public static String trim(String columnString, String fileEncoding, char trimChar, TrimType trimType) { if (TrimType.NONE.equals(trimType)) { return columnString; } if (!isHalfWidthChar(fileEncoding, trimChar)) { throw new FileException("Trim char is not half-width character."); } int start = 0; int length = columnString.length(); if (TrimType.LEFT.equals(trimType) || TrimType.BOTH.equals(trimType)) { while ((start < length) && columnString.charAt(start) == trimChar) { start++; } } if (TrimType.RIGHT.equals(trimType) || TrimType.BOTH.equals(trimType)) { while ((start < length) && columnString.charAt(length - 1) == trimChar) { length--; } } return columnString.substring(start, length); }  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 testTrim01() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.LEFT; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("1", result); }
@Test public void testTrim02() throws Exception { String columnString = "1aaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.LEFT; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("1aaa", result); }
@Test public void testTrim03() throws Exception { String columnString = "aaa1aaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.LEFT; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("1aaa", result); }
@Test public void testTrim04() throws Exception { String columnString = "1"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.RIGHT; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("1", result); }
@Test public void testTrim05() throws Exception { String columnString = "aaa1"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.RIGHT; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("aaa1", result); }
@Test public void testTrim06() throws Exception { String columnString = "aaa1aaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.RIGHT; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("aaa1", result); }
@Test public void testTrim07() throws Exception { String columnString = "aaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.NONE; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("aaa", result); }
@Test public void testTrim08() throws Exception { String columnString = "aaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'あ'; TrimType trimType = TrimType.LEFT; try { FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); fail("FileExceptionが発生しませんでした。"); } catch (FileException e) { assertEquals("Trim char is not half-width character.", e .getMessage()); } }
@Test public void testTrim09() throws Exception { String columnString = "aaa"; String fileEncoding = "XXX"; char trimChar = 'a'; TrimType trimType = TrimType.LEFT; try { FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); fail("FileExceptionが発生しませんでした。"); } catch (FileException e) { assertEquals("Specified Encoding : XXX is not supported", e .getMessage()); assertTrue(e.getCause() instanceof UnsupportedEncodingException); } }
@Test public void testTrim10() throws Exception { String columnString = "aaa"; String fileEncoding = "XXX"; char trimChar = 'あ'; TrimType trimType = TrimType.NONE; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("aaa", result); }
@Test public void testTrim11() throws Exception { String columnString = ""; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.LEFT; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("", result); }
@Test public void testTrim12() throws Exception { String columnString = ""; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.RIGHT; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("", result); }
@Test public void testTrim13() throws Exception { String columnString = ""; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.NONE; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("", result); }
@Test public void testTrim14() throws Exception { String columnString = "aaa1aaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.BOTH; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("1", result); }
@Test public void testTrim15() throws Exception { String columnString = ""; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.BOTH; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("", result); }
@Test public void testTrim16() throws Exception { String columnString = null; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.LEFT; try { FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); fail("NullPointerExceptionが発生しませんでした。"); } catch (NullPointerException e) { assertTrue(e instanceof NullPointerException); } }
@Test public void testTrim17() throws Exception { String columnString = "aaa1aaa"; String fileEncoding = null; char trimChar = 'a'; TrimType trimType = TrimType.LEFT; try { FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); fail("NullPointerExceptionが発生しませんでした。"); } catch (NullPointerException e) { assertTrue(e instanceof NullPointerException); } }
@Test public void testTrim18() throws Exception { String columnString = "aaa1aaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = null; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("aaa1aaa", result); }
@Test public void testTrim19() throws Exception { String columnString = "aaaaaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.BOTH; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("", result); }
@Test public void testTrim20() throws Exception { String columnString = "aaa１aaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.LEFT; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("１aaa", result); }
@Test public void testTrim21() throws Exception { String columnString = "aaa１aaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.RIGHT; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("aaa１", result); }
@Test public void testTrim22() throws Exception { String columnString = "aaa１aaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.NONE; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("aaa１aaa", result); }
@Test public void testTrim23() throws Exception { String columnString = "aaa１aaa"; String fileEncoding = "Shift_JIS"; char trimChar = 'a'; TrimType trimType = TrimType.BOTH; String result = FileDAOUtility.trim(columnString, fileEncoding, trimChar, trimType); assertNotNull(result); assertEquals("１", result); }