@Test
  public void testNullAndEmptyPatientAppointmentList() {
    try {

      // return null list
      when(this.mockJMeadowsClient.getPatientAppointments(any(JMeadowsQuery.class)))
          .thenReturn(null);

      JMeadowsQuery query = new JMeadowsQueryBuilder().user(user).patient(patient).build();

      PatientIds patientIds =
          new PatientIds.Builder().pid(pid).icn(icn).uid(uid).edipi(edipi).build();

      List<VistaDataChunk> vistaDataChunkList =
          jMeadowsAppointmentService.fetchDodPatientAppointments(query, patientIds);

      assertNotNull(vistaDataChunkList);
      assertThat(vistaDataChunkList.size(), is(0));

      // return empty list
      when(this.mockJMeadowsClient.getPatientAppointments(any(JMeadowsQuery.class)))
          .thenReturn(new ArrayList<PatientAppointments>());

      assertNotNull(vistaDataChunkList);
      assertThat(vistaDataChunkList.size(), is(0));

    } catch (JMeadowsException_Exception e) {
      fail(e.getMessage());
    }
  }
  @Test
  public void testFetchPatientAppointments() {
    try {
      when(this.mockJMeadowsClient.getPatientAppointments(any(JMeadowsQuery.class)))
          .thenReturn(createTestData());

      JMeadowsQuery query = new JMeadowsQueryBuilder().user(user).patient(patient).build();

      PatientIds patientIds =
          new PatientIds.Builder().pid(pid).icn(icn).uid(uid).edipi(edipi).build();

      List<VistaDataChunk> vistaDataChunkList =
          jMeadowsAppointmentService.fetchDodPatientAppointments(query, patientIds);

      assertNotNull(vistaDataChunkList);

      // dod status report should have been removed
      assertThat(vistaDataChunkList.size(), is(2));

      List<PatientAppointments> testDataList = createTestData();

      for (int i = 0; i < vistaDataChunkList.size(); i++) {
        VistaDataChunk vistaDataChunk = vistaDataChunkList.get(i);

        assertThat(
            JMeadowsAppointmentService.DOMAIN_APPOINTMENT_VISIT, is(vistaDataChunk.getDomain()));
        assertThat(2, is(vistaDataChunk.getItemCount()));
        assertThat(i + 1, is(vistaDataChunk.getItemIndex()));
        assertThat(vistaId, is(vistaDataChunk.getParams().get("vistaId")));
        assertThat(dfn, is(vistaDataChunk.getParams().get("patientDfn")));
        assertThat(vistaId, is(vistaDataChunk.getSystemId()));
        assertThat(dfn, is(vistaDataChunk.getLocalPatientId()));
        assertThat(icn, is(vistaDataChunk.getPatientIcn()));
        assertThat(pid, is(vistaDataChunk.getPatientId()));
        assertThat(
            "vrpcb://9E7A/HMP SYNCHRONIZATION CONTEXT/HMPDJFS API", is(vistaDataChunk.getRpcUri()));
        assertThat(VistaDataChunk.NEW_OR_UPDATE, is(vistaDataChunk.getType()));

        Map<String, Object> jsonMap = vistaDataChunk.getJsonMap();

        PatientAppointments testPatientAppointment = testDataList.get(i);

        // assertThat("Allergy/Adverse Reaction", is(jsonMap.get("kind")));
        assertThat("DOD", is(jsonMap.get("facilityCode")));
        assertThat("DOD", is(jsonMap.get("facilityName")));
        assertThat(
            "urn:va:appointment:DOD:" + edipi + ":" + testPatientAppointment.getCdrEventId(),
            is(jsonMap.get("uid")));

        List<Map<String, Object>> providers = (List<Map<String, Object>>) jsonMap.get("providers");

        Map<String, Object> provider = providers.get(0);
        assertThat(testPatientAppointment.getProviderName(), is(provider.get("name")));
      }

    } catch (JMeadowsException_Exception e) {
      fail(e.getMessage());
    }
  }