I have a method that scans a file and assigns values to an object:
private List<Customer> customerList = new ArrayList<Customer>();
public void scanLocalFile() throws FileNotFoundException {
File file = new File("input.txt");
Scanner scan = new Scanner(file);
while (scan.hasNextLine()) {
String[] fields = line.split(";");
String name = fields[0];
String score = fields[1];
Customer customer = new Customer(name, score);
customerList.add(customer);
}
scan.close();
}
How do I write a junit test for a method like this? Is it possible to use the same file ("input.txt") for a unit test as well?
The file's structure:
John Smith;45;
Adam West;78;