I am writing test cases to meet the Sonar coverage for my code and I am not sure how to write test cases for the below piece of code →
I am basically using Query class to fetch details from Cs using java management and am unable to write test cases for the below.
Query query = stack.contentType(CS_TYPE_PRODUCT).query();query = query.where(key, value);
// I am more concerned about the below code to write test coverage
query.find(new QueryResultsCallBack() { @Override public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) { if (error == null) { PcmMetadataAppDto pcmMeta = new PcmMetadataAppDto(); pcmMeta.setPcmEntryLocale(queryresult.getResultObjects().get(0).get("locale").toString()); pcmMeta.setPcmEntryUid(queryresult.getResultObjects().get(0).get("uid").toString()); pcmMeta.setPcmEntryVersion(queryresult.getResultObjects().get(0) .get("_version").toString()); pcmMetadataResponseAppDto.setPcmMetadata(pcmMeta); try { pcmMeta.setPcmEntryUrl(getPcmUri(stackUrl, stackApiKey, CS_TYPE_PRODUCT, pcmMeta.getPcmEntryLocale(), pcmMeta.getPcmEntryUid()).toString()); } catch (URISyntaxException e) { throw new RuntimeException(e); } log.info("query result is {} ", queryresult.getResultObjects().get(0).getJSONObject("")); } }});