ChildDetailController { public String get() { Child child = allBeneficiaries.findChild(caseId); Mother mother = allBeneficiaries.findMother(child.motherCaseId()); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(child.dateOfBirth()); String photoPath = isBlank(child.photoPath()) ? (AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); ChildDetail detail = new ChildDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()), new LocationDetails(couple.village(), couple.subCenter()), new BirthDetails(deliveryDate.toString(), calculateAge(deliveryDate), child.gender()), photoPath) .addTimelineEvents(getEvents()) .addExtraDetails(child.details()); return new Gson().toJson(detail); } ChildDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AllTimelineEvents allTimelineEvents); String get(); void takePhoto();  }
@Test public void shouldGetChildDetailsAsJSON() throws Exception { TimelineEvent birthEvent = TimelineEvent.forChildBirthInChildProfile(caseId, "2011-10-21", null, null); TimelineEvent ancEvent = TimelineEvent.forMotherPNCVisit(caseId, "2", "2011-12-22", "bps 1", "bpd 1", "temp 1", "hb 1"); TimelineEvent eventVeryCloseToCurrentDate = TimelineEvent.forMotherPNCVisit(caseId, "2", "2012-07-29", "bps 2", "bpd 2", "temp 2", "hb 2"); HashMap<String, String> details = new HashMap<String, String>(); details.put("ashaName", "Shiwani"); details.put("dateOfDelivery", "2012-07-28"); details.put("isHighRisk", "yes"); details.put("highRiskReason", "Anaemia"); when(allBeneficiaries.findChild(caseId)).thenReturn(new Child(caseId, "Mother-Case-Id", "TC 1", "2012-07-28", "male", details).withPhotoPath("photo path")); when(allBeneficiaries.findMother("Mother-Case-Id")).thenReturn(new Mother(caseId, "EC CASE 1", "TC 1", "2011-10-22").withDetails(details)); when(allEligibleCouples.findByCaseID("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "Woman 1", "Husband 1", "EC Number 1", "Village 1", "Subcenter 1", new HashMap<String, String>())); when(allTimelineEvents.forCase(caseId)).thenReturn(asList(birthEvent, ancEvent, eventVeryCloseToCurrentDate)); ChildDetail expectedDetail = new ChildDetail(caseId, "TC 1", new CoupleDetails("Woman 1", "Husband 1", "EC Number 1", false), new LocationDetails("Village 1", "Subcenter 1"), new BirthDetails("2012-07-28", "4 days", "male"), "photo path") .addTimelineEvents(asList(eventFor(eventVeryCloseToCurrentDate, "29-07-2012"), eventFor(ancEvent, "22-12-2011"), eventFor(birthEvent, "21-10-2011"))) .addExtraDetails(details); String actualJson = controller.get(); ChildDetail actualDetail = new Gson().fromJson(actualJson, ChildDetail.class); assertEquals(expectedDetail, actualDetail); }