@Test public void anExceptionMeteredAnnotatedMethod_WithPublicScope_ButDifferentTypeOfException() throws Exception { final Metric metric = registry .allMetrics() .get(new MetricName(InstrumentedWithExceptionMetered.class, "failures")); assertMetricIsSetup(metric); assertThat("Metric intialises to zero", ((Meter) metric).count(), is(0L)); try { instance.errorProneMethod(new MyOtherException()); fail("Expected an exception to be thrown"); } catch (MyOtherException e) { } assertThat( "Metric should not be marked if the exception is a different type", ((Meter) metric).count(), is(0L)); }
@Test public void anExceptionMeteredAnnotatedMethod_WithPublicScope_AndSubclassesOfSpecifiedException() throws Exception { final Metric metric = registry .allMetrics() .get(new MetricName(InstrumentedWithExceptionMetered.class, "failures")); assertMetricIsSetup(metric); assertThat("Metric intialises to zero", ((Meter) metric).count(), is(0L)); try { instance.errorProneMethod(new MySpecialisedException()); fail("Expected an exception to be thrown"); } catch (MyException e) { } assertThat( "Metric should be marked when a subclass of the specified exception type is thrown", ((Meter) metric).count(), is(1L)); }