VariableFileLineWriter extends AbstractFileLineWriter<T> { @Override protected String getColumn(T t, int index) { String columnString = super.getColumn(t, index); if (getColumnEncloseChar()[index] == Character.MIN_VALUE) { return columnString; } else { StringBuilder builder = new StringBuilder(); for (int i = 0; i < columnString.length(); i++) { char columnChar = columnString.charAt(i); builder.append(columnChar); if (getColumnEncloseChar()[index] == columnChar) { builder.append(columnChar); } } return builder.toString(); } } VariableFileLineWriter(String fileName, Class<T> clazz,
            Map<String, ColumnFormatter> columnFormatterMap); @Override char getDelimiter(); @Override char getEncloseChar();  }
@Test public void testGetColumn01() throws Exception { String fileName = TEMP_FILE_NAME; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); VariableFileLineWriter<VariableFileLineWriter_Stub05> lineWriter = Mockito .spy(new VariableFileLineWriter<VariableFileLineWriter_Stub05>(fileName, VariableFileLineWriter_Stub05.class, columnFormatterMap)); VariableFileLineWriter_Stub05 t = new VariableFileLineWriter_Stub05(); t.setColumn01("abcdef"); int index = 0; try { String result = lineWriter.getColumn(t, index); assertEquals("abcdef", result); } finally { lineWriter.closeFile(); } }
@Test public void testGetColumn02() throws Exception { String fileName = TEMP_FILE_NAME; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); VariableFileLineWriter<VariableFileLineWriter_Stub06> lineWriter = new VariableFileLineWriter<VariableFileLineWriter_Stub06>(fileName, VariableFileLineWriter_Stub06.class, columnFormatterMap); VariableFileLineWriter_Stub06 t = new VariableFileLineWriter_Stub06(); t.setColumn01("abcdef"); int index = 0; try { String result = lineWriter.getColumn(t, index); assertEquals("abcdef", result); } finally { lineWriter.closeFile(); } }
@Test public void testGetColumn03() throws Exception { String fileName = TEMP_FILE_NAME; Map<String, ColumnFormatter> textGetterMap = new HashMap<String, ColumnFormatter>(); textGetterMap.put("java.lang.String", new NullColumnFormatter()); VariableFileLineWriter<VariableFileLineWriter_Stub06> lineWriter = new VariableFileLineWriter<VariableFileLineWriter_Stub06>(fileName, VariableFileLineWriter_Stub06.class, textGetterMap); VariableFileLineWriter_Stub06 t = new VariableFileLineWriter_Stub06(); t.setColumn01("ab\"cdef"); int index = 0; try { String result = lineWriter.getColumn(t, index); assertEquals("ab\"\"cdef", result); } finally { lineWriter.closeFile(); } }
@Test public void testGetColumn04() throws Exception { String fileName = TEMP_FILE_NAME; Map<String, ColumnFormatter> textGetterMap = new HashMap<String, ColumnFormatter>(); textGetterMap.put("java.lang.String", new NullColumnFormatter()); VariableFileLineWriter<VariableFileLineWriter_Stub06> lineWriter = new VariableFileLineWriter<VariableFileLineWriter_Stub06>(fileName, VariableFileLineWriter_Stub06.class, textGetterMap); VariableFileLineWriter_Stub06 t = null; int index = 0; try { lineWriter.getColumn(t, index); fail("NullPointerExceptionがスローされませんでした。"); } catch (NullPointerException e) { assertEquals(NullPointerException.class, e.getClass()); } finally { lineWriter.closeFile(); } }
@Test public void testGetColumn05() throws Exception { String fileName = TEMP_FILE_NAME; Map<String, ColumnFormatter> textGetterMap = new HashMap<String, ColumnFormatter>(); textGetterMap.put("java.lang.String", new NullColumnFormatter()); VariableFileLineWriter<VariableFileLineWriter_Stub08> lineWriter = new VariableFileLineWriter<VariableFileLineWriter_Stub08>(fileName, VariableFileLineWriter_Stub08.class, textGetterMap); VariableFileLineWriter_Stub08 t = new VariableFileLineWriter_Stub08(); t.setColumn01("abcdef"); t.setColumn02("aaabbb"); int index = 1; try { String result = lineWriter.getColumn(t, index); assertEquals("aaabbb", result); } finally { lineWriter.closeFile(); } }