### Question:
CommentEventGeneratorListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; XWikiDocument originalDoc = doc.getOriginalDocument(); XWikiContext context = (XWikiContext) data; XObjectEvent objectEvent = (XObjectEvent) event; String reference = this.defaultEntityReferenceSerializer.serialize(doc.getDocumentReference()); if (event instanceof XObjectDeletedEvent) { BaseObject obj = originalDoc.getXObject((ObjectReference) objectEvent.getReference()); String number = String.valueOf(obj.getNumber()); this.observation.notify(new CommentDeletedEvent(reference, number), source, context); } else { BaseObject obj = doc.getXObject((ObjectReference) objectEvent.getReference()); String number = String.valueOf(obj.getNumber()); if (event instanceof XObjectAddedEvent) { this.observation.notify(new CommentAddedEvent(reference, number), source, context); } else { this.observation.notify(new CommentUpdatedEvent(reference, number), source, context); } } } CommentEventGeneratorListener(); @Override void onEvent(Event event, Object source, Object data);  }### Answer:
@Test public void testAddComment() throws ComponentLookupException { this.document.addXObject(this.commentXObject); final Event event = new CommentAddedEvent("wiki:space.page", "0"); this.mocker.getComponentUnderTest().onEvent(new XObjectAddedEvent(this.commentXObject.getReference()), this.document, this.oldcore.getXWikiContext()); verify(this.mockObservation) .notify(any(event.getClass()), same(document), same(this.oldcore.getXWikiContext())); }
@Test public void testDeleteComment() throws ComponentLookupException { this.documentOrigin.addXObject(this.commentXObject); final Event event = new CommentDeletedEvent("wiki:space.page", "0"); this.mocker.getComponentUnderTest().onEvent(new XObjectDeletedEvent(this.commentXObject.getReference()), this.document, this.oldcore.getXWikiContext()); verify(this.mockObservation) .notify(any(event.getClass()), same(document), same(this.oldcore.getXWikiContext())); }
@Test public void testModifiedComment() throws ComponentLookupException { this.document.addXObject(this.commentXObject); this.documentOrigin.addXObject(this.commentXObject.clone()); this.commentXObject.setStringValue("comment", "comment"); final Event event = new CommentUpdatedEvent("wiki:space.page", "0"); this.mocker.getComponentUnderTest().onEvent(new XObjectUpdatedEvent(this.commentXObject.getReference()), this.document, this.oldcore.getXWikiContext()); verify(this.mockObservation) .notify(any(event.getClass()), same(document), same(this.oldcore.getXWikiContext())); }