### Question:
EventReporter implements Publisher { public Event reportEvent(String messageFile, String eventAction) throws ADKException { Event event = CustomEventGenerator.generateEvent(messageFile, EventAction.valueOf(eventAction)); if (event == null) { LOG.error("Null event can not be reported"); return null; } if (zone.isConnected()) { zone.reportEvent(event); } else { LOG.error("Zone is not connected"); return null; } return event; } EventReporter(Zone zone); static void main(String[] args); List<Event> runReportScript(String script, long waitTime); Event reportLeaInfoEvent(EventAction action); Event reportSchoolInfoEvent(EventAction action); Event reportStudentPersonalEvent(EventAction action); Event reportStudentLeaRelationshipEvent(EventAction action); Event reportStudentSchoolEnrollmentEvent(EventAction action); Event reportStaffPersonalEvent(EventAction action); Event reportEmployeePersonalEvent(EventAction action); Event reportStaffAssignmentEvent(EventAction action); Event reportEmploymentRecordEvent(EventAction action); Event reportEmployeeAssignmentEvent(EventAction action); Event reportEvent(String messageFile, String eventAction); @Override void onRequest(DataObjectOutputStream out, Query query, Zone zone, MessageInfo info); static final Logger LOG; }### Answer:
@Test public void testReportEventValidFile() throws ADKException { URL url = getClass().getResource("/element_xml/StudentPersonal.xml"); String validFilename = url.getPath(); String eventActionStr = EventAction.ADD.toString(); Event event = eventReporter.reportEvent(validFilename, eventActionStr); Assert.assertNotNull(event); EventAction eventAction = event.getAction(); Assert.assertEquals(eventActionStr, eventAction.toString()); Mockito.verify(zone, Mockito.times(1)).reportEvent(Mockito.eq(event)); eventActionStr = EventAction.CHANGE.toString(); event = eventReporter.reportEvent(validFilename, eventActionStr); Assert.assertNotNull(event); eventAction = event.getAction(); Assert.assertEquals(eventActionStr, eventAction.toString()); Mockito.verify(zone, Mockito.times(1)).reportEvent(Mockito.eq(event)); eventActionStr = EventAction.DELETE.toString(); event = eventReporter.reportEvent(validFilename, eventActionStr); Assert.assertNotNull(event); eventAction = event.getAction(); Assert.assertEquals(eventActionStr, eventAction.toString()); Mockito.verify(zone, Mockito.times(1)).reportEvent(Mockito.eq(event)); Mockito.when(zone.isConnected()).thenReturn(false); event = eventReporter.reportEvent(validFilename, EventAction.ADD.toString()); Assert.assertNull(event); Mockito.verify(zone, Mockito.times(0)).reportEvent(Mockito.eq(event)); }
@Test public void testReportEventInvalidFile() throws ADKException { String invalidFilename = "doesntexist.xml"; Event event = eventReporter.reportEvent(invalidFilename, EventAction.ADD.toString()); Assert.assertNull(event); Mockito.verify(zone, Mockito.times(0)).reportEvent(Mockito.eq(event)); }