samedi 17 juin 2017

Buffered reader test

I would like to test method which can take data from specific URL address and add it as a String to the ArrayList. The code for now:

public List<String> getListOfAirportsFromCsvAsAStrings(String urlAddress) {

    BufferedReader reader = null;

    try {
        URL url = new URL(urlAddress);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        connection.setRequestMethod("GET");

        reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

        String line = null;
        while ((line = reader.readLine()) != null) {
            airportsAsAStringFromCsvFile.add(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    }
    return airportsAsAStringFromCsvFile;
}

Is this method testable?

Aucun commentaire:

Enregistrer un commentaire