From 5900cd6daa1749e760565e456c19d9b188e9a483 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 8 Dec 2009 15:29:27 +0000 Subject: [PATCH] Renamed tests for AnnotationConfig[Web]ApplicationContext; added tests for scan() and register() methods. git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2604 50f2f4bb-b051-0410-bef5-90022cba6387 --- ...otationConfigApplicationContextTests.java} | 22 ++++++++++++++++--- .../annotation6/ComponentForScanning.java | 7 ++++++ .../annotation6/ConfigForScanning.java | 14 ++++++++++++ .../annotation6/Jsr330NamedForScanning.java | 8 +++++++ ...tionConfigWebApplicationContextTests.java} | 2 +- 5 files changed, 49 insertions(+), 4 deletions(-) rename org.springframework.context/src/test/java/org/springframework/context/annotation/{ConfigurationClassApplicationContextTests.java => AnnotationConfigApplicationContextTests.java} (84%) create mode 100644 org.springframework.context/src/test/java/org/springframework/context/annotation6/ComponentForScanning.java create mode 100644 org.springframework.context/src/test/java/org/springframework/context/annotation6/ConfigForScanning.java create mode 100644 org.springframework.context/src/test/java/org/springframework/context/annotation6/Jsr330NamedForScanning.java rename org.springframework.web/src/test/java/org/springframework/web/context/support/{ConfigurationClassWebApplicationContextTests.java => AnnotationConfigWebApplicationContextTests.java} (95%) diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation/ConfigurationClassApplicationContextTests.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java similarity index 84% rename from org.springframework.context/src/test/java/org/springframework/context/annotation/ConfigurationClassApplicationContextTests.java rename to org.springframework.context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java index 6f15b00d6cc..dcdb918d9b7 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/annotation/ConfigurationClassApplicationContextTests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java @@ -22,23 +22,39 @@ import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import org.junit.Test; import static org.junit.matchers.JUnitMatchers.*; +import static org.springframework.util.StringUtils.uncapitalize; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation6.ComponentForScanning; +import org.springframework.context.annotation6.ConfigForScanning; +import org.springframework.context.annotation6.Jsr330NamedForScanning; +import org.springframework.util.StringUtils; /** * @author Chris Beams */ -public class ConfigurationClassApplicationContextTests { +public class AnnotationConfigApplicationContextTests { @Test(expected=IllegalArgumentException.class) public void nullGetBeanParameterIsDisallowed() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); context.getBean((Class)null); } + + @Test + public void scanAndRefresh() { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + context.scan("org.springframework.context.annotation6"); + context.refresh(); + context.getBean(uncapitalize(ConfigForScanning.class.getSimpleName())); + context.getBean("testBean"); // contributed by ConfigForScanning + context.getBean(uncapitalize(ComponentForScanning.class.getSimpleName())); + context.getBean(uncapitalize(Jsr330NamedForScanning.class.getSimpleName())); + } @Test - public void addConfigurationClass() { + public void registerAndRefresh() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(Config.class, NameConfig.class); context.refresh(); @@ -63,7 +79,7 @@ public class ConfigurationClassApplicationContextTests { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); // attempt to retrieve the instance by its generated bean name - Config configObject = (Config) context.getBean("configurationClassApplicationContextTests.Config"); + Config configObject = (Config) context.getBean("annotationConfigApplicationContextTests.Config"); assertNotNull(configObject); } diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation6/ComponentForScanning.java b/org.springframework.context/src/test/java/org/springframework/context/annotation6/ComponentForScanning.java new file mode 100644 index 00000000000..8307f58a0bc --- /dev/null +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation6/ComponentForScanning.java @@ -0,0 +1,7 @@ +package org.springframework.context.annotation6; + +import org.springframework.stereotype.Component; + +@Component +public class ComponentForScanning { +} diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation6/ConfigForScanning.java b/org.springframework.context/src/test/java/org/springframework/context/annotation6/ConfigForScanning.java new file mode 100644 index 00000000000..8dbb67f34ae --- /dev/null +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation6/ConfigForScanning.java @@ -0,0 +1,14 @@ +package org.springframework.context.annotation6; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import test.beans.TestBean; + +@Configuration +public class ConfigForScanning { + @Bean + public TestBean testBean() { + return new TestBean(); + } +} diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation6/Jsr330NamedForScanning.java b/org.springframework.context/src/test/java/org/springframework/context/annotation6/Jsr330NamedForScanning.java new file mode 100644 index 00000000000..49567880a3f --- /dev/null +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation6/Jsr330NamedForScanning.java @@ -0,0 +1,8 @@ +package org.springframework.context.annotation6; + +import javax.inject.Named; + +@Named +public class Jsr330NamedForScanning { + +} diff --git a/org.springframework.web/src/test/java/org/springframework/web/context/support/ConfigurationClassWebApplicationContextTests.java b/org.springframework.web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java similarity index 95% rename from org.springframework.web/src/test/java/org/springframework/web/context/support/ConfigurationClassWebApplicationContextTests.java rename to org.springframework.web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java index 92c1799e646..c7d7b399c09 100644 --- a/org.springframework.web/src/test/java/org/springframework/web/context/support/ConfigurationClassWebApplicationContextTests.java +++ b/org.springframework.web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration; /** * @author Chris Beams */ -public class ConfigurationClassWebApplicationContextTests { +public class AnnotationConfigWebApplicationContextTests { @Test public void testSingleWellFormedConfigLocation() {