### Question:
LegacyParentFieldUpdaterListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { if (event instanceof DocumentRenamedEvent) { boolean updateParentField = true; if (data instanceof MoveRequest) { updateParentField = ((MoveRequest) data).isUpdateParentField(); } if (updateParentField) { DocumentRenamedEvent documentRenamedEvent = (DocumentRenamedEvent) event; this.logger.info("Updating the document parent fields from [{}] to [{}].", documentRenamedEvent.getSourceReference(), documentRenamedEvent.getTargetReference()); this.modelBridge.updateParentField(documentRenamedEvent.getSourceReference(), documentRenamedEvent.getTargetReference()); } } } LegacyParentFieldUpdaterListener(); @Override void onEvent(Event event, Object source, Object data); static final String NAME; }### Answer:
@Test public void onDocumentRenamedWithUpdateParentField() { renameRequest.setUpdateParentField(true); this.listener.onEvent(documentRenamedEvent, null, renameRequest); verify(this.modelBridge).updateParentField(oldReference, newReference); assertEquals("Updating the document parent fields from [wiki:Users.Alice] to [wiki:Users.Bob].", logCapture.getMessage(0)); }
@Test public void onDocumentRenamedWithoutUpdateParentField() { renameRequest.setUpdateParentField(false); this.listener.onEvent(documentRenamedEvent, null, renameRequest); verify(this.modelBridge, never()).updateParentField(any(), any()); }
@Test public void onDocumentRenamedWithoutRenameRequest() { this.listener.onEvent(documentRenamedEvent, null, null); verify(this.modelBridge).updateParentField(oldReference, newReference); assertEquals("Updating the document parent fields from [wiki:Users.Alice] to [wiki:Users.Bob].", logCapture.getMessage(0)); }
@Test public void onOtherEvents() { this.listener.onEvent(null, null, null); verify(this.modelBridge, never()).updateParentField(any(), any()); }