### Question:
TaggingServiceImpl implements TaggingService, Constants { @Override public ResponseWithCount getUnTaggedAssetsByApplication(Request request) throws ServiceException { String assetGroup = request.getAg(); String searchText = request.getSearchtext(); int from = request.getFrom(); int size = request.getSize(); List<Map<String, Object>> masterDetailList = new ArrayList<>(); LinkedHashMap<String, Object> app; JsonArray buckets; try { buckets = repository.getUntaggedIssuesByapplicationFromES(assetGroup, mandatoryTags, searchText, from, size); } catch (DataException e) { throw new ServiceException(e); } JsonObject tagsObj = null; JsonObject bucketsTags = null; JsonObject tagsJson = null; JsonElement tagsDocId = null; String tags = null; String tagName = null; int total = 0; for (int i = 0; i < buckets.size(); i++) { total = buckets.size(); app = new LinkedHashMap<>(); app.put("application", buckets.get(i).getAsJsonObject().get("key").getAsString()); tagsObj = (JsonObject) buckets.get(i).getAsJsonObject().get("tags"); bucketsTags = (JsonObject) tagsObj.get("buckets"); Iterator<String> it = bucketsTags.keySet().iterator(); while (it.hasNext()) { tags = it.next(); tagsJson = (JsonObject) bucketsTags.get(tags); tagsDocId = tagsJson.get("doc_count"); StringBuilder sb = new StringBuilder(tags); sb.setCharAt(0, Character.toLowerCase(sb.charAt(0))); tagName = sb.toString(); app.put(tagName + "Untagged", tagsDocId.getAsLong()); } masterDetailList.add(app); } if (masterDetailList.isEmpty()) { throw new ServiceException(NO_DATA_FOUND); } if (from >= masterDetailList.size()) { throw new ServiceException("From exceeds the size of list"); } int endIndex = 0; if ((from + size) > masterDetailList.size()) { endIndex = masterDetailList.size(); } else { endIndex = from + size; } List<Map<String, Object>> subDetailList; if (from == 0 && size == 0) { subDetailList = masterDetailList; } else { subDetailList = masterDetailList.subList(from, endIndex); } if (buckets.size() > 0) { return new ResponseWithCount(subDetailList, total); } else { throw new ServiceException("No records found!!"); } }  @Override ResponseWithCount getUnTaggedAssetsByApplication(Request request); Map<String, Object> getTaggingSummary(String assetGroup); List<Map<String, Object>> getUntaggingByTargetTypes(UntaggedTargetTypeRequest request); @Override List<Map<String, Long>> taggingByApplication(String assetGroup, String targetType);  }### Answer:
@Test public void getUnTaggedAssetsByApplicationTest() throws Exception { request.setAg("aws-all1"); Gson gson = new Gson(); JsonArray array = new JsonArray(); JsonObject tagsJson = new JsonObject(); JsonObject oneTagsJson = new JsonObject(); JsonObject twoTagsJson = new JsonObject(); JsonObject threeTagsJson = new JsonObject(); threeTagsJson.add("doc_count", gson.fromJson("165", JsonElement.class)); twoTagsJson.add("Environment", threeTagsJson); oneTagsJson.add("buckets", twoTagsJson); tagsJson.add("key", gson.fromJson("My-TMO", JsonElement.class)); tagsJson.add("doc_count", gson.fromJson("3066", JsonElement.class)); tagsJson.add("tags", oneTagsJson); array.add(tagsJson); when( repository.getUntaggedIssuesByapplicationFromES(anyString(), anyString(), anyString(), anyInt(), anyInt())) .thenReturn(array); assertThat(taggingServiceImpl.getUnTaggedAssetsByApplication(request), is(notNullValue())); when(repository.getUntaggedIssuesByapplicationFromES(anyString(), anyString(), anyString(), anyInt(), anyInt())) .thenThrow(new DataException()); assertThatThrownBy(() -> taggingServiceImpl.getUnTaggedAssetsByApplication(request)) .isInstanceOf(ServiceException.class); }