### Question:
RelativeLinkUpdaterListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { boolean updateRelativeLinks = data instanceof AbstractCopyOrMoveRequest ? ((AbstractCopyOrMoveRequest) data).isUpdateLinks() : true; if (updateRelativeLinks && (event instanceof DocumentCopiedEvent || event instanceof DocumentRenamedEvent)) { @SuppressWarnings("unchecked") AbstractEntityCopyOrRenameEvent<DocumentReference> copyOrRenameEvent = (AbstractEntityCopyOrRenameEvent<DocumentReference>) event; this.logger.info("Updating the relative links from [{}].", copyOrRenameEvent.getTargetReference()); this.linkRefactoring.updateRelativeLinks(copyOrRenameEvent.getSourceReference(), copyOrRenameEvent.getTargetReference()); } } RelativeLinkUpdaterListener(); @Override void onEvent(Event event, Object source, Object data); static final String NAME; }### Answer:
@Test public void onDocumentRenamedWithUpdateLinks() { renameRequest.setUpdateLinks(true); this.listener.onEvent(documentRenamedEvent, null, renameRequest); verify(this.linkRefactoring).updateRelativeLinks(oldReference, newReference); assertEquals("Updating the relative links from [wiki:Users.Bob].", logCapture.getMessage(0)); }
@Test public void onDocumentRenamedWithoutUpdateLinks() { renameRequest.setUpdateLinks(false); this.listener.onEvent(documentRenamedEvent, null, renameRequest); verify(this.linkRefactoring, never()).updateRelativeLinks(any(), any()); }
@Test public void onDocumentRenamedWithoutRenameRequest() { this.listener.onEvent(documentRenamedEvent, null, null); verify(this.linkRefactoring).updateRelativeLinks(oldReference, newReference); assertEquals("Updating the relative links from [wiki:Users.Bob].", logCapture.getMessage(0)); }
@Test public void onDocumentCopiedWithUpdateLinks() { copyRequest.setUpdateLinks(true); this.listener.onEvent(documentCopiedEvent, null, copyRequest); verify(this.linkRefactoring).updateRelativeLinks(oldReference, newReference); assertEquals("Updating the relative links from [wiki:Users.Bob].", logCapture.getMessage(0)); }
@Test public void onDocumentCopiedWithoutUpdateLinks() { copyRequest.setUpdateLinks(false); this.listener.onEvent(documentCopiedEvent, null, copyRequest); verify(this.linkRefactoring, never()).updateRelativeLinks(any(), any()); }
@Test public void onDocumentCopiedWithoutCopyRequest() { this.listener.onEvent(documentCopiedEvent, null, null); verify(this.linkRefactoring).updateRelativeLinks(oldReference, newReference); assertEquals("Updating the relative links from [wiki:Users.Bob].", logCapture.getMessage(0)); }
@Test public void onOtherEvents() { this.listener.onEvent(null, null, null); verify(this.linkRefactoring, never()).updateRelativeLinks(any(), any()); }