### Question:
LinkCheckerEventListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { DocumentModelBridge doc = (DocumentModelBridge) source; final String reference = this.serializer.serialize(doc.getDocumentReference()); Map<String, Map<String, LinkState>> states = this.linkStateManager.getLinkStates(); for (Map.Entry<String, Map<String, LinkState>> entry : states.entrySet()) { Map<String, LinkState> state = entry.getValue(); state.remove(reference); if (state.size() == 0) { states.remove(entry.getKey()); } } }  @Override List<Event> getEvents(); @Override String getName(); @Override void onEvent(Event event, Object source, Object data);  }### Answer:
@Test public void testOnEvent() throws Exception { final DocumentModelBridge documentModelBridge = getMockery().mock(DocumentModelBridge.class); final EntityReferenceSerializer serializer = getComponentManager().getInstance( EntityReferenceSerializer.TYPE_STRING); final DocumentReference reference = new DocumentReference("wiki", "space", "page"); final LinkStateManager linkStateManager = getComponentManager().getInstance(LinkStateManager.class); final Map<String, Map<String, LinkState>> states = new HashMap<String, Map<String, LinkState>>(); Map<String, LinkState> referenceStates1 = new HashMap<String, LinkState>(); referenceStates1.put("wiki1:space1.page1", new LinkState(200, System.currentTimeMillis())); referenceStates1.put("wiki2:space2.page2", new LinkState(200, System.currentTimeMillis())); states.put("url1", referenceStates1); Map<String, LinkState> referenceStates2 = new HashMap<String, LinkState>(); referenceStates2.put("wiki1:space1.page1", new LinkState(200, System.currentTimeMillis())); states.put("url2", referenceStates2); getMockery().checking(new Expectations() {{ oneOf(documentModelBridge).getDocumentReference(); will(returnValue(reference)); oneOf(serializer).serialize(reference); will(returnValue("wiki1:space1.page1")); oneOf(linkStateManager).getLinkStates(); will(returnValue(states)); }}); this.listener.onEvent(new DocumentUpdatingEvent(), documentModelBridge, null); Assert.assertEquals(1, states.size()); Assert.assertEquals(1, states.get("url1").size()); Assert.assertNull(states.get("url2")); }