### Question:
QueueMetricMonitor { public void monitor(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); reportFailed("resourcePool"); return; } if(insightObjectFeed.getAll() == null || insightObjectFeed.getAll().size() == 0) { logger.info("No insights found for ResourcePool: {}", resourcePoolId); return; } for(Insight insight : insightObjectFeed.getAll()) { String insightTitle = getReportSafeInsightTitle(insight); try { DataObjectFeed feed = readyAgendaPersister.retrieve(Arrays.asList(new ByInsightId(insight.getId()))); Integer waitingAgendaCount = feed.getAll() != null ? feed.getAll().size() : 0; if(waitingAgendaCount != null && waitingAgendaCount > 0) reportWaiting(insightTitle, waitingAgendaCount); logger.info("Insight: {} Waiting: {}", insightTitle, waitingAgendaCount); } catch(Exception e) { logger.error("Failed to process ResourcePool: {} Insight: {}", resourcePoolId, insightTitle, e); reportFailed(insightTitle); } } logger.info("Processed ResourcePool: {}", resourcePoolId); } QueueMetricMonitor(
        ObjectPersister<ReadyAgenda> readyAgendaPersister,
        ObjectClient<Insight> insightClient,
        MetricReporter metricReporter); void monitor(String resourcePoolId); void setMetricReporter(MetricReporter metricReporter);  }### Answer:
@Test(expectedExceptions = RuntimeException.class) public void testInsightClientError() throws Throwable { doThrow(new RuntimeException("a")).when(mockInsightClient).getObjects(anyList()); queueMonitor.monitor(RESOURCE_POOL_ID); }
@Test public void testInsightClientNoResults() throws Throwable { doReturn(new DefaultDataObjectResponse<>()).when(mockInsightClient).getObjects(anyList()); queueMonitor.monitor(RESOURCE_POOL_ID); verify(mockInsightClient, times(0)).getObject(anyString()); }
@Test public void testQueueSizeFailure() throws Throwable { doReturn(getInsightFeed(1)).when(mockInsightClient).getObjects(anyList()); doReturn(new QueueResult<>().setSuccessful(false)).when(mockReadyAgendaQueue).size(); queueMonitor.monitor(RESOURCE_POOL_ID); }
@Test public void testQueueOkaySize() throws Throwable { doReturn(getInsightFeed(1)).when(mockInsightClient).getObjects(anyList()); doReturn(new QueueResult<>().setSuccessful(true).setMessage("0")).when(mockReadyAgendaQueue).size(); queueMonitor.monitor(RESOURCE_POOL_ID); }
@Test public void testQueueUnderSize() throws Throwable { DataObjectResponse<Insight> insightDataObjectResponse = new DefaultDataObjectResponse<>(); Insight insight = new Insight(); insight.setQueueSize(1); insight.setId("myID"); 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()); queueMonitor.monitor(RESOURCE_POOL_ID); verify(mockReadyAgendaPersister, times(1)).retrieve(anyList()); }