### Question:
FilteringMetricsScope extends AccumulateByNameMetricsScope { @Override public void addDimension(String name, String value) { if (!metricsEnabledDimensionsAll && (metricsEnabledDimensions == null || !metricsEnabledDimensions.contains(name))) { return; } super.addDimension(name, value); } FilteringMetricsScope();  FilteringMetricsScope(MetricsLevel metricsLevel, Set<String> metricsEnabledDimensions); @Override void addData(String name, double value, StandardUnit unit); @Override void addData(String name, double value, StandardUnit unit, MetricsLevel level); @Override void addDimension(String name, String value);  }### Answer:
@Test public void testMetricsDimensions() { TestScope scope = new TestScope(MetricsLevel.DETAILED, ImmutableSet.of("ShardId")); scope.addDimension("ShardId", "shard-0001"); scope.addDimension("Operation", "ProcessRecords"); scope.addDimension("ShardId", "shard-0001"); scope.addDimension("ShardId", "shard-0002"); scope.addDimension("WorkerIdentifier", "testworker"); scope.assertDimensions( TestHelper.constructDimension("ShardId", "shard-0001"), TestHelper.constructDimension("ShardId", "shard-0002")); }
@Test public void testMetricsDimensionsAll() { TestScope scope = new TestScope(MetricsLevel.DETAILED, ImmutableSet.of( "ThisDoesNotMatter", MetricsScope.METRICS_DIMENSIONS_ALL, "ThisAlsoDoesNotMatter")); scope.addDimension("ShardId", "shard-0001"); scope.addDimension("Operation", "ProcessRecords"); scope.addDimension("ShardId", "shard-0001"); scope.addDimension("ShardId", "shard-0002"); scope.addDimension("WorkerIdentifier", "testworker"); scope.assertDimensions( TestHelper.constructDimension("ShardId", "shard-0001"), TestHelper.constructDimension("ShardId", "shard-0002"), TestHelper.constructDimension("Operation", "ProcessRecords"), TestHelper.constructDimension("WorkerIdentifier", "testworker")); }