Question: Create test cases using JUnit package sdp.io; import java.io.Reader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.List; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVRecord; // Allow

Create test cases using JUnit

package sdp.io;

import java.io.Reader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.List;

import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVRecord;

// Allow for relative filepaths with .getResource // Allow for entire directory to be run with .isDirectory() of File public class CSVFileReader { private File csvFile; private List csvRecs; private Reader reader; public List getRecords() { return this.csvRecs; } public List readFile(String csvFilePath) { this.csvFile = new File(csvFilePath); if (csvFile.exists() && csvFile.isFile()) { try { this.reader = new FileReader(this.csvFile); readRecords(); } catch (FileNotFoundException e) { e.printStackTrace(); } } return this.csvRecs; } private void readRecords() { try { this.csvRecs = CSVFormat.EXCEL.withFirstRecordAsHeader().parse(this.reader).getRecords(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!