AbstractFileLineIterator implements
                                              FileLineIterator<T> { protected void init() { if (!calledInit) { buildFields(); if (isCheckEncloseChar()) { if (isEnclosed()) { throw new FileException("columnEncloseChar can not change.", new IllegalStateException(), fileName); } } if (isCheckColumnAnnotationCount()) { if (fields.length == 0) { throw new FileException("InputFileColumn is not found.", new IllegalStateException(), fileName); } } buildStringConverters(); buildMethods(); try { buildLineReader(); buildHeader(); buildTrailerQueue(); } catch (FileException e) { if (this.reader != null) { try { closeFile(); } catch (FileException fe) { } } throw e; } calledInit = true; } } 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 testInit01() throws Exception { URL url = this.getClass().getResource( "AbstractFileLineIterator_next06.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07> fileLineIterator = PowerMockito.spy( new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07>( fileName, AbstractFileLineIterator_Stub07.class, columnParserMap)); ReflectionTestUtils.setField(fileLineIterator, "calledInit", true); fileLineIterator.init(); assertTrue((Boolean) ReflectionTestUtils.getField(fileLineIterator, "calledInit")); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildFields"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildStringConverters"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildMethods"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildLineReader"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildHeader"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildTrailerQueue"); }
@Test public void testInit02() throws Exception { URL url = this.getClass().getResource("File_Empty.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07> fileLineIterator = PowerMockito.spy( new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07>( fileName, AbstractFileLineIterator_Stub07.class, columnParserMap)); ReflectionTestUtils.setField(fileLineIterator, "calledInit", false); fileLineIterator.init(); assertTrue((Boolean) ReflectionTestUtils.getField(fileLineIterator, "calledInit")); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildFields"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildStringConverters"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildMethods"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildLineReader"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildHeader"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildTrailerQueue"); }
@Test public void testInit03() throws Exception { URL url = this.getClass().getResource("File_Empty.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07> fileLineIterator = PowerMockito.spy( new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07>( fileName, AbstractFileLineIterator_Stub07.class, columnParserMap)); ReflectionTestUtils.setField(fileLineIterator, "calledInit", false); FileException exception = new FileException("buildFieldsのエラーです"); PowerMockito.doThrow(exception).when(fileLineIterator, "buildFields"); try { fileLineIterator.init(); fail("FileExceptionがスローされませんでした。"); } catch (FileException e) { assertFalse((Boolean) ReflectionTestUtils.getField(fileLineIterator, "calledInit")); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildFields"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildStringConverters"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildMethods"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildLineReader"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildHeader"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildTrailerQueue"); assertSame(exception, e); } }
@Test public void testInit04() throws Exception { URL url = this.getClass().getResource("File_Empty.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07> fileLineIterator = PowerMockito.spy( new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07>( fileName, AbstractFileLineIterator_Stub07.class, columnParserMap)); ReflectionTestUtils.setField(fileLineIterator, "calledInit", false); FileLineException exception = new FileLineException( "buildStringConvertersのエラーです"); PowerMockito.doThrow(exception).when(fileLineIterator, "buildStringConverters"); try { fileLineIterator.init(); fail("FileLineExceptionがスローされませんでした。"); } catch (FileLineException e) { assertFalse((Boolean) ReflectionTestUtils.getField(fileLineIterator, "calledInit")); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildFields"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildStringConverters"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildMethods"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildLineReader"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildHeader"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildTrailerQueue"); assertSame(exception, e); } }
@Test public void testInit05() throws Exception { URL url = this.getClass().getResource("File_Empty.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07> fileLineIterator = PowerMockito.spy( new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07>( fileName, AbstractFileLineIterator_Stub07.class, columnParserMap)); ReflectionTestUtils.setField(fileLineIterator, "calledInit", false); FileException exception = new FileException("buildMethodsのエラーです"); PowerMockito.doThrow(exception).when(fileLineIterator, "buildMethods"); try { fileLineIterator.init(); fail("FileExceptionがスローされませんでした。"); } catch (FileException e) { assertFalse((Boolean) ReflectionTestUtils.getField(fileLineIterator, "calledInit")); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildFields"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildStringConverters"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildMethods"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildLineReader"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildHeader"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildTrailerQueue"); assertSame(exception, e); } }
@Test public void testInit06() throws Exception { URL url = this.getClass().getResource("File_Empty.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07> fileLineIterator = PowerMockito.spy( new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07>( fileName, AbstractFileLineIterator_Stub07.class, columnParserMap)); ReflectionTestUtils.setField(fileLineIterator, "calledInit", false); FileException exception = new FileException("buildHeadersのエラーです"); PowerMockito.doThrow(exception).when(fileLineIterator, "buildHeader"); try { fileLineIterator.init(); fail("FileExceptionがスローされませんでした。"); } catch (FileException e) { assertFalse((Boolean) ReflectionTestUtils.getField(fileLineIterator, "calledInit")); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildFields"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildStringConverters"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildMethods"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildLineReader"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildHeader"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildTrailerQueue"); assertSame(exception, e); } }
@Test public void testInit07() throws Exception { URL url = this.getClass().getResource("File_Empty.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07> fileLineIterator = PowerMockito.spy( new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07>( fileName, AbstractFileLineIterator_Stub07.class, columnParserMap)); ReflectionTestUtils.setField(fileLineIterator, "calledInit", false); FileException exception = new FileException("buildTrailerQueueのエラーです"); PowerMockito.doThrow(exception).when(fileLineIterator, "buildTrailerQueue"); try { fileLineIterator.init(); fail("FileExceptionがスローされませんでした。"); } catch (FileException e) { assertFalse((Boolean) ReflectionTestUtils.getField(fileLineIterator, "calledInit")); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildStringConverters"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildMethods"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildLineReader"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildHeader"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildTrailerQueue"); assertSame(exception, e); } }
@Test public void testInit08() throws Exception { URL url = this.getClass().getResource("File_Empty.txt"); String fileName = url.getPath(); Map<String, ColumnParser> columnParserMap = new HashMap<String, ColumnParser>(); columnParserMap.put("java.lang.String", new NullColumnParser()); AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07> fileLineIterator = PowerMockito.spy( new AbstractFileLineIteratorImpl02<AbstractFileLineIterator_Stub07>( fileName, AbstractFileLineIterator_Stub07.class, columnParserMap)); ReflectionTestUtils.setField(fileLineIterator, "calledInit", false); FileException exception = new FileException("buildLineReaderのエラーです"); PowerMockito.doThrow(exception).when(fileLineIterator, "buildLineReader"); try { fileLineIterator.init(); fail("FileExceptionがスローされませんでした。"); } catch (FileException e) { assertFalse((Boolean) ReflectionTestUtils.getField(fileLineIterator, "calledInit")); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildStringConverters"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildMethods"); PowerMockito.verifyPrivate(fileLineIterator).invoke("buildLineReader"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildHeader"); PowerMockito.verifyPrivate(fileLineIterator, Mockito.never()).invoke("buildTrailerQueue"); assertSame(exception, e); } }