Apply and enforce spring-javaformat
This commit is contained in:
committed by
Dave Syer
parent
ad60397400
commit
7254dc8be7
@@ -18,67 +18,75 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DevelepmentStageInjectorTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
System.setProperty("spring.guice.stage", "DEVELOPMENT");
|
||||
}
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
System.setProperty("spring.guice.stage", "DEVELOPMENT");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup() {
|
||||
System.clearProperty("spring.guice.stage");
|
||||
}
|
||||
@AfterClass
|
||||
public static void cleanup() {
|
||||
System.clearProperty("spring.guice.stage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyInitBean() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DevelepmentStageInjectorTest.ModulesConfig.class);
|
||||
TestGuiceModule testGuiceModule = context.getBean(TestGuiceModule.class);
|
||||
assertFalse(testGuiceModule.getProviderExecuted());
|
||||
GuiceToken guiceToken = context.getBean(GuiceToken.class);
|
||||
assertTrue(testGuiceModule.getProviderExecuted());
|
||||
context.close();
|
||||
}
|
||||
@Test
|
||||
public void testLazyInitBean() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
DevelepmentStageInjectorTest.ModulesConfig.class);
|
||||
TestGuiceModule testGuiceModule = context.getBean(TestGuiceModule.class);
|
||||
assertFalse(testGuiceModule.getProviderExecuted());
|
||||
GuiceToken guiceToken = context.getBean(GuiceToken.class);
|
||||
assertTrue(testGuiceModule.getProviderExecuted());
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableGuiceModules
|
||||
static class ModulesConfig {
|
||||
@Bean
|
||||
public TestGuiceModule testGuiceModule() {
|
||||
return new TestGuiceModule();
|
||||
}
|
||||
@Configuration
|
||||
@EnableGuiceModules
|
||||
static class ModulesConfig {
|
||||
|
||||
@Bean
|
||||
public InjectorFactory injectorFactory() {
|
||||
return new TestDevelopmentStageInjectorFactory();
|
||||
}
|
||||
@Bean
|
||||
public TestGuiceModule testGuiceModule() {
|
||||
return new TestGuiceModule();
|
||||
}
|
||||
|
||||
}
|
||||
@Bean
|
||||
public InjectorFactory injectorFactory() {
|
||||
return new TestDevelopmentStageInjectorFactory();
|
||||
}
|
||||
|
||||
static class TestGuiceModule extends AbstractModule {
|
||||
private boolean providerExecuted = false;
|
||||
}
|
||||
|
||||
public boolean getProviderExecuted() {
|
||||
return this.providerExecuted;
|
||||
}
|
||||
static class TestGuiceModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
private boolean providerExecuted = false;
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public GuiceToken guiceToken() {
|
||||
this.providerExecuted = true;
|
||||
return new GuiceToken();
|
||||
}
|
||||
}
|
||||
public boolean getProviderExecuted() {
|
||||
return this.providerExecuted;
|
||||
}
|
||||
|
||||
static class TestDevelopmentStageInjectorFactory implements InjectorFactory {
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Injector createInjector(List<Module> modules) {
|
||||
return Guice.createInjector(Stage.DEVELOPMENT, modules);
|
||||
}
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
public GuiceToken guiceToken() {
|
||||
this.providerExecuted = true;
|
||||
return new GuiceToken();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class TestDevelopmentStageInjectorFactory implements InjectorFactory {
|
||||
|
||||
@Override
|
||||
public Injector createInjector(List<Module> modules) {
|
||||
return Guice.createInjector(Stage.DEVELOPMENT, modules);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class GuiceToken {
|
||||
|
||||
}
|
||||
|
||||
static class GuiceToken {}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@ public class SpringModuleGuiceBindingAwareTests {
|
||||
@Test
|
||||
public void testAllDependenciesInjectedAndLifeycleMethodsCalledOnce() {
|
||||
Injector injector = Guice.createInjector(new SimpleGuiceModule(),
|
||||
new SpringModule(BeanFactoryProvider
|
||||
.from(GuiceProjectWithSpringLibraryTestSpringConfig.class)));
|
||||
new SpringModule(BeanFactoryProvider.from(GuiceProjectWithSpringLibraryTestSpringConfig.class)));
|
||||
|
||||
// check guice provided bindings
|
||||
assertNotNull(injector.getInstance(GuiceDependency1.class));
|
||||
@@ -55,12 +54,9 @@ public class SpringModuleGuiceBindingAwareTests {
|
||||
assertEquals("done", springBean.getDep1().doWork());
|
||||
|
||||
// check binding equality
|
||||
assertSame(injector.getInstance(IGuiceDependency1.class),
|
||||
AopTestUtils.getTargetObject(springBean.getDep1()));
|
||||
assertSame(injector.getInstance(IGuiceDependency2.class),
|
||||
AopTestUtils.getTargetObject(springBean.getDep2()));
|
||||
assertSame(injector.getInstance(IGuiceDependency3.class),
|
||||
AopTestUtils.getTargetObject(springBean.getDep3()));
|
||||
assertSame(injector.getInstance(IGuiceDependency1.class), AopTestUtils.getTargetObject(springBean.getDep1()));
|
||||
assertSame(injector.getInstance(IGuiceDependency2.class), AopTestUtils.getTargetObject(springBean.getDep2()));
|
||||
assertSame(injector.getInstance(IGuiceDependency3.class), AopTestUtils.getTargetObject(springBean.getDep3()));
|
||||
}
|
||||
|
||||
static class SimpleGuiceModule extends AbstractModule {
|
||||
@@ -73,10 +69,10 @@ public class SpringModuleGuiceBindingAwareTests {
|
||||
bind(IGuiceDependency2.class).toInstance(new IGuiceDependency2() {
|
||||
});
|
||||
// test provider binding
|
||||
bind(IGuiceDependency3.class)
|
||||
.toProvider(Providers.of(new IGuiceDependency3() {
|
||||
}));
|
||||
bind(IGuiceDependency3.class).toProvider(Providers.of(new IGuiceDependency3() {
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -88,8 +84,7 @@ public class SpringModuleGuiceBindingAwareTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ApplicationListener<ApplicationEvent> eventListener(
|
||||
final IGuiceDependency1 dependency) {
|
||||
public ApplicationListener<ApplicationEvent> eventListener(final IGuiceDependency1 dependency) {
|
||||
return new ApplicationListener<ApplicationEvent>() {
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
@@ -97,38 +92,49 @@ public class SpringModuleGuiceBindingAwareTests {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static interface IGuiceDependency1 {
|
||||
|
||||
String doWork();
|
||||
|
||||
}
|
||||
|
||||
static interface IGuiceDependency2 {
|
||||
|
||||
}
|
||||
|
||||
static interface IGuiceDependency3 {
|
||||
|
||||
}
|
||||
|
||||
static class GuiceDependency1 implements IGuiceDependency1 {
|
||||
|
||||
@Override
|
||||
public String doWork() {
|
||||
return "done";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static interface ISpringBean {
|
||||
|
||||
IGuiceDependency1 getDep1();
|
||||
|
||||
IGuiceDependency2 getDep2();
|
||||
|
||||
IGuiceDependency3 getDep3();
|
||||
|
||||
}
|
||||
|
||||
static class SpringBean implements ISpringBean {
|
||||
|
||||
private final IGuiceDependency1 dep1;
|
||||
|
||||
@Inject
|
||||
private IGuiceDependency2 dep2;
|
||||
|
||||
@Inject
|
||||
private IGuiceDependency3 dep3;
|
||||
|
||||
@@ -151,6 +157,7 @@ public class SpringModuleGuiceBindingAwareTests {
|
||||
public IGuiceDependency3 getDep3() {
|
||||
return dep3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,9 +95,11 @@ public class SpringModuleMetadataTests {
|
||||
}
|
||||
|
||||
interface Service {
|
||||
|
||||
}
|
||||
|
||||
protected static class MyService implements Service {
|
||||
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
@@ -110,51 +112,62 @@ public class SpringModuleMetadataTests {
|
||||
|
||||
@Configuration
|
||||
protected static class MetadataExcludesConfig {
|
||||
|
||||
@Bean
|
||||
public GuiceModuleMetadata guiceModuleMetadata() {
|
||||
GuiceModuleMetadata metadata = new GuiceModuleMetadata();
|
||||
metadata.exclude(new AssignableTypeFilter(Service.class));
|
||||
return metadata;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class MetadataIncludesConfig {
|
||||
|
||||
@Bean
|
||||
public GuiceModuleMetadata guiceModuleMetadata() {
|
||||
GuiceModuleMetadata metadata = new GuiceModuleMetadata();
|
||||
metadata.include(new AnnotationTypeFilter(Cacheable.class));
|
||||
return metadata;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class TestConfig {
|
||||
|
||||
@Bean
|
||||
public Service service() {
|
||||
return new MyService();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class PrimaryConfig {
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public Service primary() {
|
||||
return new MyService();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class MoreConfig {
|
||||
|
||||
@Bean
|
||||
public Service more() {
|
||||
return new MyService();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class OtherConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ public class SpringModuleWiringTests extends AbstractCompleteWiringTests {
|
||||
|
||||
@Override
|
||||
protected Injector createInjector() {
|
||||
return Guice.createInjector(new SpringModule(
|
||||
new AnnotationConfigApplicationContext(TestConfig.class)));
|
||||
return Guice.createInjector(new SpringModule(new AnnotationConfigApplicationContext(TestConfig.class)));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class TestConfig {
|
||||
|
||||
@Bean
|
||||
public Service service() {
|
||||
return new MyService();
|
||||
@@ -66,5 +66,7 @@ public class SpringModuleWiringTests extends AbstractCompleteWiringTests {
|
||||
return new Parameterized<String>() {
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,13 +31,14 @@ public class SpringModuleWrappedTests {
|
||||
|
||||
@Test
|
||||
public void testDependenciesFromWrappedModule() {
|
||||
Injector injector = Guice.createInjector(new SpringModule(
|
||||
BeanFactoryProvider.from(TestConfig.class, ModuleProviderConfig.class)));
|
||||
Injector injector = Guice.createInjector(
|
||||
new SpringModule(BeanFactoryProvider.from(TestConfig.class, ModuleProviderConfig.class)));
|
||||
assertNotNull(injector.getInstance(Baz.class));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class TestConfig {
|
||||
|
||||
@Bean
|
||||
public Baz baz(Service service) {
|
||||
return new Baz(service);
|
||||
@@ -46,9 +47,11 @@ public class SpringModuleWrappedTests {
|
||||
}
|
||||
|
||||
interface Service {
|
||||
|
||||
}
|
||||
|
||||
protected static class MyService implements Service {
|
||||
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
@@ -57,6 +60,7 @@ public class SpringModuleWrappedTests {
|
||||
public Foo(@Named("service") Service service) {
|
||||
service.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Baz {
|
||||
|
||||
Reference in New Issue
Block a user