### Question:
TextFileInputDialog extends BaseStepDialog implements StepDialogInterface { public void setMinimalWidth() { int nrNonEmptyFields = wFields.nrNonEmpty(); for ( int i = 0; i < nrNonEmptyFields; i++ ) { TableItem item = wFields.getNonEmpty( i ); item.setText( 5, "" ); item.setText( 6, "" ); item.setText( 12, ValueMetaString.getTrimTypeDesc( ValueMetaInterface.TRIM_TYPE_BOTH ) ); int type = ValueMetaFactory.getIdForValueMeta( item.getText( 2 ) ); switch ( type ) { case ValueMetaInterface.TYPE_STRING: item.setText( 3, "" ); break; case ValueMetaInterface.TYPE_INTEGER: item.setText( 3, "0" ); break; case ValueMetaInterface.TYPE_NUMBER: item.setText( 3, "0.#####" ); break; case ValueMetaInterface.TYPE_DATE: break; default: break; } } for ( int i = 0; i < input.inputFields.length; i++ ) { input.inputFields[i].setTrimType( ValueMetaInterface.TRIM_TYPE_BOTH ); } wFields.optWidth( true ); } TextFileInputDialog( Shell parent, Object in, TransMeta transMeta, String sname ); String open(); void setFlags(); void getData( TextFileInputMeta meta ); static int guessPrecision( double d ); static int guessIntLength( double d ); void setMinimalWidth(); void setMinimalWidth( TableView wFields ); static final int[] dateLengths; }### Answer:
@Test public void testMinimalWidth_PDI_14253() throws Exception { final String virtualFile = "ram: KettleVFS.getFileObject( virtualFile ).createFile(); final String content = "r1c1, r1c2\nr2c1 , r2c2 "; ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write( content.getBytes() ); OutputStream os = KettleVFS.getFileObject( virtualFile ).getContent().getOutputStream(); IOUtils.copy( new ByteArrayInputStream( bos.toByteArray() ), os ); os.close(); TextFileInputMeta meta = new TextFileInputMeta(); meta.content.lineWrapped = false; meta.inputFields = new BaseFileField[]{ new BaseFileField( "col1", -1, -1 ), new BaseFileField( "col2", -1, -1 ) }; meta.content.fileCompression = "None"; meta.content.fileType = "CSV"; meta.content.header = false; meta.content.nrHeaderLines = -1; meta.content.footer = false; meta.content.nrFooterLines = -1; TextFileInputData data = new TextFileInputData(); data.files = new FileInputList(); data.files.addFile( KettleVFS.getFileObject( virtualFile ) ); data.outputRowMeta = new RowMeta(); data.outputRowMeta.addValueMeta( new ValueMetaString( "col1" ) ); data.outputRowMeta.addValueMeta( new ValueMetaString( "col2" ) ); data.dataErrorLineHandler = mock( FileErrorHandler.class ); data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX; data.separator = ","; data.filterProcessor = new TextFileFilterProcessor( new TextFileFilter[0], new Variables() { } ); data.filePlayList = new FilePlayListAll(); TextFileInputDialog dialog = new TextFileInputDialog( mock( Shell.class ), meta, mock( TransMeta.class ), "TFIMinimalWidthTest" ); TableView tv = mock( TableView.class ); when( tv.nrNonEmpty() ).thenReturn( 0 ); dialog.setMinimalWidth( tv ); RowSet output = new BlockingRowSet( 5 ); TextFileInput input = StepMockUtil.getStep( TextFileInput.class, TextFileInputMeta.class, "test" ); input.setOutputRowSets( Collections.singletonList( output ) ); while ( input.processRow( meta, data ) ) { } Object[] row1 = output.getRowImmediate(); assertRow( row1, "r1c1", "r1c2" ); Object[] row2 = output.getRowImmediate(); assertRow( row2, "r2c1", "r2c2" ); KettleVFS.getFileObject( virtualFile ).delete(); }