@Test public void testGetAllEvents() throws XWikiException { ArrayList<EventApi> eventList = new ArrayList<EventApi>(); IEvent event = createMock(IEvent.class); event.setLanguage(eq("de")); expectLastCall().once(); IEvent event2 = createMock(IEvent.class); event2.setLanguage(eq("de")); expectLastCall().once(); IEvent event3 = createMock(IEvent.class); event3.setLanguage(eq("de")); expectLastCall().once(); IEvent event4 = createMock(IEvent.class); event4.setLanguage(eq("de")); expectLastCall().once(); DocumentReference cal2DocRef = new DocumentReference(context.getDatabase(), "MyCalDoc2Space", "MyCal2Doc"); Calendar cal2 = new Calendar(cal2DocRef, isArchiv); cal2.setCalendarUtils(calUtils); cal2.inject_getEventCmd(eventMgrMock); expect(eventMgrMock.getEvents(same(cal2), eq(0), eq(0))).andReturn(eventList); replayAll(event, event2, event3, event4); eventList.add(new EventApi(event, context)); eventList.add(new EventApi(event2, context)); eventList.add(new EventApi(event3, context)); eventList.add(new EventApi(event4, context)); List<EventApi> events = cal2.getAllEvents(); verifyAll(event, event2, event3, event4); assertEquals("expecting complete eventList", eventList, events); }
@Test public void testGetAllEvents_informationHidingSecurity() throws XWikiException { List<EventApi> list = Collections.emptyList(); expect(eventMgrMock.getEvents(same(cal), eq(0), eq(0))).andReturn(list).once(); replayAll(); List<EventApi> events = cal.getAllEvents(); verifyAll(); assertNotSame("getAllEvents may not leak internal data references.", eventList, events); }
@Test public void testGetEvents_illegalStartValue() throws XWikiException { ArrayList<EventApi> eventList = new ArrayList<EventApi>(); IEvent event = createMock(IEvent.class); event.setLanguage(eq("de")); expectLastCall().once(); DocumentReference cal2DocRef = new DocumentReference(context.getDatabase(), "MyCalDoc2Space", "MyCal2Doc"); Calendar cal2 = new Calendar(cal2DocRef, isArchiv); cal2.setCalendarUtils(calUtils); cal2.inject_getEventCmd(eventMgrMock); expect(eventMgrMock.getEvents(same(cal2), eq(5), eq(1))).andReturn(eventList); replayAll(event); eventList.add(new EventApi(event, context)); int start = 5; int nb = 1; List<EventApi> events = cal2.getEvents(start, nb); verifyAll(event); assertEquals("Expecting to get the full eventlist", eventList, events); }