### Question:
SkinListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; List<BaseObject> skinObjects = document.getXObjects(SKIN_CLASS); if (skinObjects != null && !skinObjects.isEmpty()) { clearCacheFromSkin(document); return; } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data);  }### Answer:
@Test public void onEventWhenSkinIsChanged() throws Exception { Event event = mock(Event.class); XWikiDocument doc = mock(XWikiDocument.class); Object data = new Object(); EntityReference classReference = new LocalDocumentReference("XWiki", "XWikiSkins"); List<BaseObject> objects = new ArrayList<>(); BaseObject object = mock(BaseObject.class); objects.add(object); when(doc.getXObjects(classReference)).thenReturn(objects); DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); when(doc.getDocumentReference()).thenReturn(documentReference); DocumentSkinReference skinReference = new DocumentSkinReference(documentReference, null); when(skinReferenceFactory.createReference(documentReference)).thenReturn(skinReference); mocker.getComponentUnderTest().onEvent(event, doc, data); verify(lessResourcesCache).clearFromSkin(skinReference); verify(colorThemeCache).clearFromSkin(skinReference); }
@Test public void onEventWhenNoObject() throws Exception { Event event = mock(Event.class); XWikiDocument doc = mock(XWikiDocument.class); Object data = new Object(); EntityReference classReference = new LocalDocumentReference("XWiki", "XWikiSkins"); List<BaseObject> objects = new ArrayList<>(); when(doc.getXObjects(classReference)).thenReturn(objects); mocker.getComponentUnderTest().onEvent(event, doc, data); verifyZeroInteractions(lessResourcesCache); verifyZeroInteractions(colorThemeCache); }