@Test public void loadCatchesExceptionWhenPatientDoesNotHavePatientClass() throws ComponentLookupException { when(this.doc.getXObject(Patient.CLASS_REFERENCE)).thenReturn(null); PatientData<Attachment> result = this.mocker.getComponentUnderTest().load(this.patient); Assert.assertNull(result); }
@Override public PatientData<Attachment> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { throw new NullPointerException(ERROR_MESSAGE_NO_PATIENT_CLASS); } @SuppressWarnings("unchecked") List<String> reports = data.getListValue(FIELD_NAME); List<Attachment> result = new ArrayList<>(reports.size()); for (String report : reports) { XWikiAttachment xattachment = doc.getAttachment(report); if (xattachment != null) { result.add(this.adapter.fromXWikiAttachment(xattachment)); } } return new IndexedPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }
MedicalReportsController implements PatientDataController<Attachment> { @Override public PatientData<Attachment> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { throw new NullPointerException(ERROR_MESSAGE_NO_PATIENT_CLASS); } @SuppressWarnings("unchecked") List<String> reports = data.getListValue(FIELD_NAME); List<Attachment> result = new ArrayList<>(reports.size()); for (String report : reports) { XWikiAttachment xattachment = doc.getAttachment(report); if (xattachment != null) { result.add(this.adapter.fromXWikiAttachment(xattachment)); } } return new IndexedPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; } }
MedicalReportsController implements PatientDataController<Attachment> { @Override public PatientData<Attachment> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { throw new NullPointerException(ERROR_MESSAGE_NO_PATIENT_CLASS); } @SuppressWarnings("unchecked") List<String> reports = data.getListValue(FIELD_NAME); List<Attachment> result = new ArrayList<>(reports.size()); for (String report : reports) { XWikiAttachment xattachment = doc.getAttachment(report); if (xattachment != null) { result.add(this.adapter.fromXWikiAttachment(xattachment)); } } return new IndexedPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  }
MedicalReportsController implements PatientDataController<Attachment> { @Override public PatientData<Attachment> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { throw new NullPointerException(ERROR_MESSAGE_NO_PATIENT_CLASS); } @SuppressWarnings("unchecked") List<String> reports = data.getListValue(FIELD_NAME); List<Attachment> result = new ArrayList<>(reports.size()); for (String report : reports) { XWikiAttachment xattachment = doc.getAttachment(report); if (xattachment != null) { result.add(this.adapter.fromXWikiAttachment(xattachment)); } } return new IndexedPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  @Override PatientData<Attachment> load(Patient patient); @Override void save(Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); @Override void writeJSON(Patient patient, JSONObject json); @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override PatientData<Attachment> readJSON(JSONObject json); @Override String getName(); }
MedicalReportsController implements PatientDataController<Attachment> { @Override public PatientData<Attachment> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { throw new NullPointerException(ERROR_MESSAGE_NO_PATIENT_CLASS); } @SuppressWarnings("unchecked") List<String> reports = data.getListValue(FIELD_NAME); List<Attachment> result = new ArrayList<>(reports.size()); for (String report : reports) { XWikiAttachment xattachment = doc.getAttachment(report); if (xattachment != null) { result.add(this.adapter.fromXWikiAttachment(xattachment)); } } return new IndexedPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  @Override PatientData<Attachment> load(Patient patient); @Override void save(Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); @Override void writeJSON(Patient patient, JSONObject json); @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override PatientData<Attachment> readJSON(JSONObject json); @Override String getName();  }