@Test
public void testGetEvents() throws Exception {

  // We create 4 events:
  // - Event no. 1 ends way before the interval we query for                -> no hit
  // - Event no. 2 starts before the interval and ends within the interval  -> hit
  // - Event no. 3 starts and ends within the interval                      -> hit
  // - Event no. 4 starts exactly when the interval ends                    -> hit because separationMillis > 0
  final long oneHourMillis = 3600_000;
  final long nowMillis = new Date().getTime();
  final String mpId = "mpId";
  final String agentId = "agent1";
  final String orgId = new DefaultOrganization().getId();
  final Date intervalStart = new Date(nowMillis);
  final Date intervalEnd = new Date(nowMillis + 5 * oneHourMillis);
  final Date[] eventStartDates = {
      new Date(nowMillis - 4 * oneHourMillis),
      new Date(nowMillis - oneHourMillis),
      new Date(nowMillis + oneHourMillis),
      new Date(intervalEnd.getTime()),
  };
  for (int i = 0; i < 4; i++) {
    final Date start = eventStartDates[i];
    final Date end = new Date(start.getTime() + 2 * oneHourMillis);
    schedulerDatabase.storeEvent(
        mpId + i,
        orgId,
        Opt.some(agentId),
        Opt.some(start),
        Opt.some(end),
        Opt.none(),
        Opt.none(),
        Opt.none(),
        Opt.none(),
        Opt.none(),
        Opt.none(),
        Opt.none(),
        Opt.none()
    );
  }
  final int separationMillis = 60 * 1000;
  final List<String> eventIds = schedulerDatabase.getEvents(agentId, intervalStart, intervalEnd, separationMillis);
  Assert.assertEquals(3, eventIds.size());
  Assert.assertFalse(eventIds.contains(mpId + 0));
  Assert.assertTrue(eventIds.contains(mpId + 1));
  Assert.assertTrue(eventIds.contains(mpId + 2));
  Assert.assertTrue(eventIds.contains(mpId + 3));
}