@Test
public void testGetUpcomingRecording() throws Exception {

  final long nowMillis = System.currentTimeMillis();
  final long oneHourMillis = 3600_000;
  final String captureAgentId = "Device A";
  final Set<String> userIds = Collections.emptySet();
  final Map<String, String> wfProperties = this.wfProperties;
  final Map<String, String> caProperties = Collections.singletonMap("foo", "bar");
  final Opt<String> schedulingSource = Opt.none();
  final String id = "Recording";
  // We add 3 recordings here. One is in the past, one is current, one is in the future.
  // start = now - 4h, end = now - 2h              0
  // start = now - 1h, end = now + 1h              1
  // start = now + 2h, end = now + 4h              2
  for (int i = 0; i < 3; i++) {
    final long offset = i * 3 * oneHourMillis;
    final Date start = new Date(nowMillis - 4 * oneHourMillis + offset);
    final Date end = new Date(nowMillis - 2 * oneHourMillis  + offset);
    final MediaPackage mp = generateEvent(Opt.some(id + i));
    final DublinCoreCatalog dublinCoreCatalog = generateEvent(captureAgentId, Opt.some(mp.getIdentifier().toString()), Opt.some("Test Title" + i), start, end);
    addDublinCore(Opt.some(mp.getIdentifier().toString()), mp, dublinCoreCatalog);
    schedSvc.addEvent(
        start,
        end,
        captureAgentId,
        userIds,
        mp,
        wfProperties,
        caProperties,
        schedulingSource
    );
  }
  // We expect the third of the three recordings to be the upcoming one
  final Opt<MediaPackage> currentRecording = schedSvc.getUpcomingRecording(captureAgentId);
  assertTrue(currentRecording.isSome());
  final TechnicalMetadata technicalMetadata = schedSvc.getTechnicalMetadata(currentRecording.get().getIdentifier().toString());
  assertEquals(id + 2, currentRecording.get().getIdentifier().toString());
  assertEquals(nowMillis + 2 * oneHourMillis, technicalMetadata.getStartDate().getTime());
  assertEquals(nowMillis + 4 * oneHourMillis, technicalMetadata.getEndDate().getTime());
}