@Test
  public void
      shouldAddPromptsForWelcomeMessage_AdherenceSummary_AndAdherenceCapture_ForFirstPatient() {
    final List<String> patientsWithAdherence = asList(patient1.getPatientId());
    final List<String> patientsWithoutAdherence =
        asList(patient2.getPatientId(), patient3.getPatientId());
    setAdherenceProvided(patient1);
    AdherenceSummaryByProvider adherenceSummary =
        adherenceSummary(asList(patient1, patient2, patient3));
    when(adherenceDataService.getAdherenceSummary(PROVIDER_ID)).thenReturn(adherenceSummary);

    Node expectedNode =
        new Node()
            .addPrompts(welcomeMessagePrompts(whpIvrMessage))
            .addPrompts(
                adherenceSummaryPrompts(
                    whpIvrMessage, patientsWithAdherence, patientsWithoutAdherence))
            .addPrompts(
                CaptureAdherencePrompts.captureAdherencePrompts(
                    whpIvrMessage, patient2.getPatientId(), 1))
            .addTransition("?", new AdherenceCaptureTransition())
            .addTransition("hangup", new HangupTransition());

    Node actualNode = adherenceSummaryTransition.getDestinationNode("", flowSession);
    assertThat(actualNode, is(expectedNode));
  }
  @Test
  public void shouldPlayWelcomeMessagePrompts() {
    AdherenceSummaryByProvider adherenceSummary = adherenceSummary(asList(patient1, patient2));
    when(adherenceDataService.getAdherenceSummary(PROVIDER_ID)).thenReturn(adherenceSummary);

    Node destinationNode = adherenceSummaryTransition.getDestinationNode("", flowSession);

    assertThat(destinationNode.getPrompts(), hasItems(welcomeMessagePrompts(whpIvrMessage)));
  }
  @Test
  public void shouldSetMaxInputDigitIfItHasTransition() {
    setAdherenceProvided(patient1);
    AdherenceSummaryByProvider adherenceSummary =
        adherenceSummary(asList(patient1, patient2, patient3));
    when(adherenceDataService.getAdherenceSummary(PROVIDER_ID)).thenReturn(adherenceSummary);

    Node actualNode = adherenceSummaryTransition.getDestinationNode("", flowSession);
    assertThat(actualNode.getMaxTransitionInputDigit(), is(1));
  }
  @Test
  public void shouldAddRecordCallStartTime() throws Exception {
    DateTime now = new DateTime(2011, 1, 2, 1, 1, 1, 1);
    mockCurrentDate(now);

    AdherenceSummaryByProvider adherenceSummary = adherenceSummary(asList(patient1, patient2));
    when(adherenceDataService.getAdherenceSummary(PROVIDER_ID)).thenReturn(adherenceSummary);

    List<INodeOperation> operations =
        adherenceSummaryTransition.getDestinationNode("", flowSession).getOperations();
    assertThat(operations, hasItem(new RecordCallStartTimeOperation(now)));
  }
  @Test
  public void shouldAddHangupTransitionWhenThereAreNoPatientsRemaining() {
    setAdherenceProvided(patient1);
    setAdherenceProvided(patient2);

    AdherenceSummaryByProvider adherenceSummary = adherenceSummary(asList(patient1, patient2));
    when(adherenceDataService.getAdherenceSummary(PROVIDER_ID)).thenReturn(adherenceSummary);
    mockCurrentDate(DateUtil.now());

    Node actualNode = adherenceSummaryTransition.getDestinationNode("", flowSession);
    assertEquals(flowSession.get(IvrSession.CALL_STATUS), CallStatus.ADHERENCE_ALREADY_PROVIDED);
    assertEquals(new HangupTransition(), actualNode.getTransitions().get("hangup"));
    assertThat(actualNode.getOperations(), hasItem(isA(RecordCallStartTimeOperation.class)));
  }
  @Test
  public void shouldSaveCallLogWhenProviderCallsOnDayOutsideWindow() {
    DateTime now = new DateTime(2012, 8, 8, 1, 1, 1, 1);
    AdherenceSummaryByProvider adherenceSummary = adherenceSummary(asList(patient1, patient2));

    mockCurrentDate(now);
    when(adherenceDataService.getAdherenceSummary(PROVIDER_ID)).thenReturn(adherenceSummary);

    Node destinationNode = adherenceSummaryTransition.getDestinationNode("", flowSession);

    Assert.assertThat(
        destinationNode.getOperations(), hasItem(isA(RecordCallStartTimeOperation.class)));
    assertEquals(
        flowSession.get(IvrSession.CALL_STATUS), CallStatus.OUTSIDE_ADHERENCE_CAPTURE_WINDOW);
  }
  @Test
  public void shouldBuildNodeWhichCapturesTimeOfAdherenceSubmission() {
    DateTime now = new DateTime(2011, 1, 2, 1, 1, 1, 1);
    mockCurrentDate(now);

    AdherenceSummaryByProvider adherenceSummary = adherenceSummary(asList(patient1, patient2));
    when(adherenceDataService.getAdherenceSummary(PROVIDER_ID)).thenReturn(adherenceSummary);

    List<INodeOperation> operations =
        adherenceSummaryTransition.getDestinationNode("", flowSession).getOperations();
    for (INodeOperation operation : operations) {
      operation.perform("", flowSession);
    }
    assertEquals(now, new IvrSession(flowSession).startOfAdherenceSubmission());
  }
  public void shouldPlayWindowClosedPrompts_whenCalledBetweenWedToSat() {
    DateTime now = new DateTime(2012, 8, 8, 1, 1, 1, 1);
    AdherenceSummaryByProvider adherenceSummary = adherenceSummary(asList(patient1, patient2));

    mockCurrentDate(now);
    when(adherenceDataService.getAdherenceSummary(PROVIDER_ID)).thenReturn(adherenceSummary);

    Node destinationNode = adherenceSummaryTransition.getDestinationNode("", flowSession);

    Node expectedNode =
        new Node()
            .addPrompts(welcomeMessagePrompts(whpIvrMessage))
            .addPrompts(adherenceCaptureWindowClosedPrompts(whpIvrMessage))
            .addTransition("hangup", new HangupTransition());

    assertThat(destinationNode.getPrompts(), is(expectedNode.getPrompts()));
    assertThat(destinationNode.getTransitions(), is(expectedNode.getTransitions()));
  }
  @Test
  public void
      shouldAddPromptsForWelcomeMessage_AdherenceSummary_AndCompletion_WhenThereAreNoPatientsRemaining() {
    setAdherenceProvided(patient1);
    setAdherenceProvided(patient2);

    AdherenceSummaryByProvider adherenceSummary = adherenceSummary(asList(patient1, patient2));
    when(adherenceDataService.getAdherenceSummary(PROVIDER_ID)).thenReturn(adherenceSummary);
    mockCurrentDate(DateUtil.now());
    List<Prompt> expectedPrompts =
        new PromptBuilder(whpIvrMessage)
            .addAll(welcomeMessagePrompts(whpIvrMessage))
            .addAll(
                adherenceSummaryWithCallCompletionPrompts(
                    whpIvrMessage,
                    adherenceSummary.countOfAllPatients(),
                    adherenceSummary.countOfPatientsWithAdherence()))
            .buildList();

    Node actualNode = adherenceSummaryTransition.getDestinationNode("", flowSession);
    assertThat(actualNode.getPrompts(), is(expectedPrompts));
  }