Add test for binding to Map by generic signature

See #67
This commit is contained in:
Dave Syer
2019-11-19 10:57:34 +00:00
parent 4277d3e0f5
commit f759e6e4ab
2 changed files with 66 additions and 2 deletions

View File

@@ -0,0 +1,63 @@
package org.springframework.guice;
import java.util.Map;
import com.google.inject.AbstractModule;
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 static org.junit.Assert.assertTrue;
/**
* Test injecting Map
*
* @author Dave Syer
*/
public class MapWiringTests {
// Test Guice -> Spring direction
@SuppressWarnings({ "resource", "unused" })
@Test
public void testProvidesMap() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
ModulesConfig.class, FooBar.class);
Bar bar = context.getBean(Bar.class);
}
@Configuration
@EnableGuiceModules
static class ModulesConfig {
@Bean
TestConfig testConfig() {
return new TestConfig();
}
}
@Configuration
static class FooBar {
@Bean
Bar foo(Map<String, Foo> foos) {
assertTrue(!foos.isEmpty());
return new Bar();
}
}
static class TestConfig extends AbstractModule {
@Override
protected void configure() {
bind(Foo.class);
}
}
static class Foo {
}
static class Bar {
}
}

View File

@@ -325,6 +325,7 @@ public class SuperClassTests {
}
private void baseTestSpringFactoryBean(Class<?> configClass) {
@SuppressWarnings("resource")
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
configClass);
@@ -495,8 +496,8 @@ public class SuperClassTests {
}
public static class Bar {}
public static class Bar {
}
@Component
public static class BarFactory implements FactoryBean<Bar> {