### Question:
IconThemeListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; List<BaseObject> iconThemeObjects = document.getXObjects(ICON_THEME_CLASS); if (iconThemeObjects != null && !iconThemeObjects.isEmpty()) { iconSetCache.clear(document.getDocumentReference()); BaseObject iconThemeObj = iconThemeObjects.get(0); String iconThemeName = iconThemeObj.getStringValue("name"); String currentWiki = document.getDocumentReference().getWikiReference().getName(); iconSetCache.clear(iconThemeName, currentWiki); } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data);  }### Answer:
@Test public void onEvent() throws Exception { XWikiDocument doc = mock(XWikiDocument.class); List<BaseObject> list = new ArrayList<BaseObject>(); BaseObject obj = mock(BaseObject.class); list.add(obj); when(obj.getStringValue("name")).thenReturn("icontheme1"); DocumentReference docRef = new DocumentReference("wikiA", "b", "c"); when(doc.getDocumentReference()).thenReturn(docRef); LocalDocumentReference iconThemeClassRef = new LocalDocumentReference("IconThemesCode", "IconThemeClass"); when(doc.getXObjects(eq(iconThemeClassRef))).thenReturn(list); mocker.getComponentUnderTest().onEvent(null, doc, null); verify(iconSetCache, atLeastOnce()).clear(docRef); verify(iconSetCache, atLeastOnce()).clear("icontheme1", "wikiA"); }
@Test public void onEventWhenNoObjects() throws Exception { XWikiDocument doc = mock(XWikiDocument.class); when(doc.getXObject(any(DocumentReference.class))).thenReturn(null); mocker.getComponentUnderTest().onEvent(null, doc, null); verify(iconSetCache, never()).clear(any(DocumentReference.class)); }
@Test public void onEventWhenEmptyListObjects() throws Exception { XWikiDocument doc = mock(XWikiDocument.class); List<BaseObject> list = new ArrayList<BaseObject>(); LocalDocumentReference iconThemeClassRef = new LocalDocumentReference("IconThemesCode", "IconThemeClass"); when(doc.getXObjects(eq(iconThemeClassRef))).thenReturn(list); mocker.getComponentUnderTest().onEvent(null, doc, null); verify(iconSetCache, never()).clear(any(DocumentReference.class)); }