HealthModule extends AbstractModule { final protected LinkedBindingBuilder<HealthIndicator> bindAdditionalHealthIndicator() { return Multibinder.newSetBinder(binder(), HealthIndicator.class).addBinding(); }    }
@Test public void testConfiguringIndicatorsByExtendingHealthModule() throws InterruptedException, ExecutionException { LifecycleInjector injector = InjectorBuilder.fromModules(new HealthModule() { @Override protected void configureHealth() { bindAdditionalHealthIndicator().toInstance(healthy); } }, new ArchaiusModule()).createInjector(); HealthCheckAggregator aggregator = injector.getInstance(HealthCheckAggregator.class); assertNotNull(aggregator); HealthCheckStatus healthCheckStatus = aggregator.check().get(); assertTrue(healthCheckStatus.isHealthy()); assertEquals(1, healthCheckStatus.getHealthResults().size()); }
@Test public void testMultipleInstancesOfHealthModuleInstalled() throws InterruptedException, ExecutionException { LifecycleInjector injector = InjectorBuilder.fromModules(new HealthModule() { @Override protected void configureHealth() { bindAdditionalHealthIndicator().toInstance(healthy); } }, new HealthModule() { @Override protected void configureHealth() { bindAdditionalHealthIndicator().toInstance(unhealthy); } }, new ArchaiusModule()).createInjector(); HealthCheckAggregator aggregator = injector.getInstance(HealthCheckAggregator.class); assertNotNull(aggregator); HealthCheckStatus healthCheckStatus = aggregator.check().get(); assertFalse(healthCheckStatus.isHealthy()); assertEquals(2, healthCheckStatus.getHealthResults().size()); }