### Question:
CsvUtils extends PentahoBase { public ModelInfo generateFields( String project, String filename, int rowLimit, String delimiter, String enclosure, int headerRows, boolean doData, boolean doColumns, String encoding ) throws Exception { String path; if ( filename.endsWith( ".tmp" ) ) { path = PentahoSystem.getApplicationContext().getSolutionPath( TMP_FILE_PATH ); } else { String relativePath = PentahoSystem.getSystemSetting( "file-upload-defaults/relative-path", String.valueOf( DEFAULT_RELATIVE_UPLOAD_FILE_PATH ) ); path = PentahoSystem.getApplicationContext().getSolutionPath( relativePath ); } String fileLocation = path + filename; return generateFields( project, fileLocation, filename, rowLimit, delimiter, enclosure, headerRows, doData, doColumns, encoding ); }  ModelInfo getFileContents( String project, String name, String delimiter, String enclosure, int rows,
                                    boolean isFirstRowHeader, String encoding ); ModelInfo generateFields( String project, String filename, int rowLimit, String delimiter, String enclosure,
                                   int headerRows, boolean doData, boolean doColumns, String encoding ); @Override Log getLogger(); String getEncoding( String fileName ); ModelInfo getModelInfo( String project, String filename ); static final List<String> NUMBER_FORMATS; static final String DEFAULT_RELATIVE_UPLOAD_FILE_PATH; static final String TMP_FILE_PATH; }### Answer:
@Test public void generateFields_OneHeaderLine_OneDataLine() throws Exception { prepareFile( new String[] { "col1", "col2" }, new String[] { "1", "2" } ); ModelInfo info = generateFields( 2, null, 1 ); ColumnInfo[] columns = info.getColumns(); assertEquals( 2, columns.length ); assertEquals( "col1", columns[ 0 ].getId() ); assertEquals( "col2", columns[ 1 ].getId() ); DataRow[] data = info.getData(); assertEquals( 1, data.length ); assertEquals( 2, data[ 0 ].getCells().length ); assertEquals( "1", data[ 0 ].getCells()[ 0 ] ); assertEquals( "2", data[ 0 ].getCells()[ 1 ] ); }
@Test public void generateFields_EscapesColumnsNames() throws Exception { String[] headers = { "col.1", "col 2 */+" }; for ( String header : headers ) { assertFalse( Util.validateId( header ) ); } prepareFile( headers ); ColumnInfo[] columns = generateFields( 1, null, 1 ).getColumns(); for ( int i = 0; i < columns.length; i++ ) { ColumnInfo column = columns[ i ]; assertEquals( "Keeps original title", headers[ i ], column.getTitle() ); assertTrue( "Escapes id", Util.validateId( column.getId() ) ); } }