@Test
  public void testOnEvent_nullDoc_ing() {
    Event event = new DocumentUpdatingEvent();

    replayDefault();
    listener.onEvent(event, null, context);
    verifyDefault();
  }
  @Test
  public void testOnEvent_update_ed_includeDocFields_noChange() {
    Event event = new DocumentUpdatedEvent();
    listener.includeDocFields = true;

    expect(remoteObsManContextMock.isRemoteState()).andReturn(false).once();
    expect(docMock.getXObject(eq(classRef))).andReturn(new BaseObject()).once();
    expect(origDocMock.getXObject(eq(classRef))).andReturn(new BaseObject()).once();
    expect(docMock.getTitle()).andReturn("").once();
    expect(origDocMock.getTitle()).andReturn("").once();
    expect(docMock.getContent()).andReturn("").once();
    expect(origDocMock.getContent()).andReturn("").once();

    replayDefault();
    listener.onEvent(event, docMock, context);
    verifyDefault();
  }
  @Test
  public void testOnEvent_isRemote_ed() {
    Event event = new DocumentUpdatedEvent();

    expect(remoteObsManContextMock.isRemoteState()).andReturn(true).once();

    replayDefault();
    listener.onEvent(event, docMock, context);
    verifyDefault();
  }
  @Test
  public void testOnEvent_noObjs_ed() {
    Event event = new DocumentUpdatedEvent();

    expect(remoteObsManContextMock.isRemoteState()).andReturn(false).once();
    expect(docMock.getXObject(eq(classRef))).andReturn(null).once();
    expect(origDocMock.getXObject(eq(classRef))).andReturn(null).once();

    replayDefault();
    listener.onEvent(event, docMock, context);
    verifyDefault();
  }
  @Before
  public void setUp_AbstractDocumentUpdateListenerTest() throws Exception {
    context = getContext();
    classRef = new DocumentReference("wiki", "Classes", "SomeClass");
    fields = Arrays.asList("field1", "field2");
    docRef = new DocumentReference("wiki", "Space", "SomeDoc");
    docMock = createMockAndAddToDefault(XWikiDocument.class);
    expect(docMock.getDocumentReference()).andReturn(docRef).anyTimes();
    origDocMock = createMockAndAddToDefault(XWikiDocument.class);
    expect(origDocMock.getDocumentReference()).andReturn(docRef).anyTimes();
    expect(docMock.getOriginalDocument()).andReturn(origDocMock).anyTimes();

    listener = new TestDocumentUpdateListener();
    listener.injectWebUtilsService(Utils.getComponent(IWebUtilsService.class));
    listener.injecExecution(Utils.getComponent(Execution.class));
    listener.injectCopyDocService(Utils.getComponent(ICopyDocumentRole.class));
    listener.injectRemoteObservationManagerContext(
        remoteObsManContextMock = createMockAndAddToDefault(RemoteObservationManagerContext.class));
    listener.injectObservationManager(
        obsManagerMock = createMockAndAddToDefault(ObservationManager.class));
    listener.configSrc = Utils.getComponent(ConfigurationSource.class);

    creatingEventMock = createMockAndAddToDefault(Event.class);
    createdEventMock = createMockAndAddToDefault(Event.class);
    updatingEventMock = createMockAndAddToDefault(Event.class);
    updatedEventMock = createMockAndAddToDefault(Event.class);
    deletingEventMock = createMockAndAddToDefault(Event.class);
    deletedEventMock = createMockAndAddToDefault(Event.class);
  }
  @Test
  public void testOnEvent_update_ing_noEvent() {
    Event event = new DocumentUpdatingEvent();
    updatingEventMock = null;

    expect(remoteObsManContextMock.isRemoteState()).andReturn(false).once();
    expect(docMock.getXObject(eq(classRef))).andReturn(getBaseObject1()).once();
    expect(origDocMock.getXObject(eq(classRef))).andReturn(getBaseObject2()).once();

    replayDefault();
    listener.onEvent(event, docMock, context);
    verifyDefault();
  }
 @Test
 public void testGetEvents() {
   Set<Class<? extends Event>> eventClasses = new HashSet<Class<? extends Event>>();
   for (Event theEvent : listener.getEvents()) {
     eventClasses.add(theEvent.getClass());
   }
   assertEquals(2, eventClasses.size());
   assertTrue(
       "Expecting registration for DocumentUpdatingEvent",
       eventClasses.contains(DocumentUpdatingEvent.class));
   assertTrue(
       "Expecting registration for DocumentUpdatedEvent events",
       eventClasses.contains(DocumentUpdatedEvent.class));
 }
  @Test
  public void testOnEvent_update_ed() {
    Event event = new DocumentUpdatedEvent();

    expect(remoteObsManContextMock.isRemoteState()).andReturn(false).once();
    expect(docMock.getXObject(eq(classRef))).andReturn(getBaseObject1()).once();
    expect(origDocMock.getXObject(eq(classRef))).andReturn(getBaseObject2()).once();
    obsManagerMock.notify(same(updatedEventMock), same(docMock), same(context));
    expectLastCall().once();

    replayDefault();
    listener.onEvent(event, docMock, context);
    verifyDefault();
  }