### Question:
ColorThemeListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; List<BaseObject> flamingoThemeObjects = document.getXObjects(FLAMINGO_THEME_CLASS); if (flamingoThemeObjects != null && !flamingoThemeObjects.isEmpty()) { clearCacheFromColorTheme(document); return; } List<BaseObject> colorThemeObjects = document.getXObjects(COLOR_THEME_CLASS); if (colorThemeObjects != null && !colorThemeObjects.isEmpty()) { clearCacheFromColorTheme(document); return; } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data);  }### Answer:
@Test public void onEventWhenFlamingoThemeChanged() throws Exception { Event event = mock(Event.class); XWikiDocument doc = mock(XWikiDocument.class); Object data = new Object(); EntityReference classReference = new LocalDocumentReference("FlamingoThemesCode", "ThemeClass"); 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); ColorThemeReference colorThemeReference = new DocumentColorThemeReference(documentReference, null); when(colorThemeReferenceFactory.createReference(eq(documentReference))).thenReturn(colorThemeReference); mocker.getComponentUnderTest().onEvent(event, doc, data); verify(lessResourcesCache).clearFromColorTheme(colorThemeReference); verify(colorThemeCache).clearFromColorTheme(colorThemeReference); }
@Test public void onEventWhenColorThemeChanged() throws Exception { Event event = mock(Event.class); XWikiDocument doc = mock(XWikiDocument.class); Object data = new Object(); EntityReference classReference = new LocalDocumentReference("ColorThemes", "ColorThemeClass"); 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); ColorThemeReference colorThemeReference = new DocumentColorThemeReference(documentReference, null); when(colorThemeReferenceFactory.createReference(eq(documentReference))).thenReturn(colorThemeReference); mocker.getComponentUnderTest().onEvent(event, doc, data); verify(lessResourcesCache).clearFromColorTheme(colorThemeReference); verify(colorThemeCache).clearFromColorTheme(colorThemeReference); }
@Test public void onEventWhenNoObject() throws Exception { Event event = mock(Event.class); XWikiDocument doc = mock(XWikiDocument.class); Object data = new Object(); EntityReference classReference = new EntityReference("ColorThemeClass", EntityType.DOCUMENT, new EntityReference("ColorThemes", EntityType.SPACE)); List<BaseObject> objects = new ArrayList<>(); when(doc.getXObjects(classReference)).thenReturn(objects); mocker.getComponentUnderTest().onEvent(event, doc, data); verifyZeroInteractions(lessResourcesCache); verifyZeroInteractions(colorThemeCache); }