EligibleCoupleDetailController { public String get() { EligibleCouple eligibleCouple = allEligibleCouples.findByCaseID(caseId); ECDetail ecContext = new ECDetail(caseId, eligibleCouple.village(), eligibleCouple.subCenter(), eligibleCouple.ecNumber(), eligibleCouple.isHighPriority(), null, eligibleCouple.photoPath(), new ArrayList<Child>(), new CoupleDetails(eligibleCouple.wifeName(), eligibleCouple.husbandName(), eligibleCouple.ecNumber(), eligibleCouple.isOutOfArea()), eligibleCouple.details()). addTimelineEvents(getEvents()); return new Gson().toJson(ecContext); } EligibleCoupleDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples,
                                          AllTimelineEvents allTimelineEvents); String get(); void takePhoto();  }
@Test public void shouldGetANCDetailsAsJSON() { TimelineEvent pregnancyEvent = TimelineEvent.forStartOfPregnancyForEC(caseId, "TC 1", "2011-10-21", "2011-10-21"); TimelineEvent fpEvent = TimelineEvent.forChangeOfFPMethod(caseId, "condom", "iud", "2011-12-22"); TimelineEvent eventVeryCloseToCurrentDate = TimelineEvent.forChangeOfFPMethod(caseId, "iud", "condom", "2012-07-29"); HashMap<String, String> details = new HashMap<String, String>(); details.put("ashaName", "Shiwani"); details.put("isHighPriority", "1"); when(allEligibleCouples.findByCaseID(caseId)).thenReturn(new EligibleCouple("EC CASE 1", "Woman 1", "Husband 1", "EC Number 1", "Village 1", "Subcenter 1", details)); when(allTimelineEvents.forCase(caseId)).thenReturn(asList(pregnancyEvent, fpEvent, eventVeryCloseToCurrentDate)); ECDetail expectedDetail = new ECDetail(caseId, "Village 1", "Subcenter 1", "EC Number 1", true, null, null, new ArrayList<Child>(), new CoupleDetails("Woman 1", "Husband 1", "EC Number 1", false), details) .addTimelineEvents(asList(eventFor(eventVeryCloseToCurrentDate, "29-07-2012"), eventFor(fpEvent, "22-12-2011"), eventFor(pregnancyEvent, "21-10-2011"))); String actualJson = controller.get(); ECDetail actualDetail = new Gson().fromJson(actualJson, ECDetail.class); assertEquals(expectedDetail, actualDetail); }