### Question:
GroupBy extends BaseStep implements StepInterface { void addToBuffer( Object[] row ) throws KettleFileException { data.bufferList.add( row ); if ( data.bufferList.size() > 5000 && data.rowsOnFile == 0 ) { String pathToTmp = environmentSubstitute( getMeta().getDirectory() ); try { File ioFile = new File( pathToTmp ); if ( !ioFile.exists() ) { pathToTmp = retrieveVfsPath( pathToTmp ); } data.tempFile = File.createTempFile( getMeta().getPrefix(), ".tmp", new File( pathToTmp ) ); data.fosToTempFile = new FileOutputStream( data.tempFile ); data.dosToTempFile = new DataOutputStream( data.fosToTempFile ); data.firstRead = true; } catch ( IOException e ) { throw new KettleFileException( BaseMessages.getString( PKG, "GroupBy.Exception.UnableToCreateTemporaryFile" ), e ); } Object[] oldest = data.bufferList.get( 0 ); data.inputRowMeta.writeData( data.dosToTempFile, oldest ); data.bufferList.remove( 0 ); data.rowsOnFile++; } } GroupBy( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
      Trans trans ); @Override boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); @Override boolean init( StepMetaInterface smi, StepDataInterface sdi ); @Override void dispose( StepMetaInterface smi, StepDataInterface sdi ); @Override void batchComplete(); GroupByMeta getMeta();  }### Answer:
@Test public void testAddToBuffer() throws KettleException, FileSystemException { GroupByData groupByData = new GroupByData(); ArrayList listMock = mock( ArrayList.class ); when( listMock.size() ).thenReturn( 5001 ); groupByData.bufferList = listMock; groupByData.rowsOnFile = 0; RowMetaInterface inputRowMetaMock = mock( RowMetaInterface.class ); groupByData.inputRowMeta = inputRowMetaMock; GroupBy groupBySpy = Mockito.spy( new GroupBy( mockHelper.stepMeta, groupByData, 0, mockHelper.transMeta, mockHelper.trans ) ); GroupByMeta groupByMetaMock = mock( GroupByMeta.class ); when( groupByMetaMock.getPrefix() ).thenReturn( "group-by-test-temp-file-" ); when( groupBySpy.getMeta() ).thenReturn( groupByMetaMock ); String userDir = System.getProperty( "user.dir" ); String vfsFilePath = "file: when( groupBySpy.environmentSubstitute( anyString() ) ).thenReturn( vfsFilePath ); Object[] row = { "abc" }; groupBySpy.addToBuffer( row ); assertTrue( groupByData.tempFile.exists() ); groupBySpy.dispose( groupByMetaMock, groupByData ); assertFalse( groupByData.tempFile.exists() ); verify( groupBySpy, times( 1 ) ).retrieveVfsPath( anyString() ); }