@Test public void saveAddsNewAttachmentsWhenNeeded() throws ComponentLookupException, IOException, XWikiException { when(this.doc.getAttachment("a1.png")).thenReturn(null); CapturingMatcher<XWikiAttachment> newAttachmentCapturer = new CapturingMatcher<>(); Mockito.doNothing().when(this.doc).addAttachment(Matchers.argThat(newAttachmentCapturer)); this.mocker.getComponentUnderTest().save(this.patient); verify(this.doc).removeXObjects(AdditionalImagesController.CLASS_REFERENCE); verify(this.doc, times(2)).newXObject(AdditionalImagesController.CLASS_REFERENCE, this.context); XWikiAttachment newAttachment = newAttachmentCapturer.getLastValue(); Assert.assertEquals("a1.png", newAttachment.getFilename()); Assert.assertEquals(4, newAttachment.getFilesize()); Assert.assertEquals(this.date1, newAttachment.getDate()); Assert.assertEquals(this.author1, newAttachment.getAuthorReference()); Assert.assertArrayEquals("abcd".getBytes(StandardCharsets.ISO_8859_1), IOUtils.toByteArray(newAttachment.getContentInputStream(this.context))); verify(this.xattachment2).setFilesize(3); verify(this.xattachment2).setDate(this.date2); verify(this.xattachment2).setAuthorReference(this.author2); verify(this.xattachment2).setContent(this.attachment2.getContent()); }
@Override public void save(@Nonnull final Patient patient) { save(patient, PatientWritePolicy.UPDATE); }
AdditionalImagesController implements PatientDataController<Attachment> { @Override public void save(@Nonnull final Patient patient) { save(patient, PatientWritePolicy.UPDATE); } }
AdditionalImagesController implements PatientDataController<Attachment> { @Override public void save(@Nonnull final Patient patient) { save(patient, PatientWritePolicy.UPDATE); }  }
AdditionalImagesController implements PatientDataController<Attachment> { @Override public void save(@Nonnull final Patient patient) { save(patient, PatientWritePolicy.UPDATE); }  @Override PatientData<Attachment> load(Patient patient); @Override void save(@Nonnull final 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(); }
AdditionalImagesController implements PatientDataController<Attachment> { @Override public void save(@Nonnull final Patient patient) { save(patient, PatientWritePolicy.UPDATE); }  @Override PatientData<Attachment> load(Patient patient); @Override void save(@Nonnull final 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(); static final EntityReference CLASS_REFERENCE; }