### Question:
CommonUtils { public static boolean isValidResource(String esUrl) { HttpClient httpclient = HttpClientBuilder.create().build(); HttpHead httpHead = new HttpHead(esUrl); HttpResponse response; try { response = httpclient.execute(httpHead); return HttpStatus.SC_OK == response.getStatusLine().getStatusCode(); } catch (ClientProtocolException clientProtocolException) { LOGGER.error("ClientProtocolException in getHttpHead:" + clientProtocolException); } catch (IOException ioException) { LOGGER.error("IOException in getHttpHead:" + ioException); } return false; }  static Boolean isEnvVariableExists(String envVariableName); static String getEnvVariableValue(String envVariableName); static String doHttpPost(final String url,  String requestBody); static String doHttpPut(final String url, final String requestBody); static boolean isValidResource(String esUrl); static Object buildQueryForExistingIssues(Map<String, Object> filter); static String getIndexNameFromRuleParam(Map<String, String> ruleParam); @SuppressWarnings("unchecked") static Map<String, String> flatNestedMap(String notation, Map<String, Object> nestedMap); static String getUniqueAnnotationId(Annotation annotation); static String getUniqueAnnotationId(String parentId, String ruleId); static String getUniqueIdForString(String inStr); static String hash(String s); static Map<String, String> createParamMap(String ruleParams); static String decrypt(String encryptedText); static Map<String, String> buildMapFromString(String input, String splitOn, String keyValueSeparator); static Long getElapseTimeSince(long startTime); static String getCurrentDateStringWithFormat(String timeZone, String format); static Date getDateFromString(final String dateInString, final String format); static Date dateFormat(final String dateInString, String formatFrom, String formatTo); static int compareDate(final Date firstDate, final Date lastDate); static boolean resourceCreatedBeforeCutoffData(final Date resourceCreationDate); static String doHttpPost(final String url, final String requestBody, final Map<String, String> headers); static String doHttpGet(final String url); static SSLContext createNoSSLContext(); static String getJsonString(final Object annotation); static String encryptB64(String plainText); static String decryptB64(String text); static String encrypt(String plainText, final String key); static String decrypt(String encryptedText, final String key); static String getPropValue(final String keyname); static String getTemplateContent(final String templateName); static String serializeToString(Object object); static Object deSerializeToObject(String jsonString); static Boolean doesAllHaveValue(String...strings );  }### Answer:
@Test public void isValidResourceTest() throws Exception{ PowerMockito.when(httpClient.execute((HttpHead) any())).thenReturn(httpResponse); assertTrue(CommonUtils.isValidResource("url")); }
@SuppressWarnings("unchecked") @Test public void isValidResourceTest2() throws ClientProtocolException, IOException { PowerMockito.when(httpClient.execute((HttpHead) any())).thenThrow(ClientProtocolException.class); assertFalse(CommonUtils.isValidResource("url")); }
@SuppressWarnings("unchecked") @Test public void isValidResourceTest3() throws ClientProtocolException, IOException { PowerMockito.when(httpClient.execute((HttpHead) any())).thenThrow(IOException.class); assertFalse(CommonUtils.isValidResource("url")); }
@Test public void isValidResourceTest4() throws ClientProtocolException, IOException { PowerMockito.when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_FORBIDDEN, "NOT FINE!")); PowerMockito.when(httpClient.execute((HttpHead) any())).thenReturn(httpResponse); assertFalse(CommonUtils.isValidResource("https: }