### Question:
AbstractMetricsHandler extends
	AbstractRestHandler<RestfulGateway, EmptyRequestBody, MetricCollectionResponseBody, M> { @Override protected final CompletableFuture<MetricCollectionResponseBody> handleRequest( @Nonnull HandlerRequest<EmptyRequestBody, M> request, @Nonnull RestfulGateway gateway) throws RestHandlerException { metricFetcher.update(); final MetricStore.ComponentMetricStore componentMetricStore = getComponentMetricStore( request, metricFetcher.getMetricStore()); if (componentMetricStore == null || componentMetricStore.metrics == null) { return CompletableFuture.completedFuture( new MetricCollectionResponseBody(Collections.emptyList())); } final Set<String> requestedMetrics = new HashSet<>(request.getQueryParameter( MetricsFilterParameter.class)); if (requestedMetrics.isEmpty()) { return CompletableFuture.completedFuture( new MetricCollectionResponseBody(getAvailableMetrics(componentMetricStore))); } else { final List<Metric> metrics = getRequestedMetrics(componentMetricStore, requestedMetrics); return CompletableFuture.completedFuture(new MetricCollectionResponseBody(metrics)); } } AbstractMetricsHandler(
			CompletableFuture<String> localRestAddress,
			GatewayRetriever<? extends RestfulGateway> leaderRetriever,
			Time timeout,
			Map<String, String> headers,
			MessageHeaders<EmptyRequestBody, MetricCollectionResponseBody, M> messageHeaders,
			MetricFetcher metricFetcher);   }### Answer:
@Test public void testListMetrics() throws Exception { final CompletableFuture<MetricCollectionResponseBody> completableFuture = testMetricsHandler.handleRequest( new HandlerRequest<>( EmptyRequestBody.getInstance(), new TestMessageParameters(), Collections.emptyMap(), Collections.emptyMap()), mockDispatcherGateway); assertTrue(completableFuture.isDone()); final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get(); assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1)); final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next(); assertThat(metric.getId(), equalTo(TEST_METRIC_NAME)); assertThat(metric.getValue(), equalTo(null)); }
@Test public void testReturnEmptyListIfNoComponentMetricStore() throws Exception { testMetricsHandler.returnComponentMetricStore = false; final CompletableFuture<MetricCollectionResponseBody> completableFuture = testMetricsHandler.handleRequest( new HandlerRequest<>( EmptyRequestBody.getInstance(), new TestMessageParameters(), Collections.emptyMap(), Collections.emptyMap()), mockDispatcherGateway); assertTrue(completableFuture.isDone()); final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get(); assertThat(metricCollectionResponseBody.getMetrics(), empty()); }
@Test public void testGetMetrics() throws Exception { final CompletableFuture<MetricCollectionResponseBody> completableFuture = testMetricsHandler.handleRequest( new HandlerRequest<>( EmptyRequestBody.getInstance(), new TestMessageParameters(), Collections.emptyMap(), Collections.singletonMap(METRICS_FILTER_QUERY_PARAM, Collections.singletonList(TEST_METRIC_NAME))), mockDispatcherGateway); assertTrue(completableFuture.isDone()); final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get(); assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1)); final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next(); assertThat(metric.getId(), equalTo(TEST_METRIC_NAME)); assertThat(metric.getValue(), equalTo(Integer.toString(TEST_METRIC_VALUE))); }
@Test public void testReturnEmptyListIfRequestedMetricIsUnknown() throws Exception { final CompletableFuture<MetricCollectionResponseBody> completableFuture = testMetricsHandler.handleRequest( new HandlerRequest<>( EmptyRequestBody.getInstance(), new TestMessageParameters(), Collections.emptyMap(), Collections.singletonMap(METRICS_FILTER_QUERY_PARAM, Collections.singletonList("unknown_metric"))), mockDispatcherGateway); assertTrue(completableFuture.isDone()); final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get(); assertThat(metricCollectionResponseBody.getMetrics(), empty()); }