throws Exception
{
final Named name1 = Names.named("bean1");
final Named name2 = Names.named("bean2");
final TestingMBeanServer tms = new TestingMBeanServer();
final Module m1 = new MBeanModule() {
@Override
protected void configureMBeans() {
export(Key.get(Bean.class, name1)).as("bean1:name=bean1");
}
};
final Module m2 = new MBeanModule() {
@Override
protected void configureMBeans() {
export(Key.get(Bean.class, name2)).as("bean2:name=bean2");
}
};
Guice.createInjector(Stage.PRODUCTION,
m1,
m2,
new AbstractModule() {
@Override
public void configure() {
bind(MBeanServer.class).toInstance(tms);
bind(Bean.class).annotatedWith(name1).toInstance(new Bean("name1"));
bind(Bean.class).annotatedWith(name2).toInstance(new Bean("name2"));
}
});
Assert.assertEquals(2, tms.getMBeanCount().intValue());
Assert.assertNotNull(tms.getMBeanInfo(new ObjectName("bean1:name=bean1")));
Assert.assertNotNull(tms.getMBeanInfo(new ObjectName("bean2:name=bean2")));
}