AbstractFileLineIterator implements
                                              FileLineIterator<T> { protected String readLine() { if (!hasNext()) { return null; } String currentReadLineString = null; try { currentReadLineString = lineReader.readLine(); } catch (FileException e) { throw new FileException("Processing of lineReader was failed.", e, fileName); } if (0 < trailerLineCount) { String pollingLineString = trailerQueue.poll(); trailerQueue.add(currentReadLineString); return pollingLineString; } return currentReadLineString; } AbstractFileLineIterator(String fileName, Class<T> clazz,
            Map<String, ColumnParser> columnParserMap); @Override boolean hasNext(); @Override T next(); @Override void remove(); @Override void closeFile(); @Override List<String> getHeader(); @Override List<String> getTrailer(); @Override void skip(int skipLines); int getCurrentLineCount();  }
@Test public void testBuildLineReader01() throws Exception { URL url = this.getClass().getResource( "AbstractFileLineIterator_buildLineReader01.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl03<AbstractFileLineIterator_Stub20> fileLineIterator = new AbstractFileLineIteratorImpl03<AbstractFileLineIterator_Stub20>( fileName, AbstractFileLineIterator_Stub20.class, columnParserMap); ReflectionTestUtils.setField(fileLineIterator, "enclosed", true); ReflectionTestUtils.setField(fileLineIterator, "columnEncloseChar", new char[] {}); Method method = AbstractFileLineIterator.class.getDeclaredMethod("buildLineReader"); method.setAccessible(true); method.invoke(fileLineIterator); Object reader = ReflectionTestUtils.getField(fileLineIterator, "reader"); assertEquals(BufferedReader.class, reader.getClass()); Field field = AbstractFileLineIterator.class.getDeclaredField("lineReader"); field.setAccessible(true); Object reader02 = field.get(fileLineIterator); assertEquals(EncloseCharLineFeed2LineReader.class, reader02.getClass()); field = EncloseCharLineFeed2LineReader.class.getDeclaredField("delimiterCharacter"); field.setAccessible(true); assertEquals(',', field.get(reader02)); assertEquals('\"', ReflectionTestUtils.getField(reader02, "encloseCharacter")); assertEquals("\r\n", ReflectionTestUtils.getField(reader02, "lineFeedChar")); assertSame(reader, ReflectionTestUtils.getField(reader02, "reader")); assertEquals("AbstractFileLineIterator_buildLineReader01", ((BufferedReader) reader).readLine()); ((BufferedReader) reader).close(); }
@Test public void testBuildLineReader02() throws Exception { URL url = this.getClass().getResource( "AbstractFileLineIterator_buildLineReader01.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl03<AbstractFileLineIterator_Stub21> fileLineIterator = new AbstractFileLineIteratorImpl03<AbstractFileLineIterator_Stub21>( fileName, AbstractFileLineIterator_Stub21.class, columnParserMap); ReflectionTestUtils.setField(fileLineIterator, "enclosed", true); ReflectionTestUtils.setField(fileLineIterator, "columnEncloseChar", new char[] {}); Method method = AbstractFileLineIterator.class.getDeclaredMethod("buildLineReader"); method.setAccessible(true); method.invoke(fileLineIterator); Object reader = ReflectionTestUtils.getField(fileLineIterator, "reader"); assertEquals(BufferedReader.class, reader.getClass()); Object reader02 = ReflectionTestUtils.getField(fileLineIterator, "lineReader"); assertEquals(EncloseCharLineFeed1LineReader.class, reader02.getClass()); assertEquals(',', ReflectionTestUtils.getField(reader02, "delimiterCharacter")); assertEquals('\"', ReflectionTestUtils.getField(reader02, "encloseCharacter")); assertEquals("\r", ReflectionTestUtils.getField(reader02, "lineFeedChar")); assertSame(reader, ReflectionTestUtils.getField(reader02, "reader")); assertEquals("AbstractFileLineIterator_buildLineReader01", ((BufferedReader) reader).readLine()); ((BufferedReader) reader).close(); }
@Test public void testBuildLineReader03() throws Exception { URL url = this.getClass().getResource( "AbstractFileLineIterator_buildLineReader01.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl04<AbstractFileLineIterator_Stub20> fileLineIterator = new AbstractFileLineIteratorImpl04<AbstractFileLineIterator_Stub20>( fileName, AbstractFileLineIterator_Stub20.class, columnParserMap); Method method = AbstractFileLineIterator.class.getDeclaredMethod("buildLineReader"); method.setAccessible(true); method.invoke(fileLineIterator); Object reader = ReflectionTestUtils.getField(fileLineIterator, "reader"); assertEquals(BufferedReader.class, reader.getClass()); Object reader02 = ReflectionTestUtils.getField(fileLineIterator, "lineReader"); assertEquals(LineFeed2LineReader.class, reader02.getClass()); assertEquals("\r\n", ReflectionTestUtils.getField(reader02, "lineFeedChar")); assertSame(reader, ReflectionTestUtils.getField(reader02, "reader")); assertEquals("AbstractFileLineIterator_buildLineReader01", ((BufferedReader) reader).readLine()); ((BufferedReader) reader).close(); }
@Test public void testBuildLineReader04() throws Exception { URL url = this.getClass().getResource( "AbstractFileLineIterator_buildLineReader01.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl04<AbstractFileLineIterator_Stub21> fileLineIterator = new AbstractFileLineIteratorImpl04<AbstractFileLineIterator_Stub21>( fileName, AbstractFileLineIterator_Stub21.class, columnParserMap); Method method = AbstractFileLineIterator.class.getDeclaredMethod("buildLineReader"); method.setAccessible(true); method.invoke(fileLineIterator); Object reader = ReflectionTestUtils.getField(fileLineIterator, "reader"); assertEquals(BufferedReader.class, reader.getClass()); Object reader02 = ReflectionTestUtils.getField(fileLineIterator, "lineReader"); assertEquals(LineFeed1LineReader.class, reader02.getClass()); assertEquals("\r", ReflectionTestUtils.getField(reader02, "lineFeedChar")); assertSame(reader, ReflectionTestUtils.getField(reader02, "reader")); assertEquals("AbstractFileLineIterator_buildLineReader01", ((BufferedReader) reader).readLine()); ((BufferedReader) reader).close(); }
@Test public void testBuildHeader01() throws Exception { URL url = this.getClass().getResource( "AbstractFileLineIterator_buildHeader01.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub60> fileLineIterator = PowerMockito.spy( new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub60>( fileName, AbstractFileLineIterator_Stub60.class, columnParserMap)); Method method = AbstractFileLineIterator.class.getDeclaredMethod("buildLineReader"); method.setAccessible(true); method.invoke(fileLineIterator); LineReader mockLineReader = Mockito.mock(LineReader.class); Mockito.doReturn("").when(mockLineReader).readLine(); ReflectionTestUtils.setField(fileLineIterator, "lineReader", mockLineReader); method = AbstractFileLineIterator.class.getDeclaredMethod("buildHeader"); method.setAccessible(true); method.invoke(fileLineIterator); Object header_object = ReflectionTestUtils.getField(fileLineIterator, "header"); assertEquals(ArrayList.class, header_object.getClass()); List<?> header = (List<?>) header_object; assertEquals(0, header.size()); Mockito.verify(mockLineReader, Mockito.never()).readLine(); }
@Test public void testBuildHeader02() throws Exception { URL url = this.getClass().getResource( "AbstractFileLineIterator_buildHeader01.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub61> fileLineIterator = new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub61>( fileName, AbstractFileLineIterator_Stub61.class, columnParserMap); Method method = AbstractFileLineIterator.class.getDeclaredMethod("buildLineReader"); method.setAccessible(true); method.invoke(fileLineIterator); LineReader mockLineReader = Mockito.mock(LineReader.class); Mockito.doReturn("1行目データ").when(mockLineReader).readLine(); ReflectionTestUtils.setField(fileLineIterator, "lineReader", mockLineReader); method = AbstractFileLineIterator.class.getDeclaredMethod("buildHeader"); method.setAccessible(true); method.invoke(fileLineIterator); Object header_object = ReflectionTestUtils.getField(fileLineIterator, "header"); assertEquals(ArrayList.class, header_object.getClass()); List<?> header = (List<?>) header_object; assertEquals(1, header.size()); assertEquals("1行目データ", header.get(0)); Mockito.verify(mockLineReader).readLine(); }
@Test public void testBuildHeader03() throws Exception { URL url = this.getClass().getResource( "AbstractFileLineIterator_buildHeader01.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub62> fileLineIterator = new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub62>( fileName, AbstractFileLineIterator_Stub62.class, columnParserMap); Method method = AbstractFileLineIterator.class.getDeclaredMethod("buildLineReader"); method.setAccessible(true); method.invoke(fileLineIterator); LineReader mockLineReader = Mockito.mock(LineReader.class); Mockito.doReturn("1行目データ").doReturn("2行目データ").doReturn("3行目データ").when(mockLineReader).readLine(); ReflectionTestUtils.setField(fileLineIterator, "lineReader", mockLineReader); method = AbstractFileLineIterator.class.getDeclaredMethod("buildHeader"); method.setAccessible(true); method.invoke(fileLineIterator); Object header_object = ReflectionTestUtils.getField(fileLineIterator, "header"); assertEquals(ArrayList.class, header_object.getClass()); List<?> header = (List<?>) header_object; assertEquals(3, header.size()); assertEquals("1行目データ", header.get(0)); assertEquals("2行目データ", header.get(1)); assertEquals("3行目データ", header.get(2)); Mockito.verify(mockLineReader, Mockito.times(3)).readLine(); }
@Test public void testBuildTrailerQueue01() throws Exception { URL url = this.getClass().getResource( "AbstractFileLineIterator_getTrailer01.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub70> fileLineIterator = new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub70>( fileName, AbstractFileLineIterator_Stub70.class, columnParserMap); Method method = AbstractFileLineIterator.class.getDeclaredMethod("buildLineReader"); method.setAccessible(true); method.invoke(fileLineIterator); LineReader lineReader = (LineReader) ReflectionTestUtils.getField(fileLineIterator, "lineReader"); lineReader = Mockito.spy(lineReader); ReflectionTestUtils.setField(fileLineIterator, "lineReader", lineReader); method = AbstractFileLineIterator.class.getDeclaredMethod("buildTrailerQueue"); method.setAccessible(true); method.invoke(fileLineIterator); Object trailerQueue_object = ReflectionTestUtils.getField(fileLineIterator, "trailerQueue"); assertNull(trailerQueue_object); Mockito.verify(lineReader, Mockito.never()).readLine(); }
@Test public void testBuildTrailerQueue02() throws Exception { URL url = this.getClass().getResource( "AbstractFileLineIterator_getTrailer01.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub71> fileLineIterator = new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub71>( fileName, AbstractFileLineIterator_Stub71.class, columnParserMap); Method method = AbstractFileLineIterator.class.getDeclaredMethod("buildLineReader"); method.setAccessible(true); method.invoke(fileLineIterator); LineReader lineReader = (LineReader) ReflectionTestUtils.getField(fileLineIterator, "lineReader"); lineReader = Mockito.spy(lineReader); ReflectionTestUtils.setField(fileLineIterator, "lineReader", lineReader); method = AbstractFileLineIterator.class.getDeclaredMethod("buildTrailerQueue"); method.setAccessible(true); method.invoke(fileLineIterator); Object trailerQueue_object = ReflectionTestUtils.getField(fileLineIterator, "trailerQueue"); assertEquals(ArrayBlockingQueue.class, trailerQueue_object.getClass()); ArrayBlockingQueue<?> trailerQueue = (ArrayBlockingQueue<?>) trailerQueue_object; assertEquals(1, trailerQueue.size()); assertEquals("Line data 3", trailerQueue.poll()); lineReader = (LineReader) ReflectionTestUtils.getField(fileLineIterator, "lineReader"); Mockito.verify(lineReader).readLine(); }
@Test public void testBuildTrailerQueue03() throws Exception { URL url = this.getClass().getResource( "AbstractFileLineIterator_getTrailer01.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub72> fileLineIterator = new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub72>( fileName, AbstractFileLineIterator_Stub72.class, columnParserMap); Method method = AbstractFileLineIterator.class.getDeclaredMethod("buildLineReader"); method.setAccessible(true); method.invoke(fileLineIterator); LineReader lineReader = (LineReader) ReflectionTestUtils.getField(fileLineIterator, "lineReader"); lineReader = Mockito.spy(lineReader); ReflectionTestUtils.setField(fileLineIterator, "lineReader", lineReader); method = AbstractFileLineIterator.class.getDeclaredMethod("buildTrailerQueue"); method.setAccessible(true); method.invoke(fileLineIterator); Object trailerQueue_object = ReflectionTestUtils.getField(fileLineIterator, "trailerQueue"); assertEquals(ArrayBlockingQueue.class, trailerQueue_object.getClass()); ArrayBlockingQueue<?> trailerQueue = (ArrayBlockingQueue<?>) trailerQueue_object; assertEquals(3, trailerQueue.size()); assertEquals("Line data 3", trailerQueue.poll()); assertEquals("Line data 4", trailerQueue.poll()); assertEquals("Line data 5", trailerQueue.poll()); lineReader = (LineReader) ReflectionTestUtils.getField(fileLineIterator, "lineReader"); Mockito.verify(lineReader, Mockito.times(3)).readLine(); }