CompoundMeterBinder implements CloseableMeterBinder { @Override public void bindTo(MeterRegistry registry) { meterBinders.forEach(binder -> bind(registry, binder)); } CompoundMeterBinder(Collection<MeterBinder> binders); @VisibleForTesting  CompoundMeterBinder(Logger logger, Collection<MeterBinder> binders); @Override void bindTo(MeterRegistry registry); @Override void close();  }
@Test public void bindsAllBinders() { MeterRegistry registry = mock(MeterRegistry.class); Set<MeterBinder> meterBinders = setOf(7, MeterBinder.class); CompoundMeterBinder composedBinder = new CompoundMeterBinder(meterBinders); composedBinder.bindTo(registry); meterBinders.forEach(binder -> verify(binder).bindTo(same(registry))); }
@Test public void logsWarning_ifBinderThrowsWhileBinding() { Logger logger = mock(Logger.class); RuntimeException thrownByBinder = new RuntimeException("thrown for test purposes"); CloseableMeterBinder throwingBinder = mock(CloseableMeterBinder.class); doThrow(thrownByBinder).when(throwingBinder).bindTo(any()); CompoundMeterBinder composedBinder = new CompoundMeterBinder(logger, singleton(throwingBinder)); composedBinder.bindTo(mock(MeterRegistry.class)); verify(logger).warn(any(String.class), same(thrownByBinder)); }