### Question:
TextFileOutput extends BaseStep implements StepInterface { protected boolean closeFile() { boolean retval = false; try { if ( data.writer != null ) { data.writer.flush(); if ( data.cmdProc != null ) { if ( log.isDebug() ) { logDebug( "Closing output stream" ); } data.writer.close(); if ( log.isDebug() ) { logDebug( "Closed output stream" ); } } } data.writer = null; if ( data.cmdProc != null ) { if ( log.isDebug() ) { logDebug( "Ending running external command" ); } int procStatus = data.cmdProc.waitFor(); try { data.cmdProc.getErrorStream().close(); data.cmdProc.getOutputStream().flush(); data.cmdProc.getOutputStream().close(); data.cmdProc.getInputStream().close(); } catch ( IOException e ) { if ( log.isDetailed() ) { logDetailed( "Warning: Error closing streams: " + e.getMessage() ); } } data.cmdProc = null; if ( log.isBasic() && procStatus != 0 ) { logBasic( "Command exit status: " + procStatus ); } } else { if ( log.isDebug() ) { logDebug( "Closing normal file ..." ); } if ( data.out != null ) { data.out.close(); } if ( data.fos != null ) { data.fos.close(); data.fos = null; } } retval = true; } catch ( Exception e ) { logError( "Exception trying to close file: " + e.toString() ); setErrors( 1 ); retval = false; } return retval; } TextFileOutput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
      Trans trans ); synchronized boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void writeRowToFile( RowMetaInterface rowMeta, Object[] r ); String buildFilename( String filename, boolean ziparchive ); void openNewFile( String baseFilename ); boolean checkPreviouslyOpened( String filename ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); boolean containsSeparatorOrEnclosure( byte[] source, byte[] separator, byte[] enclosure ); public TextFileOutputMeta meta; public TextFileOutputData data; }### Answer:
@Test public void testCloseFileDataOutIsNullCase() { textFileOutput = new TextFileOutput( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); textFileOutput.data = Mockito.mock( TextFileOutputData.class ); Assert.assertNull( textFileOutput.data.out ); textFileOutput.closeFile(); }
@Test public void testCloseFileDataOutIsNotNullCase() throws IOException { textFileOutput = new TextFileOutput( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); textFileOutput.data = Mockito.mock( TextFileOutputData.class ); textFileOutput.data.out = Mockito.mock( CompressionOutputStream.class ); textFileOutput.closeFile(); Mockito.verify( textFileOutput.data.out, Mockito.times( 1 ) ).close(); }