Fix compiler warnings
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
package org.springframework.guice;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import com.google.inject.*;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Stage;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.ModuleFilteringTests.FilterThisModule;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import org.springframework.guice.annotation.InjectorFactory;
|
||||
|
||||
import java.util.List;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class ModuleFilteringTests {
|
||||
|
||||
@@ -33,19 +34,21 @@ public class ModuleFilteringTests {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchBeanDefinitionException.class)
|
||||
@Test(expected = NoSuchBeanDefinitionException.class)
|
||||
public void verifyFilteredModuleIsFiltered() {
|
||||
System.setProperty("spring.guice.modules.exclude", "FilterThisModule");
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
ModuleFilteringTestsConfig.class);
|
||||
try {
|
||||
context.getBean(SomeInterface.class);
|
||||
} finally {
|
||||
context.getBean(SomeInterface.class);
|
||||
}
|
||||
finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static interface SomeInterface {}
|
||||
public static interface SomeInterface {
|
||||
}
|
||||
|
||||
public static class SomeDependency implements SomeInterface {
|
||||
public SomeDependency() {
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
package org.springframework.guice;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
import org.springframework.guice.injector.SpringInjector;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Test Generics (e.g., Supplier<T>) not losing type info across bridge in both directions
|
||||
*
|
||||
@@ -22,90 +24,99 @@ import java.util.function.Supplier;
|
||||
*/
|
||||
public class ProvidesSupplierWiringTests {
|
||||
|
||||
//Test Guice -> Spring direction
|
||||
@Test
|
||||
public void testProvidesSupplier() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ModulesConfig.class, FooBar.class);
|
||||
Foo foo = (Foo)context.getBean(Foo.class);
|
||||
Bar bar = (Bar)context.getBean(Bar.class);
|
||||
}
|
||||
// Test Guice -> Spring direction
|
||||
@SuppressWarnings({ "resource", "unused" })
|
||||
@Test
|
||||
public void testProvidesSupplier() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
ModulesConfig.class, FooBar.class);
|
||||
Foo foo = context.getBean(Foo.class);
|
||||
Bar bar = context.getBean(Bar.class);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableGuiceModules
|
||||
static class ModulesConfig {
|
||||
@Bean
|
||||
TestConfig testConfig() {
|
||||
return new TestConfig();
|
||||
}
|
||||
}
|
||||
@Configuration
|
||||
@EnableGuiceModules
|
||||
static class ModulesConfig {
|
||||
@Bean
|
||||
TestConfig testConfig() {
|
||||
return new TestConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class FooBar {
|
||||
@Bean
|
||||
Foo foo(Supplier<Foo> supplier) {
|
||||
return supplier.get();
|
||||
}
|
||||
@Configuration
|
||||
static class FooBar {
|
||||
@Bean
|
||||
Foo foo(Supplier<Foo> supplier) {
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
@Bean
|
||||
Bar bar(Supplier<Bar> supplier) {
|
||||
return supplier.get();
|
||||
}
|
||||
}
|
||||
@Bean
|
||||
Bar bar(Supplier<Bar> supplier) {
|
||||
return supplier.get();
|
||||
}
|
||||
}
|
||||
|
||||
static class TestConfig extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
static class TestConfig extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Supplier<Foo> getFoo() {
|
||||
return ()->new Foo();
|
||||
}
|
||||
@Singleton
|
||||
@Provides
|
||||
Supplier<Foo> getFoo() {
|
||||
return () -> new Foo();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Supplier<Bar> getBar() {
|
||||
return ()->new Bar();
|
||||
}
|
||||
}
|
||||
@Singleton
|
||||
@Provides
|
||||
Supplier<Bar> getBar() {
|
||||
return () -> new Bar();
|
||||
}
|
||||
}
|
||||
|
||||
static class Foo {
|
||||
}
|
||||
static class Foo {
|
||||
}
|
||||
|
||||
static class Bar {
|
||||
static class Bar {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Test Spring -> Guice direction
|
||||
//ToDo -- Today this direction doesn't work without further work. Ignore the test for now.
|
||||
@Ignore
|
||||
@Test
|
||||
public void testProvidesSupplierSpring() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(FooBarSpring.class);
|
||||
SpringInjector injector = new SpringInjector(context);
|
||||
Foo_Spring fooSpring = injector.getInstance(Key.get(new TypeLiteral<Supplier<Foo_Spring>>(){})).get();
|
||||
Bar_Spring barSpring = injector.getInstance(Key.get(new TypeLiteral<Supplier<Bar_Spring>>(){})).get();
|
||||
}
|
||||
// Test Spring -> Guice direction
|
||||
// ToDo -- Today this direction doesn't work without further work. Ignore the test for
|
||||
// now.
|
||||
@SuppressWarnings("unused")
|
||||
@Ignore
|
||||
@Test
|
||||
public void testProvidesSupplierSpring() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
FooBarSpring.class);
|
||||
SpringInjector injector = new SpringInjector(context);
|
||||
Foo_Spring fooSpring = injector
|
||||
.getInstance(Key.get(new TypeLiteral<Supplier<Foo_Spring>>() {
|
||||
})).get();
|
||||
Bar_Spring barSpring = injector
|
||||
.getInstance(Key.get(new TypeLiteral<Supplier<Bar_Spring>>() {
|
||||
})).get();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class FooBarSpring {
|
||||
@Bean
|
||||
Supplier<Foo_Spring> fooSpring() {
|
||||
return ()->new Foo_Spring();
|
||||
}
|
||||
@Configuration
|
||||
static class FooBarSpring {
|
||||
@Bean
|
||||
Supplier<Foo_Spring> fooSpring() {
|
||||
return () -> new Foo_Spring();
|
||||
}
|
||||
|
||||
@Bean
|
||||
Bar_Spring barSpring() {
|
||||
return new Bar_Spring();
|
||||
}
|
||||
}
|
||||
@Bean
|
||||
Bar_Spring barSpring() {
|
||||
return new Bar_Spring();
|
||||
}
|
||||
}
|
||||
|
||||
static class Foo_Spring {
|
||||
}
|
||||
static class Foo_Spring {
|
||||
}
|
||||
|
||||
static class Bar_Spring {
|
||||
static class Bar_Spring {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user