From e8cacade0238955cb4cc10e5a71a8e0ee0cb468f Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 11 Dec 2008 23:24:12 +0000 Subject: [PATCH] moving unit tests from .testsuite -> .aop --- .../AspectJPointcutAdvisorTests.java | 21 +++++++++---------- .../AspectJNamespaceHandlerTests.java | 14 ++++++++++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJPointcutAdvisorTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJPointcutAdvisorTests.java index c158ebcbe1..7348fc128a 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJPointcutAdvisorTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJPointcutAdvisorTests.java @@ -16,8 +16,9 @@ package org.springframework.aop.aspectj.annotation; -import junit.framework.TestCase; +import static org.junit.Assert.*; +import org.junit.Test; import org.springframework.aop.Pointcut; import org.springframework.aop.aspectj.AspectJExpressionPointcut; import org.springframework.aop.aspectj.AspectJExpressionPointcutTests; @@ -26,11 +27,13 @@ import org.springframework.beans.TestBean; /** * @author Rod Johnson + * @author Chris Beams */ -public class AspectJPointcutAdvisorTests extends TestCase { +public class AspectJPointcutAdvisorTests { private AspectJAdvisorFactory af = new ReflectiveAspectJAdvisorFactory(); + @Test public void testSingleton() throws SecurityException, NoSuchMethodException { AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS); @@ -42,6 +45,7 @@ public class AspectJPointcutAdvisorTests extends TestCase { assertFalse(ajpa.isPerInstance()); } + @Test public void testPerTarget() throws SecurityException, NoSuchMethodException { AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS); @@ -62,23 +66,18 @@ public class AspectJPointcutAdvisorTests extends TestCase { TestBean.class)); } - + @Test(expected=AopConfigException.class) public void testPerCflowTarget() { testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowAspect.class); } + @Test(expected=AopConfigException.class) public void testPerCflowBelowTarget() { testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowBelowAspect.class); } - private void testIllegalInstantiationModel(Class c) { - try { - new AspectMetadata(c,"someBean"); - fail(); - } - catch (AopConfigException ex) { - // OK - } + private void testIllegalInstantiationModel(Class c) throws AopConfigException { + new AspectMetadata(c,"someBean"); } } diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJNamespaceHandlerTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJNamespaceHandlerTests.java index 43777b52ad..c42867edef 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJNamespaceHandlerTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJNamespaceHandlerTests.java @@ -16,8 +16,10 @@ package org.springframework.aop.aspectj.autoproxy; -import junit.framework.TestCase; +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; import org.springframework.aop.config.AopConfigUtils; import org.springframework.aop.config.AopNamespaceUtils; import org.springframework.beans.factory.config.BeanDefinition; @@ -32,8 +34,9 @@ import org.springframework.beans.factory.xml.XmlReaderContext; /** * @author Rob Harrop + * @author Chris Beams */ -public class AspectJNamespaceHandlerTests extends TestCase { +public class AspectJNamespaceHandlerTests { private ParserContext parserContext; @@ -42,7 +45,8 @@ public class AspectJNamespaceHandlerTests extends TestCase { private BeanDefinitionRegistry registry = new DefaultListableBeanFactory(); - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { SourceExtractor sourceExtractor = new PassThroughSourceExtractor(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.registry); XmlReaderContext readerContext = @@ -50,6 +54,7 @@ public class AspectJNamespaceHandlerTests extends TestCase { this.parserContext = new ParserContext(readerContext, null); } + @Test public void testRegisterAutoProxyCreator() throws Exception { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount()); @@ -58,6 +63,7 @@ public class AspectJNamespaceHandlerTests extends TestCase { assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount()); } + @Test public void testRegisterAspectJAutoProxyCreator() throws Exception { AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount()); @@ -70,6 +76,7 @@ public class AspectJNamespaceHandlerTests extends TestCase { AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName()); } + @Test public void testRegisterAspectJAutoProxyCreatorWithExistingAutoProxyCreator() throws Exception { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals(1, registry.getBeanDefinitionCount()); @@ -82,6 +89,7 @@ public class AspectJNamespaceHandlerTests extends TestCase { AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName()); } + @Test public void testRegisterAutoProxyCreatorWhenAspectJAutoProxyCreatorAlreadyExists() throws Exception { AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals(1, registry.getBeanDefinitionCount());