ANMReportsRepository { @Transactional("anm_report") public List<ANMReport> fetchAllANMsReport() { List<ANM> allANMs = cachedANMs.fetchAll(); ArrayList<ANMReport> anmReports = new ArrayList<>(); for (ANM anm : allANMs) { anmReports.add(new ANMReport(anm.anmIdentifier(), fetchANMSummary(anm.anmIdentifier()))); } return anmReports; } protected  ANMReportsRepository(); @Autowired  ANMReportsRepository(ANMCacheableRepository anmRepository,
                                @Qualifier("anmReportsIndicatorRepository") IndicatorCacheableRepository indicatorRepository,
                                AllANMReportDataRepository anmReportDataRepository,
                                AllAnnualTargetsRepository annualTargetsRepository, Monitor monitor, ReportMonth reportMonth); @Transactional("anm_report") void save(String anmIdentifier, String externalId, String indicator, String date, String quantity); @Transactional("anm_report") List<ANMIndicatorSummary> fetchANMSummary(String anmIdentifier); @Transactional("anm_report") List<ANMReport> fetchAllANMsReport(); @Transactional("anm_report") void update(ReportDataUpdateRequest request); @Transactional("anm_report") List getReportsFor(String anmId, String startDate, String endDate); @Transactional("anm_report") void delete(ReportDataDeleteRequest request);  }
@Test public void shouldReturnAllANMReports() throws Exception { DateUtil.fakeIt(parse("2012-06-30")); ANM anmX = new ANM("ANM X"); ANM anmY = new ANM("ANM Y"); Date date1 = parse("2012-03-29").toDate(); Date date2 = parse("2012-04-30").toDate(); Date date3 = parse("2012-05-27").toDate(); Indicator indicator1 = new Indicator("IUD"); Indicator indicator2 = new Indicator("ANC"); when(anmReportDataRepository.fetchByANMIdAndDate("ANM X", parse("2012-03-26").toDate())).thenReturn(asList( new ANMReportData(anmX, "CASE 1", indicator1, date1), new ANMReportData(anmX, "CASE 2", indicator1, date1), new ANMReportData(anmX, "CASE 3", indicator1, date2), new ANMReportData(anmX, "CASE 4", indicator1, date2))); when(anmReportDataRepository.fetchByANMIdAndDate("ANM Y", parse("2012-03-26").toDate())).thenReturn(asList( new ANMReportData(anmY, "CASE 5", indicator2, date3), new ANMReportData(anmY, "CASE 6", indicator2, date3))); when(annualTargetsRepository.fetchFor("ANM X", indicator1, parse("2012-06-30").toDate())).thenReturn(new AnnualTarget(1, 1, "40", parse("2012-03-26").toDate(), parse("2013-03-25").toDate())); when(annualTargetsRepository.fetchFor("ANM Y", indicator2, parse("2012-06-30").toDate())).thenReturn(new AnnualTarget(1, 1, "30", parse("2012-03-26").toDate(), parse("2013-03-25").toDate())); when(anmRepository.fetchAll()).thenReturn(asList(anmX, anmY)); List<ANMReport> anmReports = repository.fetchAllANMsReport(); ANMReport anmXReport = new ANMReport("ANM X", asList(createSummaryForIUD())); ANMReport anmYReport = new ANMReport("ANM Y", asList(createSummaryForANC())); assertTrue(anmReports.containsAll(asList(anmXReport, anmYReport))); assertEquals(2, anmReports.size()); }