ANMDetailsService { public ANMDetails anmDetails(List<ANMDTO> anms) { List<String> anmIdentifiers = collect(anms, on(ANMDTO.class).identifier()); Map<String, Integer> ecCount = allEligibleCouples.allOpenECs(anmIdentifiers); Map<String, Integer> fpCount = allEligibleCouples.fpCountForANM(anmIdentifiers); Map<String, Integer> ancCount = allMothers.allOpenMotherCount(anmIdentifiers); Map<String, Integer> pncCount = allMothers.allOpenPNCCount(anmIdentifiers); Map<String, Integer> childCount = allChildren.openChildCount(anmIdentifiers); List<ANMDetail> anmDetails = new ArrayList<>(); for (ANMDTO anm : anms) { int ecCountForANM = ecCount.get(anm.identifier()) == null ? 0 : ecCount.get(anm.identifier()); int fpCountForANM = fpCount.get(anm.identifier()) == null ? 0 : fpCount.get(anm.identifier()); int ancCountForANM = ancCount.get(anm.identifier()) == null ? 0 : ancCount.get(anm.identifier()); int pncCountForANM = pncCount.get(anm.identifier()) == null ? 0 : pncCount.get(anm.identifier()); int childCountForANM = childCount.get(anm.identifier()) == null ? 0 : childCount.get(anm.identifier()); anmDetails.add(new ANMDetail(anm.identifier(), anm.name(), anm.location(), ecCountForANM, fpCountForANM, ancCountForANM, pncCountForANM, childCountForANM)); } return new ANMDetails(anmDetails); } @Autowired  ANMDetailsService(AllEligibleCouples allEligibleCouples, AllMothers allMothers, AllChildren allChildren); ANMDetails anmDetails(List<ANMDTO> anms);  }
@Test public void shouldGetBeneficiariesCountForANM() { List<String> anmIdentifiers = asList("demo1"); when(allEligibleCouples.allOpenECs(anmIdentifiers)).thenReturn(mapOf("demo1", 1)); when(allEligibleCouples.fpCountForANM(anmIdentifiers)).thenReturn(mapOf("demo1", 2)); when(allMothers.allOpenMotherCount(anmIdentifiers)).thenReturn(mapOf("demo1", 3)); when(allMothers.allOpenPNCCount(anmIdentifiers)).thenReturn(mapOf("demo1", 4)); when(allChildren.openChildCount(anmIdentifiers)).thenReturn(mapOf("demo1", 5)); ANMDetails anmDetails = service.anmDetails(asList(new ANMDTO("demo1", "demo1", null))); assertEquals(new ANMDetails(asList(new ANMDetail("demo1", "demo1", null, 1, 2, 3, 4, 5))), anmDetails); }