diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/annotation/AspectMetadataTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectMetadataTests.java similarity index 89% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/annotation/AspectMetadataTests.java rename to org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectMetadataTests.java index f6e3b04096f..c435cbbcd06 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/annotation/AspectMetadataTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectMetadataTests.java @@ -16,8 +16,9 @@ package org.springframework.aop.aspectj.annotation; -import junit.framework.TestCase; +import static org.junit.Assert.*; import org.aspectj.lang.reflect.PerClauseKind; +import org.junit.Test; import org.springframework.aop.Pointcut; import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionAspect; @@ -25,23 +26,18 @@ import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryT import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.PerThisAspect; /** - * * @since 2.0 * @author Rod Johnson - * + * @author Chris Beams */ -public class AspectMetadataTests extends TestCase { +public class AspectMetadataTests { + @Test(expected=IllegalArgumentException.class) public void testNotAnAspect() { - try { - new AspectMetadata(String.class,"someBean"); - fail(); - } - catch (IllegalArgumentException ex) { - // Ok - } + new AspectMetadata(String.class,"someBean"); } + @Test public void testSingletonAspect() { AspectMetadata am = new AspectMetadata(ExceptionAspect.class,"someBean"); assertFalse(am.isPerThisOrPerTarget()); @@ -49,6 +45,7 @@ public class AspectMetadataTests extends TestCase { assertEquals(PerClauseKind.SINGLETON, am.getAjType().getPerClause().getKind()); } + @Test public void testPerTargetAspect() { AspectMetadata am = new AspectMetadata(PerTargetAspect.class,"someBean"); assertTrue(am.isPerThisOrPerTarget()); @@ -56,6 +53,7 @@ public class AspectMetadataTests extends TestCase { assertEquals(PerClauseKind.PERTARGET, am.getAjType().getPerClause().getKind()); } + @Test public void testPerThisAspect() { AspectMetadata am = new AspectMetadata(PerThisAspect.class,"someBean"); assertTrue(am.isPerThisOrPerTarget()); diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java similarity index 75% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java rename to org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java index 8bf7fc8eede..6dc80c1e38b 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java @@ -16,27 +16,26 @@ package org.springframework.aop.aspectj.annotation; -import junit.framework.TestCase; +import static org.junit.Assert.*; +import org.junit.Test; import org.springframework.aop.aspectj.autoproxy.MultiplyReturnValue; import org.springframework.aop.aspectj.autoproxy.PerThisAspect; -import org.springframework.test.AssertThrows; /** * @author Rob Harrop * @author Juergen Hoeller + * @author Chris Beams */ -public class AspectProxyFactoryTests extends TestCase { - - public void testWithNonAspect() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean()); - proxyFactory.addAspect(TestBean.class); - } - }.runTest(); +public class AspectProxyFactoryTests { + + @Test(expected=IllegalArgumentException.class) + public void testWithNonAspect() { + AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean()); + proxyFactory.addAspect(TestBean.class); } + @Test public void testWithSimpleAspect() throws Exception { TestBean bean = new TestBean(); bean.setAge(2); @@ -46,6 +45,7 @@ public class AspectProxyFactoryTests extends TestCase { assertEquals("Multiplication did not occur", bean.getAge() * 2, proxy.getAge()); } + @Test public void testWithPerThisAspect() throws Exception { TestBean bean1 = new TestBean(); TestBean bean2 = new TestBean(); @@ -65,15 +65,13 @@ public class AspectProxyFactoryTests extends TestCase { assertEquals(2, proxy1.getAge()); } + @Test(expected=IllegalArgumentException.class) public void testWithInstanceWithNonAspect() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - AspectJProxyFactory pf = new AspectJProxyFactory(); - pf.addAspect(new TestBean()); - } - }.runTest(); + AspectJProxyFactory pf = new AspectJProxyFactory(); + pf.addAspect(new TestBean()); } + @Test public void testWithInstance() throws Exception { MultiplyReturnValue aspect = new MultiplyReturnValue(); int multiple = 3; @@ -90,13 +88,10 @@ public class AspectProxyFactoryTests extends TestCase { assertEquals(target.getAge() * multiple, proxy.getAge()); } + @Test(expected=IllegalArgumentException.class) public void testWithNonSingletonAspectInstance() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - AspectJProxyFactory pf = new AspectJProxyFactory(); - pf.addAspect(new PerThisAspect()); - } - }.runTest(); + AspectJProxyFactory pf = new AspectJProxyFactory(); + pf.addAspect(new PerThisAspect()); } diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/MultiplyReturnValue.java b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/MultiplyReturnValue.java new file mode 100644 index 00000000000..9d940e7ac66 --- /dev/null +++ b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/MultiplyReturnValue.java @@ -0,0 +1,48 @@ +/* + * Copyright 2002-2006 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 org.springframework.aop.aspectj.autoproxy; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; + +/** + * @author Rod Johnson + */ +@Aspect +public class MultiplyReturnValue { + + private int multiple = 2; + + public int invocations; + + public void setMultiple(int multiple) { + this.multiple = multiple; + } + + public int getMultiple() { + return this.multiple; + } + + @Around("execution(int *.getAge())") + public Object doubleReturnValue(ProceedingJoinPoint pjp) throws Throwable { + ++this.invocations; + int result = (Integer) pjp.proceed(); + return result * this.multiple; + } + +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/PerThisAspect.java b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/PerThisAspect.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/PerThisAspect.java rename to org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/PerThisAspect.java