### Question:
ExceptionMeteredMethodBean { @ExceptionMetered(name = "illegalArgumentExceptionMeteredMethod", cause = IllegalArgumentException.class) public void illegalArgumentExceptionMeteredMethod(Runnable runnable) { runnable.run(); }  @ExceptionMetered(name = "illegalArgumentExceptionMeteredMethod", cause = IllegalArgumentException.class) void illegalArgumentExceptionMeteredMethod(Runnable runnable); @ExceptionMetered(name = "exceptionMeteredMethod", cause = Exception.class) void exceptionMeteredMethod(Runnable runnable);  }### Answer:
@Test @InSequence(2) public void callExceptionMeteredMethodOnceWithThrowingExpectedException() { assertThat("Meters are not registered correctly", registry.getMeters().keySet(), is(equalTo(absoluteMetricNames()))); final RuntimeException exception = new IllegalArgumentException("message"); Runnable runnableThatThrowsIllegalArgumentException = new Runnable() { @Override public void run() { throw exception; } }; try { bean.illegalArgumentExceptionMeteredMethod(runnableThatThrowsIllegalArgumentException); fail("No exception has been re-thrown!"); } catch (RuntimeException cause) { assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(0)).getCount(), is(equalTo(METER_COUNTS[0].incrementAndGet()))); assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(1)).getCount(), is(equalTo(METER_COUNTS[1].get()))); assertSame("Exception thrown is incorrect", cause, exception); } }
@Test @InSequence(3) public void callExceptionMeteredMethodOnceWithThrowingNonExpectedException() { assertThat("Meters are not registered correctly", registry.getMeters().keySet(), is(equalTo(absoluteMetricNames()))); final RuntimeException exception = new IllegalStateException("message"); Runnable runnableThatThrowsIllegalStateException = new Runnable() { @Override public void run() { throw exception; } }; try { bean.illegalArgumentExceptionMeteredMethod(runnableThatThrowsIllegalStateException); fail("No exception has been re-thrown!"); } catch (RuntimeException cause) { assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(0)).getCount(), is(equalTo(METER_COUNTS[0].get()))); assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(1)).getCount(), is(equalTo(METER_COUNTS[1].get()))); assertSame("Exception thrown is incorrect", cause, exception); } }
@Test @InSequence(5) public void removeMeterFromRegistry() { assertThat("Meters are not registered correctly", registry.getMeters().keySet(), is(equalTo(absoluteMetricNames()))); Meter meter = registry.getMeters().get(absoluteMetricName(0)); registry.remove(absoluteMetricName(0)); final RuntimeException exception = new IllegalArgumentException("message"); Runnable runnableThatThrowsIllegalArgumentException = new Runnable() { @Override public void run() { throw exception; } }; try { bean.illegalArgumentExceptionMeteredMethod(runnableThatThrowsIllegalArgumentException); fail("No exception has been re-thrown!"); } catch (RuntimeException cause) { assertThat(cause, is(instanceOf(IllegalStateException.class))); assertThat(cause.getMessage(), is(equalTo("No meter with name [" + absoluteMetricName(0) + "] found in registry [" + registry + "]"))); assertThat("Meter count is incorrect", meter.getCount(), is(equalTo(METER_COUNTS[0].get()))); } }