@Test public void saveMergesGenesWhenPolicyIsMerge() throws XWikiException { List<Gene> data = new LinkedList<>(); Gene gene = new PhenoTipsGene("GENE1", null, null, null, "Notes1"); Gene gene2 = new PhenoTipsGene("GENE2", null, null, null, null); data.add(gene); data.add(gene2); when(this.patient.<Gene>getData(CONTROLLER_NAME)) .thenReturn(new IndexedPatientData<>(CONTROLLER_NAME, data)); when(this.context.getWiki()).thenReturn(mock(XWiki.class)); BaseObject o1 = mock(BaseObject.class); BaseObject o2 = mock(BaseObject.class); BaseObject o3 = mock(BaseObject.class); when(this.doc.getXObjects(Gene.GENE_CLASS)).thenReturn(Collections.singletonList(o3)); final BaseStringProperty geneProperty = mock(BaseStringProperty.class); final BaseStringProperty statusProperty = mock(BaseStringProperty.class); when(o3.getFieldList()).thenReturn(Arrays.asList(GENE_KEY, STATUS_KEY)); when(o3.getField(GENE_KEY)).thenReturn(geneProperty); when(o3.getField(STATUS_KEY)).thenReturn(statusProperty); when(o3.getField(STRATEGY_KEY)).thenReturn(null); when(o3.getField(COMMENTS_KEY)).thenReturn(null); when(geneProperty.getValue()).thenReturn(GENE_VALUE); when(statusProperty.getValue()).thenReturn(STATUS_KEY); when(this.doc.newXObject(Gene.GENE_CLASS, this.context)).thenReturn(o3, o1, o2); this.component.save(this.patient, PatientWritePolicy.MERGE); verify(this.doc, times(1)).removeXObjects(Gene.GENE_CLASS); verify(this.doc, times(3)).newXObject(Gene.GENE_CLASS, this.context); verify(this.doc, times(1)).getXObjects(Gene.GENE_CLASS); verify(o1).set(GENE_KEY, "GENE1", this.context); verify(o1).set(COMMENTS_KEY, "Notes1", this.context); verify(o2).set(GENE_KEY, "GENE2", this.context); verify(o2, never()).set(eq(COMMENTS_KEY), anyString(), eq(this.context)); verify(o3, times(1)).set(GENE_KEY, GENE_VALUE, this.context); verify(o3, times(1)).set(STATUS_KEY, JSON_OLD_CANDIDATE_GENE_KEY, this.context); verify(o3, times(1)).set(eq(STRATEGY_KEY), eq(Collections.emptyList()), eq(this.context)); verify(o3, never()).set(eq(COMMENTS_KEY), any(), eq(this.context)); verify(o3, times(1)).getFieldList(); verify(o3, times(4)).getField(anyString()); verifyNoMoreInteractions(this.doc); }
@Override public void save(Patient patient) { save(patient, PatientWritePolicy.UPDATE); }
GeneListController implements PatientDataController<Gene> { @Override public void save(Patient patient) { save(patient, PatientWritePolicy.UPDATE); } }
GeneListController implements PatientDataController<Gene> { @Override public void save(Patient patient) { save(patient, PatientWritePolicy.UPDATE); }  }
GeneListController implements PatientDataController<Gene> { @Override public void save(Patient patient) { save(patient, PatientWritePolicy.UPDATE); }  @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 save(Patient patient) { save(patient, PatientWritePolicy.UPDATE); }  @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);  }