### Question:
FIFOAgendaScheduler implements AgendaScheduler { @Override public List<ReadyAgenda> schedule(int requestCount, Insight insight, InsightScheduleInfo insightScheduleInfo) { DataObjectFeed<ReadyAgenda> readyAgendaFeed; try { readyAgendaFeed = readyAgendaPersister.retrieve(Arrays.asList(new ByInsightId(insight.getId()))); } catch(PersistenceException e) { logger.error("Failed to retrieve ReadyAgendas for queue.", e); return null; } if(readyAgendaFeed.isError()) { logger.error("ReadyAgenda feed returned with an error.", readyAgendaFeed.getException()); return null; } List<ReadyAgenda> readyAgendas = readyAgendaFeed.getAll(); List<ReadyAgenda> scheduledReadyAgendas = new ArrayList<>(); if(readyAgendas.size() > 0) { scheduledReadyAgendas = readyAgendas.subList(0, Math.min(requestCount, readyAgendas.size())); } logger.info("FIFO Result -- InsightId: {} Scheduled: {} Requested: {}", insight.getId(), scheduledReadyAgendas.size(), requestCount); return scheduledReadyAgendas; } FIFOAgendaScheduler(ObjectPersister<ReadyAgenda> readyAgendaPersister); @Override List<ReadyAgenda> schedule(int requestCount, Insight insight, InsightScheduleInfo insightScheduleInfo);  }### Answer:
@Test public void testScheduleNoReadyAgendas() throws Throwable { doReturn(new DataObjectFeed<ReadyAgenda>()).when(mockReadyAgendaPersister).retrieve(anyList()); List<ReadyAgenda> readyAgendas = scheduler.schedule(1, insight, insightScheduleInfo); Assert.assertNotNull(readyAgendas); Assert.assertEquals(readyAgendas.size(), 0); }
@Test public void testScheduleOneReadyAgenda() throws Throwable { List<String> customerIds = IntStream.range(0, 5).mapToObj(i -> Integer.toString(i)).collect(Collectors.toList()); doReturn(createReadyAgendaFeed(customerIds, 1)).when(mockReadyAgendaPersister).retrieve(anyList()); List<ReadyAgenda> readyAgendas = scheduler.schedule(1, insight, insightScheduleInfo); Assert.assertNotNull(readyAgendas); Assert.assertEquals(readyAgendas.size(), 1); Assert.assertEquals(readyAgendas.get(0).getCustomerId(), customerIds.get(0)); }
@Test public void testScheduleExcessReadyAgendas() throws Throwable { List<String> customerIds = new ArrayList<>(); List<String> expectedIds = IntStream.range(0, 5).mapToObj(i -> Integer.toString(i)).collect(Collectors.toList()); customerIds.addAll(expectedIds); customerIds.addAll(IntStream.range(5, 10).mapToObj(i -> Integer.toString(i)).collect(Collectors.toList())); doReturn(createReadyAgendaFeed(customerIds, 1)).when(mockReadyAgendaPersister).retrieve(anyList()); List<ReadyAgenda> readyAgendas = scheduler.schedule(5, insight, insightScheduleInfo); Assert.assertNotNull(readyAgendas); Assert.assertEquals(readyAgendas.size(), 5); Assert.assertTrue( readyAgendas.stream().map(ReadyAgenda::getCustomerId).collect(Collectors.toList()) .containsAll(expectedIds) ); }