package com.jstanier;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.googlecode.jcsv.CSVStrategy;
import com.googlecode.jcsv.reader.CSVReader;
import com.googlecode.jcsv.reader.internal.CSVReaderBuilder;

@Component
public class InputParser {

    @Autowired
    private InputReader inputReader;

    public List<TweetToSchedule> parseInput(String pathToCsvFile) {
        return parseCsvFile(pathToCsvFile);
    }

    private List<TweetToSchedule> parseCsvFile(String pathToCsvFile) {
        List<TweetToSchedule> csvData = null;
        try {
            Reader reader = inputReader.getInputReader(pathToCsvFile);
            CSVReader<TweetToSchedule> csvParser = new CSVReaderBuilder(reader)
                    .strategy(CSVStrategy.UK_DEFAULT)
                    .entryParser(new TweetToScheduleEntryParser()).build();
            csvData = csvParser.readAll();
        } catch (FileNotFoundException e) {
            exitWithError("File not found at " + pathToCsvFile);
        } catch (IOException e) {
            exitWithError("IO exception when reading " + pathToCsvFile);
        }
        return csvData;
    }

    private void exitWithError(String error) {
        System.err.println(error);
        System.exit(1);
    }
}

@@ -857,164 +857,30 @@
 r = 
-new CSVReaderBuilder(reader)%0A                    .strategy(CSVStrategy.UK_DEFAULT)%0A                    .entryParser(new TweetToScheduleEntryParser()).build(
+createCSVReader(reader
 );%0A 
@@ -1147,16 +1147,16 @@
       %7D%0A
-
         
@@ -1170,32 +1170,306 @@
 csvData;%0A    %7D%0A%0A
+    private CSVReader%3CTweetToSchedule%3E createCSVReader(Reader reader) %7B%0A        return (CSVReader%3CTweetToSchedule%3E) new CSVReaderBuilder(reader)%0A                .strategy(CSVStrategy.UK_DEFAULT)%0A                .entryParser(new TweetToScheduleEntryParser()).build();%0A    %7D%0A%0A
     private void

Refactor CSVReader creation