package fr.notfound.rest;

import static java.lang.String.format;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;



import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;

public class JavaNetUrlRestGetClient implements RestGetClient {

    @Override public String get(URL url) {
        try {
            HttpURLConnection connection = (HttpURLConnection)url.openConnection();
            connection.setRequestMethod("GET");
            connection.connect();
            if (connection.getResponseCode() != 200)
                throw new RuntimeException(format("HTTP response code of %s was %s", url, connection.getResponseCode()));
            try (Reader reader = new BufferedReader(
                    new InputStreamReader(connection.getInputStream(), Charsets.UTF_8))) {
                return CharStreams.toString(reader);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}

@@ -58,16 +58,66 @@
 .format;
+%0Aimport static java.net.HttpURLConnection.HTTP_OK;
 %0A%0Aimport
@@ -185,18 +185,16 @@
 t.URL;%0A%0A
-%0A%0A
 import c
@@ -607,11 +607,15 @@
  != 
-200
+HTTP_OK
 )%0A  

use constants instead of magic numbers for HTTP statuses