### Question:
AllowListMetricFilter extends SimpleRegexMetricFilter { @Override public boolean isAllowed(Metric metric) { return allowList.stream() .anyMatch(filter -> super.filterMatches(filter, metric)); } AllowListMetricFilter(List<String> allowList); @Override boolean isAllowed(Metric metric); @Override String toString();  }### Answer:
@Test public void testAllowAll() { List<String> allowList = Lists.newArrayList(); allowList.add("*"); AllowListMetricFilter filter = new AllowListMetricFilter(allowList); Assert.assertTrue(filter.isAllowed(metric("metric.name"))); }
@Test public void testAllowListWithValidItems() { List<String> allowList = Lists.newArrayList(); allowList.add("good.metric"); allowList.add("better.metric"); AllowListMetricFilter filter = new AllowListMetricFilter(allowList); Assert.assertTrue(filter.isAllowed(metric("good.metric"))); Assert.assertTrue(filter.isAllowed(metric("better.metric"))); Assert.assertFalse(filter.isAllowed(metric("bad.metric"))); }
@Test public void testCaseInsensitive() { List<String> allowList = Lists.newArrayList(); allowList.add("GooD"); AllowListMetricFilter filter = new AllowListMetricFilter(allowList); Assert.assertTrue(filter.isAllowed(metric("good"))); Assert.assertTrue(filter.isAllowed(metric("gOOd"))); Assert.assertTrue(filter.isAllowed(metric("gOOD"))); Assert.assertFalse(filter.isAllowed(metric("bad"))); }
@Test public void testEmptyAllowList() { List<String> allowList = Lists.newArrayList(); AllowListMetricFilter filter = new AllowListMetricFilter(allowList); Assert.assertFalse(filter.isAllowed(metric("metric.name"))); Assert.assertFalse(filter.isAllowed(metric("other.metric.name"))); }
@Test public void testBlankItem() { List<String> allowList = Lists.newArrayList(); allowList.add("metric.name"); allowList.add(""); allowList.add(" "); AllowListMetricFilter filter = new AllowListMetricFilter(allowList); Assert.assertTrue(filter.isAllowed(metric("metric.name"))); }
@Test public void testItemWithEndingRegex() { List<String> allowList = Lists.newArrayList(); allowList.add("pcs.*"); AllowListMetricFilter filter = new AllowListMetricFilter(allowList); Assert.assertTrue(filter.isAllowed(metric("pcs.metric1"))); Assert.assertFalse(filter.isAllowed(metric("other.metric"))); Assert.assertFalse(filter.isAllowed(metric("other.metric.pcs"))); }
@Test public void testItemWithStartAndEndRegex() { List<String> allowList = Lists.newArrayList(); allowList.add("*pcs*"); AllowListMetricFilter filter = new AllowListMetricFilter(allowList); Assert.assertTrue(filter.isAllowed(metric("some.pcs.metric"))); Assert.assertTrue(filter.isAllowed(metric("pcs.metric"))); Assert.assertTrue(filter.isAllowed(metric("metric.pcs"))); Assert.assertFalse(filter.isAllowed(metric("other.metric"))); }