How to mock the HttpURLConnection to the getContent() method in the sample code , Also how to get the reponse from the mock url
public class WebClient {
public String getContent(URL url) {
StringBuffer content = new StringBuffer();
try {
HttpURLConnection connection = createHttpURLConnection(url);
connection.setDoInput(true);
InputStream is = connection.getInputStream();
int count;
while (-1 != (count = is.read())) {
content.append(new String(Character.toChars(count)));
}
} catch (IOException e) {
return null;
}
return content.toString();
}
protected HttpURLConnection createHttpURLConnection(URL url) throws IOException{
return (HttpURLConnection)url.openConnection();
}
}
Thanks