From dabc6ec67f3edc9ca59a71ffece563fc5d9f8bfe Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Sun, 14 Dec 2008 08:00:16 +0000 Subject: [PATCH] moving unit tests from .testsuite -> .context git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@405 50f2f4bb-b051-0410-bef5-90022cba6387 --- ...ommonAnnotationBeanPostProcessorTests.java | 18 +++++++++++++--- ...ssPathBeanDefinitionScannerScopeTests.java | 21 ++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) rename {org.springframework.testsuite => org.springframework.context}/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java (98%) diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java similarity index 98% rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java rename to org.springframework.context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java index af4a28c1ad2..6b93c5ff36e 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java @@ -16,13 +16,14 @@ package org.springframework.context.annotation; +import static org.junit.Assert.*; + import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.annotation.Resource; import javax.ejb.EJB; -import junit.framework.TestCase; - +import org.junit.Test; import org.springframework.beans.INestedTestBean; import org.springframework.beans.ITestBean; import org.springframework.beans.NestedTestBean; @@ -39,9 +40,11 @@ import org.springframework.util.SerializationTestUtils; /** * @author Juergen Hoeller + * @author Chris Beams */ -public class CommonAnnotationBeanPostProcessorTests extends TestCase { +public class CommonAnnotationBeanPostProcessorTests { + @Test public void testPostConstructAndPreDestroy() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor()); @@ -53,6 +56,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase { assertTrue(bean.destroyCalled); } + @Test public void testPostConstructAndPreDestroyWithManualConfiguration() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor(); @@ -67,6 +71,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase { assertTrue(bean.destroyCalled); } + @Test public void testSerialization() throws Exception { CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp2 = (CommonAnnotationBeanPostProcessor) @@ -77,6 +82,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase { assertTrue(bean.destroyCalled); } + @Test public void testSerializationWithManualConfiguration() throws Exception { InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor(); bpp.setInitAnnotationType(PostConstruct.class); @@ -89,6 +95,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase { assertTrue(bean.destroyCalled); } + @Test public void testResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); @@ -110,6 +117,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase { assertTrue(bean.destroy2Called); } + @Test public void testResourceInjectionWithTwoProcessors() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); @@ -134,6 +142,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase { assertTrue(bean.destroy2Called); } + @Test public void testResourceInjectionFromJndi() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); @@ -158,6 +167,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase { assertTrue(bean.destroy2Called); } + @Test public void testExtendedResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); @@ -198,6 +208,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase { assertTrue(bean.destroy2Called); } + @Test public void testExtendedResourceInjectionWithOverriding() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); @@ -246,6 +257,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase { assertTrue(bean.destroy2Called); } + @Test public void testExtendedEjbInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ClassPathBeanDefinitionScannerScopeTests.java b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ClassPathBeanDefinitionScannerScopeTests.java index c454d9c97a4..c870ca29527 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ClassPathBeanDefinitionScannerScopeTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/ClassPathBeanDefinitionScannerScopeTests.java @@ -16,8 +16,11 @@ package org.springframework.context.annotation; -import junit.framework.TestCase; +import static org.junit.Assert.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; @@ -34,8 +37,9 @@ import org.springframework.web.context.support.GenericWebApplicationContext; /** * @author Mark Fisher * @author Juergen Hoeller + * @author Chris Beams */ -public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { +public class ClassPathBeanDefinitionScannerScopeTests { private static final String DEFAULT_NAME = "default"; @@ -50,6 +54,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { private ServletRequestAttributes newRequestAttributesWithSession; + @Before public void setUp() { this.oldRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest()); this.newRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest()); @@ -63,11 +68,13 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { this.newRequestAttributesWithSession = new ServletRequestAttributes(newRequestWithSession); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { RequestContextHolder.setRequestAttributes(null); } + @Test public void testSingletonScopeWithNoProxy() { RequestContextHolder.setRequestAttributes(oldRequestAttributes); ApplicationContext context = createContext(ScopedProxyMode.NO); @@ -88,6 +95,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { assertEquals(MODIFIED_NAME, bean2.getName()); } + @Test public void testSingletonScopeIgnoresProxyInterfaces() { RequestContextHolder.setRequestAttributes(oldRequestAttributes); ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); @@ -108,6 +116,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { assertEquals(MODIFIED_NAME, bean2.getName()); } + @Test public void testSingletonScopeIgnoresProxyTargetClass() { RequestContextHolder.setRequestAttributes(oldRequestAttributes); ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS); @@ -128,6 +137,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { assertEquals(MODIFIED_NAME, bean2.getName()); } + @Test public void testRequestScopeWithNoProxy() { RequestContextHolder.setRequestAttributes(oldRequestAttributes); ApplicationContext context = createContext(ScopedProxyMode.NO); @@ -148,6 +158,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { assertEquals(DEFAULT_NAME, bean2.getName()); } + @Test public void testRequestScopeWithProxiedInterfaces() { RequestContextHolder.setRequestAttributes(oldRequestAttributes); ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); @@ -168,6 +179,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { assertEquals(MODIFIED_NAME, bean.getName()); } + @Test public void testRequestScopeWithProxiedTargetClass() { RequestContextHolder.setRequestAttributes(oldRequestAttributes); ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS); @@ -188,6 +200,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { assertEquals(MODIFIED_NAME, bean.getName()); } + @Test public void testSessionScopeWithNoProxy() { RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); ApplicationContext context = createContext(ScopedProxyMode.NO); @@ -208,6 +221,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { assertEquals(DEFAULT_NAME, bean2.getName()); } + @Test public void testSessionScopeWithProxiedInterfaces() { RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); @@ -234,6 +248,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { assertEquals(MODIFIED_NAME, bean.getName()); } + @Test public void testSessionScopeWithProxiedTargetClass() { RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);