Search in sources :

Example 11 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class EventsContainerTest method testItAddsEventsToExistingList.

@Test
public void testItAddsEventsToExistingList() {
    //Sun, 07 Jun 2015 18:20:51 GMT
    //get 30 events in total
    List<Event> events = getSingleEvents(0, 30, 1433701251000L);
    underTest.addEvents(events);
    //Sun, 07 Jun 2015 18:20:51 GMT
    List<Event> calendarDayEvents = underTest.getEventsFor(setTimeToMidnightAndGet(Calendar.getInstance(), 1433701251000L));
    //Assert 6th item since it will represent Sun, 07 Jun 2015 which is the day that we queried for
    assertEquals(events.get(6), calendarDayEvents.get(0));
    //add event in Sun, 07 Jun 2015 18:20:51 GMT for same day, making total 2 events for same day now
    Event extraEventAdded = new Event(Color.GREEN, 1433701251000L);
    underTest.addEvent(extraEventAdded);
    //Sun, 07 Jun 2015 18:20:51 GMT
    List<Event> calendarDayEvents2 = underTest.getEventsFor(setTimeToMidnightAndGet(Calendar.getInstance(), 1433701251000L));
    assertNotNull(calendarDayEvents2);
    //Assert 6th item since it will represent Sun, 07 Jun 2015 which is the day that we queried for
    assertEquals(2, calendarDayEvents2.size());
    assertEquals(events.get(6), calendarDayEvents2.get(0));
    assertEquals(extraEventAdded, calendarDayEvents2.get(1));
}
Also used : Event(com.github.sundeepk.compactcalendarview.domain.Event) Test(org.junit.Test)

Example 12 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class EventsContainerTest method testItGetsMultipleEventsThatWereAddedForADay.

@Test
public void testItGetsMultipleEventsThatWereAddedForADay() {
    //Add 3 events per a day for Feb starting from Sun, 01 Feb 2015 00:00:00 GMT
    Map<Long, List<Event>> events = getMultipleEventsForEachDayAsMap(0, 30, 1422748800000L);
    for (Map.Entry<Long, List<Event>> entry : events.entrySet()) {
        for (Event event : entry.getValue()) {
            underTest.addEvent(event);
        }
    }
    //if multiple events were added for every day, then check that all events are present by day
    for (Map.Entry<Long, List<Event>> entry : events.entrySet()) {
        List<Event> actualEvents = underTest.getEventsFor(entry.getKey());
        Assert.assertEquals(entry.getValue(), actualEvents);
    }
}
Also used : Event(com.github.sundeepk.compactcalendarview.domain.Event) ArrayList(java.util.ArrayList) List(java.util.List) CompactCalendarHelper.getMultipleEventsForEachDayAsMap(com.github.sundeepk.compactcalendarview.CompactCalendarHelper.getMultipleEventsForEachDayAsMap) Map(java.util.Map) Test(org.junit.Test)

Example 13 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class EventsContainerTest method testItRemovesEventByDate.

@Test
public void testItRemovesEventByDate() {
    //Sun, 07 Jun 2015 18:20:51 GMT
    //get 30 events in total
    List<Event> events = getSingleEvents(0, 30, 1433701251000L);
    for (Event event : events) {
        underTest.addEvent(event);
    }
    assertEquals(1, underTest.getEventsFor(setTimeToMidnightAndGet(Calendar.getInstance(), 1433701251000L)).size());
    assertEquals(events.get(6), underTest.getEventsFor(setTimeToMidnightAndGet(Calendar.getInstance(), 1433701251000L)).get(0));
    //Sun, 07 Jun 2015 18:20:51 GMT
    underTest.removeEventByEpochMillis(setTimeToMidnightAndGet(Calendar.getInstance(), 1433701251000L));
    //Remove 6th item since it will represent Sun, 07 Jun 2015 which is the day that was removed
    events.remove(6);
    assertEquals(0, underTest.getEventsFor(setTimeToMidnightAndGet(Calendar.getInstance(), 1433701251000L)).size());
}
Also used : Event(com.github.sundeepk.compactcalendarview.domain.Event) Test(org.junit.Test)

Example 14 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class EventsContainerTest method testItRemovesEventsUsingList.

@Test
public void testItRemovesEventsUsingList() {
    //Sun, 01 Feb 2015 00:00:00 GMT
    List<Event> events = getSingleEvents(0, 30, 1422748800000L);
    for (Event event : events) {
        underTest.addEvent(event);
    }
    underTest.removeEvents(Arrays.asList(events.get(0), events.get(1), events.get(5), events.get(20)));
    List<Event> expectedEvents = getSingleEvents(0, 28, 1422748800000L);
    expectedEvents.removeAll(Arrays.asList(events.get(0), events.get(1), events.get(5), events.get(20)));
    for (Event e : expectedEvents) {
        List<Event> actualEvents = underTest.getEventsFor(e.getTimeInMillis());
        Assert.assertEquals(1, actualEvents.size());
        Assert.assertEquals(e, actualEvents.get(0));
    }
}
Also used : Event(com.github.sundeepk.compactcalendarview.domain.Event) Test(org.junit.Test)

Example 15 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class EventsContainerTest method testItRemovesAllEvents.

@Test
public void testItRemovesAllEvents() {
    //Sun, 01 Feb 2015 00:00:00 GMT
    List<Event> events = getSingleEvents(0, 30, 1422748800000L);
    for (Event event : events) {
        underTest.addEvent(event);
    }
    underTest.removeAllEvents();
    List<Event> actualEvents = underTest.getEventsFor(1422748800000L);
    Assert.assertEquals(new ArrayList<Event>(), actualEvents);
}
Also used : Event(com.github.sundeepk.compactcalendarview.domain.Event) Test(org.junit.Test)

Aggregations

Event (com.github.sundeepk.compactcalendarview.domain.Event)23 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)8 MotionEvent (android.view.MotionEvent)5 Calendar (java.util.Calendar)5 Date (java.util.Date)3 List (java.util.List)3 Paint (android.graphics.Paint)2 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 CompactCalendarHelper.getMultipleEventsForEachDayAsMap (com.github.sundeepk.compactcalendarview.CompactCalendarHelper.getMultipleEventsForEachDayAsMap)1 CompactCalendarView (com.github.sundeepk.compactcalendarview.CompactCalendarView)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Random (java.util.Random)1 TimeZone (java.util.TimeZone)1