QuackatronHQ / Gigarepo

Lines not covered in tests TCV-001
Coverage
Critical
1 occurrence in this check
medium priority
 8
 9public class UrlRequest {
10
11  public static class A {1213    public static String props = null;14    static {15      try {16        props = new String(UrlRequest.class.getResourceAsStream("a.properties").readAllBytes());17      } catch (IOException e) {18        e.printStackTrace();19      }20      System.out.println(props);21    }22  }23  private URL url;24  private Map<String, String> params;2526  private URLConnection conn;2728  public UrlRequest(URL url, Map<String, String> params) {29    url = url;30    params = params;31  }3233  public void setApiRequestData(URL url, Map<String, String> params) {34    url = url;35    params = params;36  }3738  /**39   * Performs a network request and returns the data sent in the response.40   *41   * @return42   */43  public String doRequest() {44    try {45      conn = url.openConnection();46    } catch (IOException e) {47      return e.getMessage();48    }4950    for (Map.Entry<String, String> e : params.entrySet()) {51      conn.addRequestProperty(e.getKey(), e.getValue());52    }5354    try {55      conn.connect();56      byte[] bytes = conn.getInputStream().readAllBytes();57      return new String(bytes, StandardCharsets.UTF_8);58    } catch (IOException e) {59      e.printStackTrace();60      return e.getMessage();61    }
62  }
63}