### Question:
AssetGroupUtil { public static Map<String, Object> fetchCertSummary(String compapiuri, String ag ,String token) throws Exception { Map<String, Object> certSummary = new HashMap<>(); try { String certSummaryResponse = HttpUtil.get(compapiuri + "/certificates?ag=" + ag,token); JsonObject certSummaryJson = new JsonParser().parse(certSummaryResponse).getAsJsonObject(); JsonObject certJsonObj = certSummaryJson.get("data").getAsJsonObject().get(OUTPUT).getAsJsonObject(); long total = certJsonObj.get("certificates").getAsLong(); long noncompliant = certJsonObj.get("certificates_expiring").getAsLong(); long compliant = total - noncompliant; certSummary.put(TOTAL, total); certSummary.put(NON_COMPLIANT, noncompliant); certSummary.put(COMPLIANT, compliant); } catch (Exception e) { LOGGER.error("Error retrieving cert sumamary " , e); throw e; } return certSummary; } private  AssetGroupUtil(); @SuppressWarnings("unchecked") static Map<String, List<String>> fetchAssetGroups(String asstApiUri,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchTypeCounts(String asstApiUri, String ag,String token); static Map<String, Object> fetchPatchingCompliance(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchComplianceInfo(String apiUrl, String ag, List<String> domains ,String token); static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag,
            List<String> domains ,String token); static Map<String, Object> fetchVulnSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchTaggingSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchCertSummary(String compapiuri, String ag ,String token); static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token);  }### Answer:
@Test public void testFetchCertSummary() throws Exception { String certSummaryJson = "{\"data\":{\"output\":{\"certificates\":1320,\"certificates_expiring\":0}},\"message\":\"success\"}"; when(HttpUtil.get(anyString(),anyString())).thenReturn(certSummaryJson); Map<String, Object> certSummary = AssetGroupUtil.fetchCertSummary("", "",""); assertThat(certSummary.get("total"), is(1320l)); }
@Test(expected=Exception.class) public void testFetchCertSummaryException() throws Exception { String certSummaryJson = "{\"data1\":{\"output\":{\"certificates\":1320,\"certificates_expiring\":0}},\"message\":\"success\"}"; when(HttpUtil.get(anyString(),anyString())).thenReturn(certSummaryJson); AssetGroupUtil.fetchCertSummary("", "",""); }