PNCDetailController { public String get() { Mother mother = allBeneficiaries.findMotherWithOpenStatus(caseId); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(mother.referenceDate()); Days postPartumDuration = Days.daysBetween(deliveryDate, DateUtil.today()); PNCDetail detail = new PNCDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()) .withCaste(couple.getDetail("caste")) .withEconomicStatus(couple.getDetail("economicStatus")) .withPhotoPath(couple.photoPath()), new LocationDetails(couple.village(), couple.subCenter()), new PregnancyOutcomeDetails(deliveryDate.toString(), postPartumDuration.getDays())) .addTimelineEvents(getEvents()) .addExtraDetails(mother.details()); return new Gson().toJson(detail); } PNCDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AllTimelineEvents allTimelineEvents); String get(); void takePhoto();  }
@Test public void shouldGetPNCDetailsAsJSON() throws Exception { TimelineEvent pregnancyEvent = TimelineEvent.forStartOfPregnancy(caseId, "2011-10-21", "2011-10-21"); TimelineEvent ancEvent = TimelineEvent.forANCCareProvided(caseId, "2", "2011-12-22", new HashMap<String, String>()); TimelineEvent eventVeryCloseToCurrentDate = TimelineEvent.forANCCareProvided(caseId, "2", "2012-07-29", new HashMap<String, String>()); HashMap<String, String> details = new HashMap<String, String>(); details.put("ashaName", "Shiwani"); details.put("isHighRisk", "yes"); details.put("highRiskReason", "Anaemia"); when(allBeneficiaries.findMotherWithOpenStatus(caseId)).thenReturn(new Mother(caseId, "EC CASE 1", "TC 1", "2012-07-28").withDetails(details)); HashMap<String, String> ecDetails = new HashMap<String, String>(); ecDetails.put("caste", "c_others"); ecDetails.put("economicStatus", "apl"); when(allEligibleCouples.findByCaseID("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "Woman 1", "Husband 1", "EC Number 1", "Village 1", "Subcenter 1", ecDetails).withPhotoPath("photo path")); when(allTimelineEvents.forCase(caseId)).thenReturn(asList(pregnancyEvent, ancEvent, eventVeryCloseToCurrentDate)); PNCDetail expectedDetail = new PNCDetail(caseId, "TC 1", new CoupleDetails("Woman 1", "Husband 1", "EC Number 1", false).withCaste("c_others").withEconomicStatus("apl").withPhotoPath("photo path"), new LocationDetails("Village 1", "Subcenter 1"), new PregnancyOutcomeDetails("2012-07-28", 4)) .addTimelineEvents(asList(eventFor(eventVeryCloseToCurrentDate, "29-07-2012"), eventFor(ancEvent, "22-12-2011"), eventFor(pregnancyEvent, "21-10-2011"))) .addExtraDetails(details); String actualJson = controller.get(); PNCDetail actualDetail = new Gson().fromJson(actualJson, PNCDetail.class); assertEquals(expectedDetail, actualDetail); }