@Test public void andTest() { MetricFilter trueMetricFilter = mock(MetricFilter.class); when(trueMetricFilter.matches(any(String.class), any(Metric.class))).thenReturn(true); MetricFilter falseMetricFilter = mock(MetricFilter.class); when(falseMetricFilter.matches(any(String.class), any(Metric.class))).thenReturn(false); Assert.assertTrue(MetricFilters.and(trueMetricFilter, trueMetricFilter).matches("", mock(Metric.class))); Assert.assertFalse(MetricFilters.and(trueMetricFilter, falseMetricFilter).matches("", mock(Metric.class))); Assert.assertFalse(MetricFilters.and(falseMetricFilter, trueMetricFilter).matches("", mock(Metric.class))); Assert.assertFalse(MetricFilters.and(falseMetricFilter, falseMetricFilter).matches("", mock(Metric.class))); }
public static MetricFilter and(final MetricFilter metricFilter1, final MetricFilter metricFilter2) { return new MetricFilter() { @Override public boolean matches(String name, Metric metric) { return metricFilter1.matches(name, metric) && metricFilter2.matches(name, metric); } }; }
MetricFilters { public static MetricFilter and(final MetricFilter metricFilter1, final MetricFilter metricFilter2) { return new MetricFilter() { @Override public boolean matches(String name, Metric metric) { return metricFilter1.matches(name, metric) && metricFilter2.matches(name, metric); } }; } }
MetricFilters { public static MetricFilter and(final MetricFilter metricFilter1, final MetricFilter metricFilter2) { return new MetricFilter() { @Override public boolean matches(String name, Metric metric) { return metricFilter1.matches(name, metric) && metricFilter2.matches(name, metric); } }; }  }
MetricFilters { public static MetricFilter and(final MetricFilter metricFilter1, final MetricFilter metricFilter2) { return new MetricFilter() { @Override public boolean matches(String name, Metric metric) { return metricFilter1.matches(name, metric) && metricFilter2.matches(name, metric); } }; }  static MetricFilter and(final MetricFilter metricFilter1, final MetricFilter metricFilter2); }
MetricFilters { public static MetricFilter and(final MetricFilter metricFilter1, final MetricFilter metricFilter2) { return new MetricFilter() { @Override public boolean matches(String name, Metric metric) { return metricFilter1.matches(name, metric) && metricFilter2.matches(name, metric); } }; }  static MetricFilter and(final MetricFilter metricFilter1, final MetricFilter metricFilter2);  }