@@ -75,6 +75,14 @@ public class EnableGuiceModulesTests {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moduleBeanFiltersOutModules() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
FilteringModuleBeanConfig.class);
|
||||
assertThat(context.getBean(Foo.class)).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInjectorCreationDoesNotCauseCircularDependencyError() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MySpringConfig.class);
|
||||
@@ -151,6 +159,32 @@ public class EnableGuiceModulesTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableGuiceModules
|
||||
protected static class FilteringModuleBeanConfig {
|
||||
|
||||
@Bean
|
||||
public static MyModule2 module2() {
|
||||
return new MyModule2();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static MyModule module() {
|
||||
return new MyModule();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Foo service(Service service) {
|
||||
return new Foo(service);
|
||||
}
|
||||
|
||||
@Bean
|
||||
ModuleFilter moduleFilter() {
|
||||
return module -> !(module instanceof MyModule2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class MyModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
@@ -160,6 +194,15 @@ public class EnableGuiceModulesTests {
|
||||
|
||||
}
|
||||
|
||||
protected static class MyModule2 extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
throw new RuntimeException("This should not be called when filtered out!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SpringProvidedBean {
|
||||
|
||||
public SpringProvidedBean(GuiceProvidedBean guiceProvidedBean) {
|
||||
|
||||
Reference in New Issue
Block a user