package com.jakubsprega.untestable.code.f;

import com.google.common.io.CharStreams;
import com.google.gson.Gson;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;

/**
 * Google client
 * 
 * @author jakubsprega
 */
public class GoogleClient {

    public GoogleResult search(String searchPhrase) throws Exception {
        String googleApiUrl = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=";
        String charset = "UTF-8";
        String googleRequestUrl = String.format(
            "%s%s", googleApiUrl, URLEncoder.encode(searchPhrase, charset)
        );
        
        URL url = new URL(googleRequestUrl);
        String rawJsonGoogleResponse = CharStreams.toString(
            new InputStreamReader(url.openStream(), charset)
        );
        
        GoogleResult results = new Gson().fromJson(rawJsonGoogleResponse, GoogleResult.class);
        
        return results;
    }
}

@@ -189,16 +189,91 @@
 Encoder;
+%0Aimport java.nio.charset.Charset;%0Aimport java.nio.charset.StandardCharsets;
 %0A%0A/**%0A *
@@ -289,17 +289,16 @@
 lient%0A *
- 
 %0A * @aut
@@ -349,88 +349,476 @@
 t %7B%0A
+    
 %0A    p
-ublic GoogleResult search(String searchPhra
+rivate static final String DEFAULT_GOOGLE_API_URL = %22http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=%22;%0A%0A    private final String googleApiUrl;%0A    private final Charset charset;%0A%0A    public GoogleClient(String googleApiUrl, Charset char
 se
+t
 ) 
-throws Exception %7B%0A        
+%7B%0A        this.googleApiUrl = googleApiUrl;%0A        this.charset = charset;%0A    %7D%0A%0A    public GoogleClient() %7B%0A        this(DEFAULT_GOOGLE_API_URL, StandardCharsets.UTF_8);%0A    %7D%0A%0A    public GoogleClient(
 Stri
@@ -836,108 +836,242 @@
 iUrl
- = %22http://ajax.
+) %7B%0A        this(
 google
-apis.com/ajax/services/search/web?v=1.0&q=%22
+ApiUrl, StandardCharsets.UTF_8);%0A    %7D%0A    %0A    public GoogleClient(Charset charset) %7B%0A        this(DEFAULT_GOOGLE_API_URL, charset)
 ;%0A    
+%7D%0A%0A
     
-String charset = %22UTF-8%22;
+public GoogleResult search(String searchPhrase) throws Exception %7B
 %0A   
@@ -1181,32 +1181,39 @@
 hPhrase, charset
+.name()
 )%0A        );%0A   
@@ -1205,32 +1205,24 @@
 %0A        );%0A
-        
 %0A        URL
@@ -1388,24 +1388,16 @@
      );%0A
-        
 %0A       
@@ -1484,24 +1484,16 @@
 class);%0A
-        
 %0A       

Improve google client