diff --git a/org.springframework.context/.classpath b/org.springframework.context/.classpath
index 11f30a9ddc..79ec3419eb 100644
--- a/org.springframework.context/.classpath
+++ b/org.springframework.context/.classpath
@@ -12,6 +12,8 @@
+
+
diff --git a/org.springframework.context/ivy.xml b/org.springframework.context/ivy.xml
index 2fbad1e7ef..5faa9fc91a 100644
--- a/org.springframework.context/ivy.xml
+++ b/org.springframework.context/ivy.xml
@@ -54,6 +54,8 @@
+
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AnnotationScopeMetadataResolverTests.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/AnnotationScopeMetadataResolverTests.java
similarity index 78%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AnnotationScopeMetadataResolverTests.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/AnnotationScopeMetadataResolverTests.java
index 9b2334de91..d9612acd4a 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AnnotationScopeMetadataResolverTests.java
+++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/AnnotationScopeMetadataResolverTests.java
@@ -1,27 +1,31 @@
package org.springframework.context.annotation;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.test.AssertThrows;
/**
* Unit tests for the {@link AnnotationScopeMetadataResolver} class.
*
* @author Rick Evans
+ * @author Chris Beams
*/
-public final class AnnotationScopeMetadataResolverTests extends TestCase {
+public final class AnnotationScopeMetadataResolverTests {
private AnnotationScopeMetadataResolver scopeMetadataResolver;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver();
}
+ @Test
public void testThatResolveScopeMetadataDoesNotApplyScopedProxyModeToASingleton() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
@@ -31,6 +35,7 @@ public final class AnnotationScopeMetadataResolverTests extends TestCase {
}
+ @Test
public void testThatResolveScopeMetadataDoesApplyScopedProxyModeToAPrototype() {
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(ScopedProxyMode.INTERFACES);
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
@@ -40,20 +45,14 @@ public final class AnnotationScopeMetadataResolverTests extends TestCase {
assertEquals(ScopedProxyMode.INTERFACES, scopeMetadata.getScopedProxyMode());
}
+ @Test(expected=IllegalArgumentException.class)
public void testCtorWithNullScopedProxyMode() {
- new AssertThrows(IllegalArgumentException.class) {
- public void test() throws Exception {
- new AnnotationScopeMetadataResolver(null);
- }
- }.runTest();
+ new AnnotationScopeMetadataResolver(null);
}
+ @Test(expected=IllegalArgumentException.class)
public void testSetScopeAnnotationTypeWithNullType() {
- new AssertThrows(IllegalArgumentException.class) {
- public void test() throws Exception {
- scopeMetadataResolver.setScopeAnnotationType(null);
- }
- }.runTest();
+ scopeMetadataResolver.setScopeAnnotationType(null);
}
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java
similarity index 97%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java
index bc5cee3de7..d024c8fe83 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java
+++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java
@@ -16,12 +16,13 @@
package org.springframework.context.annotation;
+import static org.junit.Assert.*;
+
import java.util.Iterator;
import java.util.Set;
import java.util.regex.Pattern;
-import junit.framework.TestCase;
-
+import org.junit.Test;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
@@ -35,13 +36,15 @@ import org.springframework.util.ClassUtils;
/**
* @author Mark Fisher
* @author Juergen Hoeller
+ * @author Chris Beams
*/
-public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
+public class ClassPathScanningCandidateComponentProviderTests {
private static final String TEST_BASE_PACKAGE =
ClassPathScanningCandidateComponentProviderTests.class.getPackage().getName();
+ @Test
public void testWithDefaults() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
Set candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
@@ -53,12 +56,14 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
}
+ @Test
public void testWithBogusBasePackage() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
Set candidates = provider.findCandidateComponents("bogus");
assertEquals(0, candidates.size());
}
+ @Test
public void testWithPackageExcludeFilter() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
provider.addExcludeFilter(new RegexPatternTypeFilter(Pattern.compile(TEST_BASE_PACKAGE + ".*")));
@@ -66,12 +71,14 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
assertEquals(0, candidates.size());
}
+ @Test
public void testWithNoFilters() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
Set candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(0, candidates.size());
}
+ @Test
public void testWithComponentAnnotationOnly() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
@@ -88,6 +95,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
}
@SuppressWarnings("unchecked")
+ @Test
public void testWithAspectAnnotationOnly() throws Exception {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AnnotationTypeFilter(
@@ -97,6 +105,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
}
+ @Test
public void testWithInterfaceType() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
@@ -105,6 +114,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
assertTrue(containsBeanClass(candidates, StubFooDao.class));
}
+ @Test
public void testWithClassType() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AssignableTypeFilter(MessageBean.class));
@@ -113,6 +123,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
assertTrue(containsBeanClass(candidates, MessageBean.class));
}
+ @Test
public void testWithMultipleMatchingFilters() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
@@ -124,6 +135,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
}
+ @Test
public void testExcludeTakesPrecedence() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/CustomComponent.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/CustomComponent.java
similarity index 100%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/CustomComponent.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/CustomComponent.java
diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation/DefaultNamedComponent.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/DefaultNamedComponent.java
index 52693697a6..04e7c195a4 100644
--- a/org.springframework.context/src/test/java/org/springframework/context/annotation/DefaultNamedComponent.java
+++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/DefaultNamedComponent.java
@@ -16,7 +16,6 @@
package org.springframework.context.annotation;
-import org.springframework.stereotype.Component;
/**
* @author Juergen Hoeller
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/FooDao.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/FooDao.java
similarity index 100%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/FooDao.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/FooDao.java
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/FooService.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/FooService.java
similarity index 100%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/FooService.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/FooService.java
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/FooServiceImpl.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/FooServiceImpl.java
similarity index 100%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/FooServiceImpl.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/FooServiceImpl.java
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/MessageBean.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/MessageBean.java
similarity index 100%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/MessageBean.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/MessageBean.java
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/NamedComponent.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/NamedComponent.java
similarity index 100%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/NamedComponent.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/NamedComponent.java
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/NamedStubDao.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/NamedStubDao.java
similarity index 100%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/NamedStubDao.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/NamedStubDao.java
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ServiceInvocationCounter.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/ServiceInvocationCounter.java
similarity index 100%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ServiceInvocationCounter.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/ServiceInvocationCounter.java
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java
similarity index 98%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java
index 5cd4eb5eaf..437d3bb211 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java
+++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java
@@ -16,6 +16,8 @@
package org.springframework.context.annotation;
+import static org.junit.Assert.assertTrue;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -23,10 +25,9 @@ import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
-import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
+import org.junit.Test;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -54,7 +55,7 @@ import org.springframework.util.ObjectUtils;
* @author Sam Brannen
* @since 2.5
*/
-public class Spr3775InitDestroyLifecycleTests extends TestCase {
+public class Spr3775InitDestroyLifecycleTests {
private static final Log logger = LogFactory.getLog(Spr3775InitDestroyLifecycleTests.class);
@@ -86,6 +87,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
return beanFactory;
}
+ @Test
public void testInitDestroyMethods() {
final Class> beanClass = InitDestroyBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
@@ -96,6 +98,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("destroy"), bean.destroyMethods);
}
+ @Test
public void testInitializingDisposableInterfaces() {
final Class> beanClass = CustomInitializingDisposableBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
@@ -108,6 +111,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
bean.destroyMethods);
}
+ @Test
public void testInitializingDisposableInterfacesWithShadowedMethods() {
final Class> beanClass = InitializingDisposableWithShadowedMethodsBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
@@ -119,6 +123,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("DisposableBean.destroy"), bean.destroyMethods);
}
+ @Test
public void testJsr250Annotations() {
final Class> beanClass = CustomAnnotatedInitDestroyBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
@@ -131,6 +136,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
bean.destroyMethods);
}
+ @Test
public void testJsr250AnnotationsWithShadowedMethods() {
final Class> beanClass = CustomAnnotatedInitDestroyWithShadowedMethodsBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
@@ -143,6 +149,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
bean.destroyMethods);
}
+ @Test
public void testAllLifecycleMechanismsAtOnce() {
final Class> beanClass = AllInOneBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/StubFooDao.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/StubFooDao.java
similarity index 100%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/StubFooDao.java
rename to org.springframework.context/src/test/java/org/springframework/context/annotation/StubFooDao.java
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AutowiredQualifierFooService.java b/org.springframework.testsuite/src/test/java/example/scannable/AutowiredQualifierFooService.java
similarity index 96%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AutowiredQualifierFooService.java
rename to org.springframework.testsuite/src/test/java/example/scannable/AutowiredQualifierFooService.java
index 8884a07559..6db0d79554 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AutowiredQualifierFooService.java
+++ b/org.springframework.testsuite/src/test/java/example/scannable/AutowiredQualifierFooService.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.context.annotation;
+package example.scannable;
import javax.annotation.PostConstruct;
diff --git a/org.springframework.testsuite/src/test/java/example/scannable/CustomComponent.java b/org.springframework.testsuite/src/test/java/example/scannable/CustomComponent.java
new file mode 100644
index 0000000000..2f6ef7f42a
--- /dev/null
+++ b/org.springframework.testsuite/src/test/java/example/scannable/CustomComponent.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example.scannable;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Mark Fisher
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface CustomComponent {
+
+}
diff --git a/org.springframework.testsuite/src/test/java/example/scannable/CustomStereotype.java b/org.springframework.testsuite/src/test/java/example/scannable/CustomStereotype.java
new file mode 100644
index 0000000000..656ad49bd8
--- /dev/null
+++ b/org.springframework.testsuite/src/test/java/example/scannable/CustomStereotype.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2002-2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example.scannable;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * @author Juergen Hoeller
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Component
+public @interface CustomStereotype {
+
+ String value() default "thoreau";
+
+}
diff --git a/org.springframework.testsuite/src/test/java/example/scannable/DefaultNamedComponent.java b/org.springframework.testsuite/src/test/java/example/scannable/DefaultNamedComponent.java
new file mode 100644
index 0000000000..8ce68ee3d4
--- /dev/null
+++ b/org.springframework.testsuite/src/test/java/example/scannable/DefaultNamedComponent.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2002-2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example.scannable;
+
+
+/**
+ * @author Juergen Hoeller
+ */
+@CustomStereotype
+public class DefaultNamedComponent {
+
+}
diff --git a/org.springframework.testsuite/src/test/java/example/scannable/FooDao.java b/org.springframework.testsuite/src/test/java/example/scannable/FooDao.java
new file mode 100644
index 0000000000..92fe2622d3
--- /dev/null
+++ b/org.springframework.testsuite/src/test/java/example/scannable/FooDao.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example.scannable;
+
+/**
+ * @author Mark Fisher
+ */
+public interface FooDao {
+
+ String findFoo(int id);
+
+}
diff --git a/org.springframework.testsuite/src/test/java/example/scannable/FooService.java b/org.springframework.testsuite/src/test/java/example/scannable/FooService.java
new file mode 100644
index 0000000000..f5fc4e6bfb
--- /dev/null
+++ b/org.springframework.testsuite/src/test/java/example/scannable/FooService.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example.scannable;
+
+/**
+ * @author Mark Fisher
+ * @author Juergen Hoeller
+ */
+public interface FooService {
+
+ String foo(int id);
+
+ boolean isInitCalled();
+
+}
diff --git a/org.springframework.testsuite/src/test/java/example/scannable/FooServiceImpl.java b/org.springframework.testsuite/src/test/java/example/scannable/FooServiceImpl.java
new file mode 100644
index 0000000000..1b13d9644d
--- /dev/null
+++ b/org.springframework.testsuite/src/test/java/example/scannable/FooServiceImpl.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example.scannable;
+
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.ListableBeanFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEventPublisher;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.MessageSource;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author Mark Fisher
+ * @author Juergen Hoeller
+ */
+@Service
+public class FooServiceImpl implements FooService {
+
+ @Autowired private FooDao fooDao;
+
+ @Autowired public BeanFactory beanFactory;
+
+ @Autowired public List listableBeanFactory;
+
+ @Autowired public ResourceLoader resourceLoader;
+
+ @Autowired public ResourcePatternResolver resourcePatternResolver;
+
+ @Autowired public ApplicationEventPublisher eventPublisher;
+
+ @Autowired public MessageSource messageSource;
+
+ @Autowired public ApplicationContext context;
+
+ @Autowired public ConfigurableApplicationContext[] configurableContext;
+
+ @Autowired public AbstractApplicationContext genericContext;
+
+ private boolean initCalled = false;
+
+ @PostConstruct
+ private void init() {
+ if (this.initCalled) {
+ throw new IllegalStateException("Init already called");
+ }
+ this.initCalled = true;
+ }
+
+ public String foo(int id) {
+ return this.fooDao.findFoo(id);
+ }
+
+ public boolean isInitCalled() {
+ return this.initCalled;
+ }
+
+}
diff --git a/org.springframework.testsuite/src/test/java/example/scannable/MessageBean.java b/org.springframework.testsuite/src/test/java/example/scannable/MessageBean.java
new file mode 100644
index 0000000000..a1035f114f
--- /dev/null
+++ b/org.springframework.testsuite/src/test/java/example/scannable/MessageBean.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example.scannable;
+
+/**
+ * @author Mark Fisher
+ */
+@CustomComponent
+public class MessageBean {
+
+ private String message;
+
+ public MessageBean() {
+ this.message = "DEFAULT MESSAGE";
+ }
+
+ public MessageBean(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return this.message;
+ }
+
+}
diff --git a/org.springframework.testsuite/src/test/java/example/scannable/NamedComponent.java b/org.springframework.testsuite/src/test/java/example/scannable/NamedComponent.java
new file mode 100644
index 0000000000..748eef7be8
--- /dev/null
+++ b/org.springframework.testsuite/src/test/java/example/scannable/NamedComponent.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example.scannable;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * @author Mark Fisher
+ */
+@Component("myNamedComponent")
+public class NamedComponent {
+
+}
diff --git a/org.springframework.testsuite/src/test/java/example/scannable/NamedStubDao.java b/org.springframework.testsuite/src/test/java/example/scannable/NamedStubDao.java
new file mode 100644
index 0000000000..a4eb66b88c
--- /dev/null
+++ b/org.springframework.testsuite/src/test/java/example/scannable/NamedStubDao.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example.scannable;
+
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author Juergen Hoeller
+ */
+@Repository("myNamedDao")
+public class NamedStubDao {
+
+ public String find(int id) {
+ return "bar";
+ }
+
+}
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ScopedProxyTestBean.java b/org.springframework.testsuite/src/test/java/example/scannable/ScopedProxyTestBean.java
similarity index 91%
rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ScopedProxyTestBean.java
rename to org.springframework.testsuite/src/test/java/example/scannable/ScopedProxyTestBean.java
index 71c36b6f82..5168b2b66b 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ScopedProxyTestBean.java
+++ b/org.springframework.testsuite/src/test/java/example/scannable/ScopedProxyTestBean.java
@@ -14,7 +14,9 @@
* limitations under the License.
*/
-package org.springframework.context.annotation;
+package example.scannable;
+
+import org.springframework.context.annotation.Scope;
/**
* @author Mark Fisher
diff --git a/org.springframework.testsuite/src/test/java/example/scannable/ServiceInvocationCounter.java b/org.springframework.testsuite/src/test/java/example/scannable/ServiceInvocationCounter.java
new file mode 100644
index 0000000000..a0aa9da722
--- /dev/null
+++ b/org.springframework.testsuite/src/test/java/example/scannable/ServiceInvocationCounter.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example.scannable;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * @author Mark Fisher
+ */
+@Component
+@Aspect
+public class ServiceInvocationCounter {
+
+ private int useCount;
+
+ @Pointcut("execution(* example.scannable.FooService+.*(..))")
+ public void serviceExecution() {}
+
+ @Before("serviceExecution()")
+ public void countUse() {
+ this.useCount++;
+ }
+
+ public int getCount() {
+ return this.useCount;
+ }
+
+}
diff --git a/org.springframework.testsuite/src/test/java/example/scannable/StubFooDao.java b/org.springframework.testsuite/src/test/java/example/scannable/StubFooDao.java
new file mode 100644
index 0000000000..b4ea5b65d5
--- /dev/null
+++ b/org.springframework.testsuite/src/test/java/example/scannable/StubFooDao.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example.scannable;
+
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author Mark Fisher
+ */
+@Repository
+@Qualifier("testing")
+public class StubFooDao implements FooDao {
+
+ public String findFoo(int id) {
+ return "bar";
+ }
+
+}
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AnnotationProcessorPerformanceTests.java b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AnnotationProcessorPerformanceTests.java
index 3bed560602..5244c34a9e 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AnnotationProcessorPerformanceTests.java
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AnnotationProcessorPerformanceTests.java
@@ -16,12 +16,13 @@
package org.springframework.context.annotation;
+import static org.junit.Assert.*;
+
import javax.annotation.Resource;
-import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
+import org.junit.Test;
import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean;
import org.springframework.beans.factory.annotation.Autowired;
@@ -34,12 +35,14 @@ import org.springframework.util.StopWatch;
/**
* @author Juergen Hoeller
+ * @author Chris Beams
* @since 2.5
*/
-public class AnnotationProcessorPerformanceTests extends TestCase {
+public class AnnotationProcessorPerformanceTests {
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
+ @Test
public void testPrototypeCreationWithResourcePropertiesIsFastEnough() {
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
// Skip this test: Trace logging blows the time limit.
@@ -65,6 +68,7 @@ public class AnnotationProcessorPerformanceTests extends TestCase {
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
+ @Test
public void testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough() {
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
// Skip this test: Trace logging blows the time limit.
@@ -91,6 +95,7 @@ public class AnnotationProcessorPerformanceTests extends TestCase {
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
+ @Test
public void testPrototypeCreationWithAutowiredPropertiesIsFastEnough() {
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
// Skip this test: Trace logging blows the time limit.
@@ -116,6 +121,7 @@ public class AnnotationProcessorPerformanceTests extends TestCase {
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
+ @Test
public void testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough() {
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
// Skip this test: Trace logging blows the time limit.
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ClassPathBeanDefinitionScannerTests.java b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ClassPathBeanDefinitionScannerTests.java
index b90122ac6f..a7d90eed51 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ClassPathBeanDefinitionScannerTests.java
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ClassPathBeanDefinitionScannerTests.java
@@ -16,8 +16,10 @@
package org.springframework.context.annotation;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+
import org.aspectj.lang.annotation.Aspect;
+import org.junit.Test;
import org.springframework.beans.TestBean;
import org.springframework.beans.factory.BeanCreationException;
@@ -33,21 +35,28 @@ import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.stereotype.Component;
+import example.scannable.CustomComponent;
+import example.scannable.FooService;
+import example.scannable.FooServiceImpl;
+import example.scannable.NamedStubDao;
+import example.scannable.StubFooDao;
+
/**
* @author Mark Fisher
* @author Juergen Hoeller
+ * @author Chris Beams
*/
-public class ClassPathBeanDefinitionScannerTests extends TestCase {
+public class ClassPathBeanDefinitionScannerTests {
+
+ private static final String BASE_PACKAGE = "example.scannable";
- private static final String BASE_PACKAGE =
- ClassPathBeanDefinitionScannerTests.class.getPackage().getName();
-
+ @Test
public void testSimpleScanWithDefaultFiltersAndPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(13, beanCount);
+ assertEquals(10, beanCount);
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
@@ -59,11 +68,12 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
+ @Test
public void testDoubleScan() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(13, beanCount);
+ assertEquals(10, beanCount);
scanner.scan(BASE_PACKAGE);
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
@@ -73,12 +83,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean("thoreau"));
}
+ @Test
public void testSimpleScanWithDefaultFiltersAndNoPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(9, beanCount);
+ assertEquals(6, beanCount);
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
@@ -86,6 +97,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean("myNamedDao"));
}
+ @Test
public void testSimpleScanWithDefaultFiltersAndOverridingBean() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(TestBean.class));
@@ -95,6 +107,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
scanner.scan(BASE_PACKAGE);
}
+ @Test
public void testSimpleScanWithDefaultFiltersAndDefaultBeanNameClash() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
@@ -111,14 +124,15 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
}
}
+ @Test
public void testSimpleScanWithDefaultFiltersAndOverriddenEqualNamedBean() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("myNamedDao", new RootBeanDefinition(NamedStubDao.class));
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(8, beanCount);
- assertEquals(9, context.getBeanDefinitionCount());
+ assertEquals(5, beanCount);
+ assertEquals(6, context.getBeanDefinitionCount());
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
@@ -126,6 +140,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean("myNamedDao"));
}
+ @Test
public void testSimpleScanWithDefaultFiltersAndOverriddenCompatibleNamedBean() {
GenericApplicationContext context = new GenericApplicationContext();
RootBeanDefinition bd = new RootBeanDefinition(NamedStubDao.class);
@@ -134,8 +149,8 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(8, beanCount);
- assertEquals(9, context.getBeanDefinitionCount());
+ assertEquals(5, beanCount);
+ assertEquals(6, context.getBeanDefinitionCount());
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
@@ -143,6 +158,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean("myNamedDao"));
}
+ @Test
public void testSimpleScanWithDefaultFiltersAndSameBeanTwice() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
@@ -152,6 +168,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
scanner.scan(BASE_PACKAGE);
}
+ @Test
public void testSimpleScanWithDefaultFiltersAndSpecifiedBeanNameClash() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
@@ -168,6 +185,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
}
}
+ @Test
public void testCustomIncludeFilterWithoutDefaultsButIncludingPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
@@ -180,6 +198,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
+ @Test
public void testCustomIncludeFilterWithoutDefaultsAndNoPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
@@ -197,12 +216,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
+ @Test
public void testCustomIncludeFilterAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(14, beanCount);
+ assertEquals(11, beanCount);
assertTrue(context.containsBean("messageBean"));
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
@@ -214,12 +234,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
+ @Test
public void testCustomAnnotationExcludeFilterAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(12, beanCount);
+ assertEquals(9, beanCount);
assertFalse(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
@@ -230,12 +251,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
+ @Test
public void testCustomAssignableTypeExcludeFilterAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(12, beanCount);
+ assertEquals(9, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("stubFooDao"));
@@ -246,13 +268,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
+ @Test
public void testCustomAssignableTypeExcludeFilterAndDefaultsWithoutPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.setIncludeAnnotationConfig(false);
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(8, beanCount);
+ assertEquals(5, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("stubFooDao"));
@@ -263,13 +286,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertFalse(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
+ @Test
public void testMultipleCustomExcludeFiltersAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(11, beanCount);
+ assertEquals(8, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertFalse(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("stubFooDao"));
@@ -280,12 +304,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
+ @Test
public void testCustomBeanNameGenerator() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(13, beanCount);
+ assertEquals(10, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("fooService"));
assertTrue(context.containsBean("serviceInvocationCounter"));
@@ -297,35 +322,37 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
+ @Test
public void testMultipleBasePackagesWithDefaultsOnly() {
GenericApplicationContext singlePackageContext = new GenericApplicationContext();
ClassPathBeanDefinitionScanner singlePackageScanner = new ClassPathBeanDefinitionScanner(singlePackageContext);
GenericApplicationContext multiPackageContext = new GenericApplicationContext();
ClassPathBeanDefinitionScanner multiPackageScanner = new ClassPathBeanDefinitionScanner(multiPackageContext);
int singlePackageBeanCount = singlePackageScanner.scan(BASE_PACKAGE);
- assertEquals(13, singlePackageBeanCount);
- int multiPackageBeanCount = multiPackageScanner.scan(
- BASE_PACKAGE, "org.springframework.dao.annotation");
-// assertTrue(multiPackageBeanCount > singlePackageBeanCount);
+ assertEquals(10, singlePackageBeanCount);
+ multiPackageScanner.scan(BASE_PACKAGE, "org.springframework.dao.annotation");
+ // assertTrue(multiPackageBeanCount > singlePackageBeanCount);
}
+ @Test
public void testMultipleScanCalls() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(13, beanCount);
+ assertEquals(10, beanCount);
assertEquals(beanCount, context.getBeanDefinitionCount());
int addedBeanCount = scanner.scan("org.springframework.aop.aspectj.annotation");
assertEquals(beanCount + addedBeanCount, context.getBeanDefinitionCount());
}
+ @Test
public void testBeanAutowiredWithAnnotationConfigEnabled() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class));
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(13, beanCount);
+ assertEquals(10, beanCount);
context.refresh();
FooServiceImpl fooService = (FooServiceImpl) context.getBean("fooService");
@@ -347,13 +374,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertSame(context, fooService.genericContext);
}
+ @Test
public void testBeanNotAutowiredWithAnnotationConfigDisabled() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
- assertEquals(9, beanCount);
+ assertEquals(6, beanCount);
context.refresh();
FooService fooService = (FooService) context.getBean("fooService");
assertFalse(fooService.isInitCalled());
@@ -365,6 +393,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
}
}
+ @Test
public void testAutowireCandidatePatternMatches() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
@@ -377,6 +406,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertEquals("bar", fooService.foo(123));
}
+ @Test
public void testAutowireCandidatePatternDoesNotMatch() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ComponentScanParserScopedProxyTests.java b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ComponentScanParserScopedProxyTests.java
index 4c0b11ff6e..4122eee6e5 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ComponentScanParserScopedProxyTests.java
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ComponentScanParserScopedProxyTests.java
@@ -23,6 +23,9 @@ import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.config.SimpleMapScope;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import example.scannable.FooService;
+import example.scannable.ScopedProxyTestBean;
+
/**
* @author Mark Fisher
* @author Juergen Hoeller
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ComponentScanParserTests.java b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ComponentScanParserTests.java
index 6d99e46870..0b39e024da 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ComponentScanParserTests.java
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ComponentScanParserTests.java
@@ -30,6 +30,8 @@ import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
+import example.scannable.AutowiredQualifierFooService;
+
/**
* @author Mark Fisher
* @author Juergen Hoeller
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/SimpleConfigTests.java b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/SimpleConfigTests.java
index c083e53f9e..c40a658737 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/SimpleConfigTests.java
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/SimpleConfigTests.java
@@ -18,6 +18,9 @@ package org.springframework.context.annotation;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
+import example.scannable.FooService;
+import example.scannable.ServiceInvocationCounter;
+
/**
* @author Mark Fisher
*/
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/SimpleScanTests.java b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/SimpleScanTests.java
index b80f583a05..e7d4769a9c 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/SimpleScanTests.java
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/SimpleScanTests.java
@@ -18,6 +18,9 @@ package org.springframework.context.annotation;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
+import example.scannable.FooService;
+import example.scannable.ServiceInvocationCounter;
+
/**
* @author Mark Fisher
* @author Juergen Hoeller
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/aspectjTypeFilterTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/aspectjTypeFilterTests.xml
index c9c4b27f0f..e352102048 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/aspectjTypeFilterTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/aspectjTypeFilterTests.xml
@@ -5,10 +5,10 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-
-
-
-
+
+
+
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/componentScanWithAutowiredQualifierTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/componentScanWithAutowiredQualifierTests.xml
index 014552c2e7..85bcd70173 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/componentScanWithAutowiredQualifierTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/componentScanWithAutowiredQualifierTests.xml
@@ -7,8 +7,8 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-
+
-
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/customNameGeneratorTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/customNameGeneratorTests.xml
index 98afdcf039..08d511cdac 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/customNameGeneratorTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/customNameGeneratorTests.xml
@@ -5,7 +5,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/customScopeResolverTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/customScopeResolverTests.xml
index 46ead34fc9..df20982b67 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/customScopeResolverTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/customScopeResolverTests.xml
@@ -5,7 +5,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/doubleScanTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/doubleScanTests.xml
index ceafc590f6..eb44cc0cf0 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/doubleScanTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/doubleScanTests.xml
@@ -7,10 +7,10 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-
+
-
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/matchingResourcePatternTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/matchingResourcePatternTests.xml
index 666cedeb21..02a949a8d4 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/matchingResourcePatternTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/matchingResourcePatternTests.xml
@@ -5,11 +5,11 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-
-
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/nonMatchingResourcePatternTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/nonMatchingResourcePatternTests.xml
index 7b04ea08c2..1600695a65 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/nonMatchingResourcePatternTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/nonMatchingResourcePatternTests.xml
@@ -9,7 +9,7 @@
resource-pattern="**/thispackagedoesnotexist/*.class"
use-default-filters="false"
annotation-config="false">
-
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyDefaultTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyDefaultTests.xml
index ace6a27818..83a1154190 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyDefaultTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyDefaultTests.xml
@@ -5,10 +5,8 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-
-
+
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyInterfacesTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyInterfacesTests.xml
index 2d0d3b4a0d..69e21adc92 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyInterfacesTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyInterfacesTests.xml
@@ -5,10 +5,8 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-
-
+
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyNoTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyNoTests.xml
index e21696c0de..cb79e0f0a5 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyNoTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyNoTests.xml
@@ -5,10 +5,9 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-
-
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyTargetClassTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyTargetClassTests.xml
index 421ab16720..7d11182142 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyTargetClassTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/scopedProxyTargetClassTests.xml
@@ -5,10 +5,8 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-
-
+
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/simpleConfigTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/simpleConfigTests.xml
index fe95742963..0425e4fe31 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/simpleConfigTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/simpleConfigTests.xml
@@ -11,10 +11,10 @@
-
+
-
+
-
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/simpleScanTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/simpleScanTests.xml
index 5431846bf5..ec67462481 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/simpleScanTests.xml
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/simpleScanTests.xml
@@ -7,7 +7,7 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-
+
diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation3/StubFooDao.java b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation3/StubFooDao.java
index c1403e0e07..64f491bd4e 100644
--- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation3/StubFooDao.java
+++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation3/StubFooDao.java
@@ -18,7 +18,8 @@ package org.springframework.context.annotation3;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
-import org.springframework.context.annotation.FooDao;
+
+import example.scannable.FooDao;
/**
* @author Mark Fisher