@Test public void writeJSONReturnsWhenDataIsEmpty() throws ComponentLookupException { List<Gene> internalList = new LinkedList<>(); PatientData<Gene> patientData = new IndexedPatientData<>(CONTROLLER_NAME, internalList); doReturn(patientData).when(this.patient).getData(CONTROLLER_NAME); JSONObject json = new JSONObject(); Collection<String> selectedFields = new LinkedList<>(); selectedFields.add(GENES_ENABLING_FIELD_NAME); this.component.writeJSON(this.patient, json, selectedFields); Assert.assertTrue(json.has(CONTROLLER_NAME)); verify(this.patient).getData(CONTROLLER_NAME); }
@Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { if (selectedFieldNames != null && !selectedFieldNames.contains(GENES_ENABLING_FIELD_NAME)) { return; } PatientData<Gene> data = patient.getData(getName()); if (data == null || data.size() == 0) { if (selectedFieldNames == null || selectedFieldNames.contains(GENES_ENABLING_FIELD_NAME)) { json.put(GENES_STRING, new JSONArray()); } return; } JSONArray geneArray = new JSONArray(); for (Gene gene : data) { geneArray.put(gene.toJSON()); } json.put(GENES_STRING, geneArray); }
GeneListController implements PatientDataController<Gene> { @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { if (selectedFieldNames != null && !selectedFieldNames.contains(GENES_ENABLING_FIELD_NAME)) { return; } PatientData<Gene> data = patient.getData(getName()); if (data == null || data.size() == 0) { if (selectedFieldNames == null || selectedFieldNames.contains(GENES_ENABLING_FIELD_NAME)) { json.put(GENES_STRING, new JSONArray()); } return; } JSONArray geneArray = new JSONArray(); for (Gene gene : data) { geneArray.put(gene.toJSON()); } json.put(GENES_STRING, geneArray); } }
GeneListController implements PatientDataController<Gene> { @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { if (selectedFieldNames != null && !selectedFieldNames.contains(GENES_ENABLING_FIELD_NAME)) { return; } PatientData<Gene> data = patient.getData(getName()); if (data == null || data.size() == 0) { if (selectedFieldNames == null || selectedFieldNames.contains(GENES_ENABLING_FIELD_NAME)) { json.put(GENES_STRING, new JSONArray()); } return; } JSONArray geneArray = new JSONArray(); for (Gene gene : data) { geneArray.put(gene.toJSON()); } json.put(GENES_STRING, geneArray); }  }
GeneListController implements PatientDataController<Gene> { @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { if (selectedFieldNames != null && !selectedFieldNames.contains(GENES_ENABLING_FIELD_NAME)) { return; } PatientData<Gene> data = patient.getData(getName()); if (data == null || data.size() == 0) { if (selectedFieldNames == null || selectedFieldNames.contains(GENES_ENABLING_FIELD_NAME)) { json.put(GENES_STRING, new JSONArray()); } return; } JSONArray geneArray = new JSONArray(); for (Gene gene : data) { geneArray.put(gene.toJSON()); } json.put(GENES_STRING, geneArray); }  @Override String getName(); @Override PatientData<Gene> load(Patient patient); @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override PatientData<Gene> readJSON(JSONObject json); @Override void save(Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); @Override void writeJSON(Patient patient, JSONObject json); }
GeneListController implements PatientDataController<Gene> { @Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { if (selectedFieldNames != null && !selectedFieldNames.contains(GENES_ENABLING_FIELD_NAME)) { return; } PatientData<Gene> data = patient.getData(getName()); if (data == null || data.size() == 0) { if (selectedFieldNames == null || selectedFieldNames.contains(GENES_ENABLING_FIELD_NAME)) { json.put(GENES_STRING, new JSONArray()); } return; } JSONArray geneArray = new JSONArray(); for (Gene gene : data) { geneArray.put(gene.toJSON()); } json.put(GENES_STRING, geneArray); }  @Override String getName(); @Override PatientData<Gene> load(Patient patient); @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override PatientData<Gene> readJSON(JSONObject json); @Override void save(Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); @Override void writeJSON(Patient patient, JSONObject json);  }