ChildReportingService { public void reportChildBalanceLessThanFiveYearOld() { LocalDate today = DateUtil.today(); List<Child> childrenLessThanFiveYearOld = allChildren.findAllChildrenLessThanFiveYearOldAsOfDate(today); logger.info(MessageFormat.format("Found {0} children for reporting Infant Balance (less than five year old) ", childrenLessThanFiveYearOld.size())); LocalDate startOfCurrentReportMonth = reportMonth.startOfCurrentReportMonth(today); updateInfantBalanceIndicator(Indicator.INFANT_BALANCE_LESS_THAN_FIVE_YEAR, childrenLessThanFiveYearOld, startOfCurrentReportMonth.toString()); } @Autowired  ChildReportingService(ReportingService reportingService, AllChildren allChildren, AllMothers allMothers,
                                 AllEligibleCouples allEligibleCouples,
                                 AllInfantBalanceOnHandReportTokens allInfantBalanceOnHandReportTokens, ReportMonth reportMonth, MCTSReporter mctsReporter); void registerChild(SafeMap reportData); void immunizationProvided(SafeMap reportData, List<String> previousImmunizations); void vitaminAProvided(SafeMap reportData); void pncVisitHappened(SafeMap reportData); void sickVisitHappened(SafeMap reportData); void closeChild(SafeMap reportData); void reportToBoth(Child child, Indicator indicator, String serviceProvidedDate, String submissionDate, Location location); void reportToBoth(Child child, Indicator indicator, String serviceProvidedDate, Location location); void reportInfantAndChildBalance(); void reportInfantBalanceOnHand(); void reportInfantBalanceTurningOneYearOld(); void reportInfantBalanceTotalNumberOfOAChildren(); void reportInfantBalanceLessThanOneYearOld(); void reportChildBalanceLessThanFiveYearOld(); static final String CHILD_ID_FIELD; }
@Test public void shouldReportTotalNumberOfChildrenLessThanFiveYearOldWhenInfantBalanceIsReported() throws Exception { LocalDate today = parse("2013-02-01"); DateUtil.fakeIt(today); when(allChildren.findAllChildrenLessThanFiveYearOldAsOfDate(today)) .thenReturn(asList( new Child("child id 1", "mother id 1", "", "5", "male").withThayiCard("thayi card 1").withAnm("ANM X"))); when(allMothers.findByCaseId("mother id 1")).thenReturn(new Mother("mother id 1", "ec id 1", "thayi card 1")); when(allEligibleCouples.findByCaseId("ec id 1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.startOfCurrentReportMonth(today)).thenReturn(parse("2013-01-26")); when(reportMonth.startOfCurrentReportMonth(parse("2013-01-26"))).thenReturn(parse("2013-01-26")); when(reportMonth.endOfCurrentReportMonth(parse("2013-01-26"))).thenReturn(parse("2013-02-25")); when(reportMonth.isDateWithinCurrentReportMonth(parse("2013-01-26"))).thenReturn(true); service.reportChildBalanceLessThanFiveYearOld(); verifyBothUpdateReportCalls(Indicator.INFANT_BALANCE_LESS_THAN_FIVE_YEAR, "2013-01-26", "child id 1", "thayi card 1", "2013-01-26", "2013-02-25"); }