### Question:
QueueMonitor { public void processResourcePool(String resourcePoolId) throws Throwable { DataObjectResponse<Insight> insightObjectFeed = insightClient.getObjects(Collections.singletonList(new ByResourcePoolId(resourcePoolId))); if(insightObjectFeed.isError()) { logger.error("Error getting any insights by resourcePoolId: {}", resourcePoolId); return; } if(insightObjectFeed.getAll() == null || insightObjectFeed.getAll().size() == 0) { logger.info("No insights found for ResourcePool: {}", resourcePoolId); return; } for(Insight insight : insightObjectFeed.getAll()) { try { InsightScheduleInfo insightScheduleInfo = retrieveInsightSchedulingInfo(resourcePoolId, insight.getId()); processInsight(insight, insightScheduleInfo); insightScheduleInfo.setLastExecuted(new Date()); insightScheduleInfoPersister.persist(insightScheduleInfo); logger.info("Persisted update to InsightScheduleInfo: {}", insightScheduleInfo.getId()); } catch(Exception e) { logger.error("Failed to process ResourcePool: {} Insight: {}", resourcePoolId, insight.getId(), e); } } logger.info("Processed ResourcePool: {}", resourcePoolId); } QueueMonitor(
        ItemQueueFactory<ReadyAgenda> readyAgendaQueueFactory,
        ObjectPersister<ReadyAgenda> readyAgendaPersister,
        ObjectClient<Insight> insightClient,
        ObjectClient<Customer> customerClient,
        ObjectPersister<InsightScheduleInfo> insightScheduleInfoPersister); void processResourcePool(String resourcePoolId); void setAgendaSchedulerFactory(AgendaSchedulerFactory agendaSchedulerFactory);  }### Answer:
@Test(expectedExceptions = RuntimeException.class) public void testInsightClientError() throws Throwable { doThrow(new RuntimeException("a")).when(mockInsightClient).getObjects(anyList()); queueMonitor.processResourcePool(RESOURCE_POOL_ID); }
@Test public void testInsightClientNoResults() throws Throwable { doReturn(new DefaultDataObjectResponse<>()).when(mockInsightClient).getObjects(anyList()); queueMonitor.processResourcePool(RESOURCE_POOL_ID); verify(mockInsightSchedulingInfoPersister, times(0)).retrieve(anyString()); }
@Test public void testQueueSizeFailure() throws Throwable { doReturn(getInsightFeed(1)).when(mockInsightClient).getObjects(anyList()); doReturn(new QueueResult<>().setSuccessful(false)).when(mockReadyAgendaQueue).size(); queueMonitor.processResourcePool(RESOURCE_POOL_ID); verify(mockAgendaSchedulerFactory, times(0)).getAgendaScheduler(any(), any(), any()); }
@Test public void testQueueOkaySize() throws Throwable { doReturn(getInsightFeed(1)).when(mockInsightClient).getObjects(anyList()); doReturn(new QueueResult<>().setSuccessful(true).setMessage("0")).when(mockReadyAgendaQueue).size(); queueMonitor.processResourcePool(RESOURCE_POOL_ID); verify(mockAgendaSchedulerFactory, times(0)).getAgendaScheduler(any(), any(), any()); }
@Test public void testQueueUnderSize() throws Throwable { doReturn(mockAgendaScheduler).when(mockAgendaSchedulerFactory).getAgendaScheduler(any(), any(), any()); DataObjectResponse<Insight> insightDataObjectResponse = new DefaultDataObjectResponse<>(); Insight insight = new Insight(); insight.setQueueSize(1); insightDataObjectResponse.add(insight); doReturn(insightDataObjectResponse).when(mockInsightClient).getObjects(anyList()); doReturn(new QueueResult<>().setSuccessful(true).setMessage("0")).when(mockReadyAgendaQueue).size(); Collection<ReadyAgenda> results = Collections.singletonList(new ReadyAgenda()); doReturn(results).when(mockAgendaScheduler).schedule(anyInt(), any(Insight.class), any(InsightScheduleInfo.class)); queueMonitor.processResourcePool(RESOURCE_POOL_ID); verify(mockAgendaSchedulerFactory, times(1)).getAgendaScheduler(any(), any(), any()); verify(mockReadyAgendaPersister, times(1)).delete(anyString()); verify(mockReadyAgendaQueue, times(1)).add(any(ReadyAgenda.class)); }