### Question:
OfficeImporterScriptService implements ScriptService { @Unstable public boolean save(XDOMOfficeDocument doc, DocumentReference documentReference, DocumentReference parentReference, String title, boolean append) { return save(doc, documentReference, this.extendedRenderingConfiguration.getDefaultContentSyntax().toIdString(), parentReference, title, append); }  XHTMLOfficeDocument officeToXHTML(InputStream officeFileStream, String officeFileName,
        DocumentReference targetDocumentReference, boolean filterStyles); XHTMLOfficeDocument officeToXHTML(InputStream officeFileStream, String officeFileName,
        String referenceDocument, boolean filterStyles); XDOMOfficeDocument xhtmlToXDOM(XHTMLOfficeDocument xhtmlOfficeDocument); XDOMOfficeDocument officeToXDOM(InputStream officeFileStream, String officeFileName,
        DocumentReference targetDocumentReference, boolean filterStyles); XDOMOfficeDocument officeToXDOM(InputStream officeFileStream, String officeFileName,
        String referenceDocument, boolean filterStyles); Map<TargetDocumentDescriptor, XDOMOfficeDocument> split(XDOMOfficeDocument xdomDocument,
        String[] headingLevels, String namingCriterionHint, DocumentReference rootDocumentReference); Map<TargetDocumentDescriptor, XDOMOfficeDocument> split(XDOMOfficeDocument xdomDocument,
        String[] headingLevels, String namingCriterionHint, String rootDocumentName); @Unstable boolean save(XDOMOfficeDocument doc, DocumentReference documentReference, DocumentReference parentReference,
        String title, boolean append); boolean save(XDOMOfficeDocument doc, DocumentReference documentReference, String syntaxId,
        DocumentReference parentReference, String title, boolean append); boolean save(XDOMOfficeDocument doc, String target, String syntaxId, String parent, String title,
        boolean append); String getErrorMessage(); static final String OFFICE_IMPORTER_ERROR; }### Answer:
@Test public void saveWithOverwrite() throws Exception { XDOMOfficeDocument doc = mock(XDOMOfficeDocument.class); DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page"); DocumentReference parentReference = new DocumentReference("wiki", "Space", "Parent"); String syntaxId = "test/1.0"; String title = "Office Document Title"; String content = "Office Document Content"; String fileName = "logo.png"; byte[] fileContent = new byte[] {65, 82}; when(documentAccessBridge.isDocumentEditable(documentReference)).thenReturn(true); when(doc.getContentAsString(syntaxId)).thenReturn(content); when(doc.getArtifacts()).thenReturn(Collections.singletonMap(fileName, fileContent)); assertTrue(officeImporterScriptService.save(doc, documentReference, syntaxId, parentReference, title, false)); verify(documentAccessBridge).setDocumentSyntaxId(documentReference, syntaxId); verify(documentAccessBridge).setDocumentContent(documentReference, content, "Created by office importer.", false); verify(documentAccessBridge).setDocumentParentReference(documentReference, parentReference); verify(documentAccessBridge).setDocumentTitle(documentReference, title); verify(documentAccessBridge).setAttachmentContent(new AttachmentReference(fileName, documentReference), fileContent); }
@Test public void saveWithAppend() throws Exception { XDOMOfficeDocument doc = mock(XDOMOfficeDocument.class); DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page"); String syntaxId = "test/1.0"; when(documentAccessBridge.isDocumentEditable(documentReference)).thenReturn(true); when(documentAccessBridge.exists(documentReference)).thenReturn(true); DocumentModelBridge document = mock(DocumentModelBridge.class); when(documentAccessBridge.getTranslatedDocumentInstance(documentReference)).thenReturn(document); when(document.getSyntax()).thenReturn(new Syntax(new SyntaxType("test", "Test"), "1.0")); when(documentAccessBridge.getDocumentContent(documentReference, null)).thenReturn("before"); when(doc.getContentAsString(syntaxId)).thenReturn("after"); assertTrue(officeImporterScriptService.save(doc, documentReference, syntaxId, null, null, true)); verify(documentAccessBridge).setDocumentContent(documentReference, "before\nafter", "Updated by office importer.", false); }