AbstractFileLineWriter implements FileLineWriter<T> { public String getFileName() { return fileName; } AbstractFileLineWriter(String fileName, Class<T> clazz,
            Map<String, ColumnFormatter> columnFormatterMap); @Override void printHeaderLine(List<String> headerLine); @Override void printDataLine(T t); @Override void printTrailerLine(List<String> trailerLine); @Override void closeFile(); String getFileName(); void setColumnFormatterMap(
            Map<String, ColumnFormatter> columnFormatterMap); abstract char getDelimiter(); abstract char getEncloseChar();  }
@Test public void testAbstractFileLineWriter03() throws Exception { String fileName = "AbstractFileLineWriter_<init>03_fileName"; Class<AbstractFileLineWriter_Stub02> clazz = AbstractFileLineWriter_Stub02.class; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("int", new IntColumnFormatter()); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); try { new AbstractFileLineWriterImpl01<AbstractFileLineWriter_Stub02>(fileName, clazz, columnFormatterMap); fail("FileExceptionが発生しませんでした。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals("FileFormat annotation is not found.", e.getMessage()); assertTrue(IllegalStateException.class.isAssignableFrom(e.getCause() .getClass())); assertEquals(fileName, e.getFileName()); } }
@Test public void testAbstractFileLineWriter05() throws Exception { String fileName = "AbstractFileLineWriter_<init>05_fileName"; Class<AbstractFileLineWriter_Stub04> clazz = AbstractFileLineWriter_Stub04.class; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("int", new IntColumnFormatter()); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); try { new AbstractFileLineWriterImpl01<AbstractFileLineWriter_Stub04>(fileName, clazz, columnFormatterMap); fail("FileExceptionが発生しませんでした。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals("Delimiter is the same as EncloseChar and is no use.", e.getMessage()); assertTrue(IllegalStateException.class.isAssignableFrom(e.getCause() .getClass())); assertEquals(fileName, e.getFileName()); } }
@Test public void testBuildFields07() throws Exception { String fileName = "fileName"; Class<AbstractFileLineWriter_Stub14> clazz = AbstractFileLineWriter_Stub14.class; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("int", new IntColumnFormatter()); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); AbstractFileLineWriter<AbstractFileLineWriter_Stub14> fileLineWriter = new AbstractFileLineWriterImpl01<AbstractFileLineWriter_Stub14>(fileName, clazz, columnFormatterMap); ReflectionTestUtils.setField(fileLineWriter, "fields", null); try { Method method = AbstractFileLineWriter.class.getDeclaredMethod( "buildFields"); method.setAccessible(true); method.invoke(fileLineWriter); fail("FileExceptionが発生しませんでした。"); } catch (InvocationTargetException e) { assertTrue(FileException.class.isAssignableFrom(e .getTargetException().getClass())); assertEquals("Column Index is duplicate : 1", e.getTargetException() .getMessage()); assertEquals(fileName, ((FileException) e.getTargetException()) .getFileName()); } }
@Test public void testBuildFields09() throws Exception { String fileName = "fileName"; Class<AbstractFileLineWriter_Stub16> clazz = AbstractFileLineWriter_Stub16.class; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("int", new IntColumnFormatter()); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); AbstractFileLineWriter<AbstractFileLineWriter_Stub16> fileLineWriter = new AbstractFileLineWriterImpl01<AbstractFileLineWriter_Stub16>(fileName, clazz, columnFormatterMap); ReflectionTestUtils.setField(fileLineWriter, "fields", null); try { Method method = AbstractFileLineWriter.class.getDeclaredMethod( "buildFields"); method.setAccessible(true); method.invoke(fileLineWriter); fail("FileExceptionが発生しませんでした。"); } catch (InvocationTargetException e) { assertTrue(IllegalStateException.class.isAssignableFrom(e .getTargetException().getCause().getClass())); assertEquals("Column Index in FileLineObject is bigger than the " + "total number of the field.", e.getTargetException() .getMessage()); assertEquals(fileName, ((FileException) e.getTargetException()) .getFileName()); Field[] resultFields = (Field[]) ReflectionTestUtils.getField( fileLineWriter, "fields"); assertNull(resultFields); } }
@Test public void testBuildFields10() throws Exception { String fileName = "fileName"; Class<AbstractFileLineWriter_Stub17> clazz = AbstractFileLineWriter_Stub17.class; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("int", new IntColumnFormatter()); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); AbstractFileLineWriter<AbstractFileLineWriter_Stub17> fileLineWriter = new AbstractFileLineWriterImpl01<AbstractFileLineWriter_Stub17>(fileName, clazz, columnFormatterMap); ReflectionTestUtils.setField(fileLineWriter, "fields", null); try { Method method = AbstractFileLineWriter.class.getDeclaredMethod( "buildFields"); method.setAccessible(true); method.invoke(fileLineWriter); fail("FileExceptionが発生しませんでした。"); } catch (InvocationTargetException e) { assertTrue(IllegalStateException.class.isAssignableFrom(e .getTargetException().getCause().getClass())); assertEquals("Column Index in FileLineObject is the minus number.", e.getTargetException().getMessage()); assertEquals(fileName, ((FileException) e.getTargetException()) .getFileName()); Field[] resultFields = (Field[]) ReflectionTestUtils.getField( fileLineWriter, "fields"); assertNull(resultFields); } }
@Test public void testBuildFields13() throws Exception { String fileName = "fileName"; Class<AbstractFileLineWriter_Stub40> clazz = AbstractFileLineWriter_Stub40.class; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("int", new IntColumnFormatter()); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); AbstractFileLineWriter<AbstractFileLineWriter_Stub40> fileLineWriter = new AbstractFileLineWriterImpl01<AbstractFileLineWriter_Stub40>(fileName, clazz, columnFormatterMap); ReflectionTestUtils.setField(fileLineWriter, "fields", null); try { Method method = AbstractFileLineWriter.class.getDeclaredMethod( "buildFields"); method.setAccessible(true); method.invoke(fileLineWriter); fail("FileExceptionが発生しませんでした。"); } catch (InvocationTargetException e) { assertTrue(IllegalStateException.class.isAssignableFrom(e .getTargetException().getCause().getClass())); assertEquals("There is a type which isn't supported in a mapping " + "target field in FileLineObject.", e.getTargetException() .getMessage()); assertEquals(fileName, ((FileException) e.getTargetException()) .getFileName()); Field[] resultFields = (Field[]) ReflectionTestUtils.getField( fileLineWriter, "fields"); assertNull(resultFields); } }
@SuppressWarnings("rawtypes") @Test public void testBuildStringConverters05() throws Exception { String fileName = "fileName"; Class<AbstractFileLineWriter_Stub23> clazz = AbstractFileLineWriter_Stub23.class; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("int", new IntColumnFormatter()); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); AbstractFileLineWriter<AbstractFileLineWriter_Stub23> fileLineWriter = new AbstractFileLineWriterImpl01<AbstractFileLineWriter_Stub23>(fileName, clazz, columnFormatterMap); Method method = AbstractFileLineWriter.class.getDeclaredMethod( "buildFields"); method.setAccessible(true); method.invoke(fileLineWriter); Map<Class, StringConverter> preStringConverterCacheMap = new HashMap<Class, StringConverter>(); Field field = AbstractFileLineWriter.class.getDeclaredField( "stringConverterCacheMap"); field.setAccessible(true); field.set(AbstractFileLineWriter.class, preStringConverterCacheMap); try { method = AbstractFileLineWriter.class.getDeclaredMethod( "buildStringConverters"); method.setAccessible(true); method.invoke(fileLineWriter); fail("FileLineExceptionが発生しませんでした。"); } catch (InvocationTargetException e) { assertTrue(FileLineException.class.isAssignableFrom(e .getTargetException().getClass())); assertEquals("Failed in an instantiate of a stringConverter.", e .getTargetException().getMessage()); assertTrue(InstantiationException.class.isAssignableFrom(e .getTargetException().getCause().getClass())); assertEquals(fileName, ((FileLineException) e.getTargetException()) .getFileName()); assertEquals(-1, ((FileLineException) e.getTargetException()) .getLineNo()); assertEquals("column1", ((FileLineException) e.getTargetException()) .getColumnName()); assertEquals(0, ((FileLineException) e.getTargetException()) .getColumnIndex()); } finally { field = AbstractFileLineWriter.class.getDeclaredField( "stringConverterCacheMap"); field.setAccessible(true); field.set(AbstractFileLineWriter.class, new HashMap<Class, StringConverter>()); } }
@SuppressWarnings("rawtypes") @Test public void testBuildStringConverters06() throws Exception { String fileName = "fileName"; Class<AbstractFileLineWriter_Stub24> clazz = AbstractFileLineWriter_Stub24.class; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("int", new IntColumnFormatter()); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); AbstractFileLineWriter<AbstractFileLineWriter_Stub24> fileLineWriter = new AbstractFileLineWriterImpl01<AbstractFileLineWriter_Stub24>(fileName, clazz, columnFormatterMap); Method method = AbstractFileLineWriter.class.getDeclaredMethod( "buildFields"); method.setAccessible(true); method.invoke(fileLineWriter); Map<Class, StringConverter> preStringConverterCacheMap = new HashMap<Class, StringConverter>(); Field field = AbstractFileLineWriter.class.getDeclaredField( "stringConverterCacheMap"); field.setAccessible(true); field.set(AbstractFileLineWriter.class, preStringConverterCacheMap); try { method = AbstractFileLineWriter.class.getDeclaredMethod( "buildStringConverters"); method.setAccessible(true); method.invoke(fileLineWriter); fail("FileLineExceptionが発生しませんでした。"); } catch (InvocationTargetException e) { assertTrue(FileLineException.class.isAssignableFrom(e .getTargetException().getClass())); assertEquals("Failed in an instantiate of a stringConverter.", e .getTargetException().getMessage()); assertTrue(IllegalAccessException.class.isAssignableFrom(e .getTargetException().getCause().getClass())); assertEquals(fileName, ((FileLineException) e.getTargetException()) .getFileName()); assertEquals(-1, ((FileLineException) e.getTargetException()) .getLineNo()); assertEquals("column1", ((FileLineException) e.getTargetException()) .getColumnName()); assertEquals(0, ((FileLineException) e.getTargetException()) .getColumnIndex()); } finally { field = AbstractFileLineWriter.class.getDeclaredField( "stringConverterCacheMap"); field.setAccessible(true); field.set(AbstractFileLineWriter.class, new HashMap<Class, StringConverter>()); } }
@SuppressWarnings("rawtypes") @Test public void testBuildMethods03() throws Exception { String fileName = "fileName"; Class<AbstractFileLineWriter_Stub25> clazz = AbstractFileLineWriter_Stub25.class; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("int", new IntColumnFormatter()); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); AbstractFileLineWriter<AbstractFileLineWriter_Stub25> fileLineWriter = new AbstractFileLineWriterImpl01<AbstractFileLineWriter_Stub25>(fileName, clazz, columnFormatterMap); Method method = AbstractFileLineWriter.class.getDeclaredMethod( "buildFields"); method.setAccessible(true); method.invoke(fileLineWriter); method = AbstractFileLineWriter.class.getDeclaredMethod( "buildStringConverters"); method.setAccessible(true); method.invoke(fileLineWriter); try { method = AbstractFileLineWriter.class.getDeclaredMethod( "buildMethods"); method.setAccessible(true); method.invoke(fileLineWriter); fail("FileExceptionが発生しませんでした。"); } catch (InvocationTargetException e) { assertTrue(FileException.class.isAssignableFrom(e .getTargetException().getClass())); assertEquals("The getter method of column doesn't exist.", e .getTargetException().getMessage()); assertTrue(NoSuchMethodException.class.isAssignableFrom(e .getTargetException().getCause().getClass())); assertEquals(fileName, ((FileException) e.getTargetException()) .getFileName()); } finally { Field field = AbstractFileLineWriter.class.getDeclaredField( "stringConverterCacheMap"); field.setAccessible(true); field.set(AbstractFileLineWriter.class, new HashMap<Class, StringConverter>()); } }
@Test public void testGetFileName01() throws Exception { String fileName = "fileName"; Class<AbstractFileLineWriter_Stub01> clazz = AbstractFileLineWriter_Stub01.class; Map<String, ColumnFormatter> columnFormatterMap = new HashMap<String, ColumnFormatter>(); columnFormatterMap.put("int", new IntColumnFormatter()); columnFormatterMap.put("java.lang.String", new NullColumnFormatter()); AbstractFileLineWriter<AbstractFileLineWriter_Stub01> fileLineWriter = new AbstractFileLineWriterImpl01<AbstractFileLineWriter_Stub01>(fileName, clazz, columnFormatterMap); ReflectionTestUtils.setField(fileLineWriter, "fileName", fileName); String result = fileLineWriter.getFileName(); assertNotNull(result); assertSame(fileName, result); }