### Question:
PrototypeMeasurementFilter implements Predicate<Measurement> { public IncludeExcludePatterns metricToPatterns(String metric) { IncludeExcludePatterns foundPatterns = metricNameToPatterns.get(metric); if (foundPatterns != null) { return foundPatterns; } foundPatterns = new IncludeExcludePatterns(); for (MeterFilterPattern meterPattern : includePatterns) { if (meterPattern.namePattern.matcher(metric).matches()) { foundPatterns.include.addAll(meterPattern.values); } } for (MeterFilterPattern meterPattern : excludePatterns) { if (meterPattern.namePattern.matcher(metric).matches()) { foundPatterns.exclude.addAll(meterPattern.values); } } metricNameToPatterns.put(metric, foundPatterns); return foundPatterns; } PrototypeMeasurementFilter(PrototypeMeasurementFilterSpecification specification); @SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation") @Override boolean test(Measurement measurement); IncludeExcludePatterns metricToPatterns(String metric); static PrototypeMeasurementFilter loadFromPath(String path);  }### Answer:
@Test public void testMetricToPatterns() { PrototypeMeasurementFilterSpecification spec = new PrototypeMeasurementFilterSpecification(); spec.getInclude().put("meterA", meterSpecA); spec.getInclude().put(".+B", meterSpecB); spec.getInclude().put(".+C.*", meterSpecC); PrototypeMeasurementFilter filter = new PrototypeMeasurementFilter(spec); PrototypeMeasurementFilter.MeterFilterPattern meterPatternA = new PrototypeMeasurementFilter.MeterFilterPattern("meterA", meterSpecA); PrototypeMeasurementFilter.MeterFilterPattern meterPatternC = new PrototypeMeasurementFilter.MeterFilterPattern(".+C.*", meterSpecC); final List<PrototypeMeasurementFilter.ValueFilterPattern> emptyList = new ArrayList<>(); Assertions.assertEquals( filter.metricToPatterns("meterA"), new PrototypeMeasurementFilter.IncludeExcludePatterns( meterPatternA.getValues(), emptyList)); Assertions.assertEquals( filter.metricToPatterns("meterBextra"), new PrototypeMeasurementFilter.IncludeExcludePatterns( emptyList, emptyList)); Assertions.assertEquals( filter.metricToPatterns("meterCthing"), new PrototypeMeasurementFilter.IncludeExcludePatterns( meterPatternC.getValues(), emptyList)); }
@Test public void testMetricToPatternsWithMultipleMeters() { PrototypeMeasurementFilterSpecification spec = new PrototypeMeasurementFilterSpecification(); spec.getInclude().put("meterA", meterSpecA); spec.getInclude().put("meter.+", meterSpecB); PrototypeMeasurementFilter filter = new PrototypeMeasurementFilter(spec); PrototypeMeasurementFilter.MeterFilterPattern meterPatternA = new PrototypeMeasurementFilter.MeterFilterPattern("ignored", meterSpecA); PrototypeMeasurementFilter.MeterFilterPattern meterPatternB = new PrototypeMeasurementFilter.MeterFilterPattern("ignored", meterSpecB); final List<PrototypeMeasurementFilter.ValueFilterPattern> emptyList = new ArrayList<>(); Assertions.assertEquals( filter.metricToPatterns("meterB"), new PrototypeMeasurementFilter.IncludeExcludePatterns( meterPatternB.getValues(), emptyList)); List<PrototypeMeasurementFilter.ValueFilterPattern> expect = new ArrayList<>(); expect.addAll(meterPatternA.getValues()); expect.addAll(meterPatternB.getValues()); PrototypeMeasurementFilter.IncludeExcludePatterns patterns = filter.metricToPatterns("meterA"); Assertions.assertEquals(new HashSet<>(expect), new HashSet<>(patterns.getInclude())); }