### Question:
AssetGroupUtil { public static Map<String, Object> fetchPatchingCompliance(String api, String ag ,String token) throws Exception { Map<String, Object> patchingInfo = new HashMap<>(); try { String responseJson = HttpUtil.get(api + "/patching?ag=" + ag,token); Map<String, Object> vulnMap = Util.parseJson(responseJson); @SuppressWarnings("unchecked") Map<String, Map<String, Object>> data = (Map<String, Map<String, Object>>) vulnMap.get("data"); Map<String, Object> output = data.get(OUTPUT); if (output != null) patchingInfo.putAll(data.get(OUTPUT)); } catch (Exception e) { LOGGER.error("Error in fetchVulnCount",e); throw e; } return patchingInfo; } 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 testFetchPatchingCompliance() throws Exception { String patchingResponse = "{\"data\":{\"output\":{\"unpatched_instances\":4748,\"patched_instances\":1330,\"total_instances\":6078,\"patching_percentage\":21}},\"message\":\"success\"}"; when(HttpUtil.get(anyString(),anyString())).thenReturn(patchingResponse); Map<String, Object> patchingInfo = AssetGroupUtil.fetchPatchingCompliance("", "",""); assertThat(patchingInfo.get("patching_percentage").toString(), is("21")); }
@Test(expected=Exception.class) public void testFetchPatchingComplianceException() throws Exception { String patchingResponse = "{\"data1\":{\"output\":{\"unpatched_instances\":4748,\"patched_instances\":1330,\"total_instances\":6078,\"patching_percentage\":21}},\"message\":\"success\"}"; when(HttpUtil.get(anyString(),anyString())).thenReturn(patchingResponse); AssetGroupUtil.fetchPatchingCompliance("", "",""); }