### Question:
MetricUtils { protected static boolean applyMetricConstraints(ConstraintEvaluator evaluator, Metric metric, String statistic) { if (!evaluator.apply(NAMESPACE_FIELD, metric.getNamespace())) { return false; } if (!evaluator.apply(METRIC_NAME_FIELD, metric.getMetricName())) { return false; } if (statistic != null && !evaluator.apply(STATISTIC_FIELD, statistic)) { return false; } for (Dimension next : metric.getDimensions()) { if (evaluator.apply(DIMENSION_NAME_FIELD, next.getName()) && evaluator.apply(DIMENSION_VALUE_FIELD, next.getValue())) { return true; } } if (metric.getDimensions().isEmpty() && evaluator.apply(DIMENSION_NAME_FIELD, null) && evaluator.apply(DIMENSION_VALUE_FIELD, null)) { return true; } return false; } private  MetricUtils();   }### Answer:
@Test public void applyMetricConstraints() { Schema schema = SchemaBuilder.newBuilder() .addStringField(NAMESPACE_FIELD) .addStringField(METRIC_NAME_FIELD) .addStringField(STATISTIC_FIELD) .addStringField(DIMENSION_NAME_FIELD) .addStringField(DIMENSION_VALUE_FIELD) .build(); Map<String, ValueSet> constraintsMap = new HashMap<>(); constraintsMap.put(NAMESPACE_FIELD, makeStringEquals(allocator, "match1")); constraintsMap.put(METRIC_NAME_FIELD, makeStringEquals(allocator, "match2")); constraintsMap.put(STATISTIC_FIELD, makeStringEquals(allocator, "match3")); constraintsMap.put(DIMENSION_NAME_FIELD, makeStringEquals(allocator, "match4")); constraintsMap.put(DIMENSION_VALUE_FIELD, makeStringEquals(allocator, "match5")); ConstraintEvaluator constraintEvaluator = new ConstraintEvaluator(allocator, schema, new Constraints(constraintsMap)); Metric metric = new Metric() .withNamespace("match1") .withMetricName("match2") .withDimensions(new Dimension().withName("match4").withValue("match5")); String statistic = "match3"; assertTrue(MetricUtils.applyMetricConstraints(constraintEvaluator, metric, statistic)); assertFalse(MetricUtils.applyMetricConstraints(constraintEvaluator, copyMetric(metric).withNamespace("no_match"), statistic)); assertFalse(MetricUtils.applyMetricConstraints(constraintEvaluator, copyMetric(metric).withMetricName("no_match"), statistic)); assertFalse(MetricUtils.applyMetricConstraints(constraintEvaluator, copyMetric(metric).withDimensions(Collections.singletonList(new Dimension().withName("no_match").withValue("match5"))), statistic)); assertFalse(MetricUtils.applyMetricConstraints(constraintEvaluator, copyMetric(metric).withDimensions(Collections.singletonList(new Dimension().withName("match4").withValue("no_match"))), statistic)); assertFalse(MetricUtils.applyMetricConstraints(constraintEvaluator, copyMetric(metric), "no_match")); }