@Test public void firesPatientChangedEventsWhenPatientDocumentsChange() throws ComponentLookupException { XWikiDocument doc = mock(XWikiDocument.class); when(doc.getXObject(Patient.CLASS_REFERENCE)).thenReturn(mock(BaseObject.class)); when(doc.getDocumentReference()).thenReturn(new DocumentReference("instance", "data", "P0000001")); PatientRepository repo = this.mocker.getInstance(PatientRepository.class); Patient p = mock(Patient.class); when(repo.load(doc)).thenReturn(p); UserManager um = this.mocker.getInstance(UserManager.class); User u = mock(User.class); when(um.getCurrentUser()).thenReturn(u); ObservationManager om = this.mocker.getInstance(ObservationManager.class); CapturingMatcher<PatientEvent> evtCapture = new CapturingMatcher<>(); CapturingMatcher<Object> dataCapture = new CapturingMatcher<>(); Mockito.doNothing().when(om).notify(Matchers.argThat(evtCapture), Matchers.argThat(dataCapture)); this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), doc, null); Assert.assertEquals(1, evtCapture.getAllValues().size()); PatientEvent evt = evtCapture.getLastValue(); Assert.assertNotNull(evt); Assert.assertTrue(evt instanceof PatientChangedEvent); Assert.assertSame(u, evt.getAuthor()); Assert.assertSame(p, evt.getPatient()); Assert.assertSame(doc, dataCapture.getLastValue()); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(doc); User user = this.userManager.getCurrentUser(); this.observationManager.notify(new PatientChangedEvent(patient, user), source); }
PatientChangedEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(doc); User user = this.userManager.getCurrentUser(); this.observationManager.notify(new PatientChangedEvent(patient, user), source); } }
PatientChangedEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(doc); User user = this.userManager.getCurrentUser(); this.observationManager.notify(new PatientChangedEvent(patient, user), source); }  }
PatientChangedEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(doc); User user = this.userManager.getCurrentUser(); this.observationManager.notify(new PatientChangedEvent(patient, user), source); }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data); }
PatientChangedEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(doc); User user = this.userManager.getCurrentUser(); this.observationManager.notify(new PatientChangedEvent(patient, user), source); }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data);  }