From 0f4ab0a987b9168a9083406bec3340c25c2a5616 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Sat, 20 Dec 2008 22:30:29 +0000 Subject: [PATCH] polishing .aop tests --- .../AbstractAspectJAdvisorFactoryTests.java | 6 ++- .../aop/framework/AopProxyUtilsTests.java | 14 ++--- .../aop/framework/CountingBeforeAdvice.java | 34 ------------ .../framework/ExposedInvocationTestBean.java | 43 --------------- .../framework/IntroductionBenchmarkTests.java | 4 +- ...ocationCheckExposedInvocationTestBean.java | 31 ----------- .../aop/framework/MethodInvocationTests.java | 4 +- ...t.xml => PrototypeTargetTests-context.xml} | 0 .../aop/framework/PrototypeTargetTests.java | 13 +++-- .../aop/framework/ProxyFactoryTests.java | 52 +++++++++++++++++-- .../TimestampIntroductionInterceptor.java | 41 --------------- .../adapter/ThrowsAdviceInterceptorTests.java | 5 +- .../ConcurrencyThrottleInterceptorTests.java | 4 +- .../CustomizableTraceInterceptorTests.java | 2 +- .../interceptor/DebugInterceptorTests.java | 2 +- .../ExposeBeanNameAdvisorsTests.java | 4 +- ...oseInvocationInterceptorTests-context.xml} | 4 +- .../ExposeInvocationInterceptorTests.java | 40 ++++++++++++-- .../PerformanceMonitorInterceptorTests.java | 16 +++--- .../SimpleTraceInterceptorTests.java | 14 ++--- .../aop/support/AopUtilsTests.java | 3 +- .../aop/support/ControlFlowPointcutTests.java | 3 +- ...elegatingIntroductionInterceptorTests.java | 5 +- .../support/NameMatchMethodPointcutTests.java | 5 +- ...MethodPointcutAdvisorIntegrationTests.java | 5 +- .../aop/support/regexpSetterTests.xml | 2 +- .../target/HotSwappableTargetSourceTests.java | 2 +- .../aop/target/prototypeTests.xml | 2 +- .../aop/target/threadLocalTests.xml | 2 +- .../advice}/MethodCounter.java | 14 ++--- .../interceptor/NopInterceptor.java | 5 +- .../SerializableNopInterceptor.java | 7 ++- .../mixin}/DefaultLockable.java | 4 +- .../framework => test/mixin}/Lockable.java | 4 +- .../framework => test/util}/TimeStamped.java | 2 +- 35 files changed, 166 insertions(+), 232 deletions(-) delete mode 100644 org.springframework.aop/src/test/java/org/springframework/aop/framework/CountingBeforeAdvice.java delete mode 100644 org.springframework.aop/src/test/java/org/springframework/aop/framework/ExposedInvocationTestBean.java delete mode 100644 org.springframework.aop/src/test/java/org/springframework/aop/framework/InvocationCheckExposedInvocationTestBean.java rename org.springframework.aop/src/test/java/org/springframework/aop/framework/{prototypeTarget.xml => PrototypeTargetTests-context.xml} (100%) delete mode 100644 org.springframework.aop/src/test/java/org/springframework/aop/framework/TimestampIntroductionInterceptor.java rename org.springframework.aop/src/test/java/org/springframework/aop/interceptor/{exposeInvocation.xml => ExposeInvocationInterceptorTests-context.xml} (82%) rename org.springframework.aop/src/test/java/{org/springframework/aop/framework => test/advice}/MethodCounter.java (82%) rename org.springframework.aop/src/test/java/{org/springframework/aop => test}/interceptor/NopInterceptor.java (93%) rename org.springframework.aop/src/test/java/{org/springframework/aop => test}/interceptor/SerializableNopInterceptor.java (89%) rename org.springframework.aop/src/test/java/{org/springframework/aop/framework => test/mixin}/DefaultLockable.java (90%) rename org.springframework.aop/src/test/java/{org/springframework/aop/framework => test/mixin}/Lockable.java (88%) rename org.springframework.aop/src/test/java/{org/springframework/aop/framework => test/util}/TimeStamped.java (95%) diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java index 5c09f2956c..f3f043e618 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java @@ -42,8 +42,6 @@ import org.springframework.aop.Advisor; import org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.AopConfigException; -import org.springframework.aop.framework.DefaultLockable; -import org.springframework.aop.framework.Lockable; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.interceptor.ExposeInvocationInterceptor; import org.springframework.aop.support.AopUtils; @@ -56,6 +54,8 @@ import org.springframework.util.ObjectUtils; import test.aspect.PerTargetAspect; import test.aspect.TwoAdviceAspect; +import test.mixin.DefaultLockable; +import test.mixin.Lockable; /** * Abstract tests for AspectJAdvisorFactory. @@ -1025,6 +1025,8 @@ interface Modifiable { } + + class NotLockable { private int intValue; diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/AopProxyUtilsTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/framework/AopProxyUtilsTests.java index b70fea2b53..33bb6b4e9d 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/AopProxyUtilsTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/framework/AopProxyUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * 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. @@ -33,7 +33,7 @@ import org.springframework.beans.TestBean; * @author Rod Johnson * @author Chris Beams */ -public class AopProxyUtilsTests { +public final class AopProxyUtilsTests { @Test public void testCompleteProxiedInterfacesWorksWithNull() { @@ -124,7 +124,7 @@ public class AopProxyUtilsTests { assertEquals(Comparable.class, userInterfaces[1]); } - @Test + @Test(expected=IllegalArgumentException.class) public void testProxiedUserInterfacesWithNoInterface() { Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[0], new InvocationHandler() { @@ -132,13 +132,7 @@ public class AopProxyUtilsTests { return null; } }); - try { - AopProxyUtils.proxiedUserInterfaces(proxy); - fail("Should have thrown IllegalArgumentException"); - } - catch (IllegalArgumentException ex) { - // expected - } + AopProxyUtils.proxiedUserInterfaces(proxy); } } \ No newline at end of file diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/CountingBeforeAdvice.java b/org.springframework.aop/src/test/java/org/springframework/aop/framework/CountingBeforeAdvice.java deleted file mode 100644 index 3f391b2c68..0000000000 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/CountingBeforeAdvice.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2002-2005 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.framework; - -import java.lang.reflect.Method; - -import org.springframework.aop.MethodBeforeAdvice; - -/** - * Simple before advice example that we can use for counting checks. - * - * @author Rod Johnson - */ -public class CountingBeforeAdvice extends MethodCounter implements MethodBeforeAdvice { - - public void before(Method m, Object[] args, Object target) throws Throwable { - count(m); - } - -} \ No newline at end of file diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/ExposedInvocationTestBean.java b/org.springframework.aop/src/test/java/org/springframework/aop/framework/ExposedInvocationTestBean.java deleted file mode 100644 index 83f5617379..0000000000 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/ExposedInvocationTestBean.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2002-2005 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.framework; - -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.aop.interceptor.ExposeInvocationInterceptor; -import org.springframework.beans.TestBean; - - -/** - * Used to test ExposeInvocationInterceptor. - * @author Rod Johnson - */ -public abstract class ExposedInvocationTestBean extends TestBean { - - public String getName() { - MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); - assertions(invocation); - return super.getName(); - } - - public void absquatulate() { - MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); - assertions(invocation); - super.absquatulate(); - } - - protected abstract void assertions(MethodInvocation invocation); -} \ No newline at end of file diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/IntroductionBenchmarkTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/framework/IntroductionBenchmarkTests.java index 4067bfb028..c533c08acb 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/IntroductionBenchmarkTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/framework/IntroductionBenchmarkTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 the original author or authors. + * 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. @@ -31,7 +31,7 @@ import org.springframework.util.StopWatch; * @author Chris Beams * @since 2.0 */ -public class IntroductionBenchmarkTests { +public final class IntroductionBenchmarkTests { private static final int EXPECTED_COMPARE = 13; diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/InvocationCheckExposedInvocationTestBean.java b/org.springframework.aop/src/test/java/org/springframework/aop/framework/InvocationCheckExposedInvocationTestBean.java deleted file mode 100644 index d5c1edc876..0000000000 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/InvocationCheckExposedInvocationTestBean.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2002-2005 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.framework; - -import junit.framework.TestCase; - -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.beans.ITestBean; - - -public class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean { - protected void assertions(MethodInvocation invocation) { - TestCase.assertTrue(invocation.getThis() == this); - TestCase.assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(), - ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass())); - } -} \ No newline at end of file diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java index b8d8e3f60c..99502e2985 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 the original author or authors. + * 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. @@ -32,7 +32,7 @@ import org.springframework.beans.TestBean; * @author Chris Beams * @since 14.03.2003 */ -public class MethodInvocationTests { +public final class MethodInvocationTests { @Test public void testValidInvocation() throws Throwable { diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/prototypeTarget.xml b/org.springframework.aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests-context.xml similarity index 100% rename from org.springframework.aop/src/test/java/org/springframework/aop/framework/prototypeTarget.xml rename to org.springframework.aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests-context.xml diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java index 1241ee90ba..166332a0af 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 the original author or authors. + * 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. @@ -27,14 +27,19 @@ import org.springframework.core.io.ClassPathResource; /** * @author Juergen Hoeller + * @author Chris Beams * @since 03.09.2004 */ -public class PrototypeTargetTests { +public final class PrototypeTargetTests { + + private static final Class CLASS = PrototypeTargetTests.class; + private static final String CLASSNAME = CLASS.getSimpleName(); + private static final ClassPathResource CONTEXT = new ClassPathResource(CLASSNAME + "-context.xml", CLASS); @Test public void testPrototypeProxyWithPrototypeTarget() { TestBeanImpl.constructionCount = 0; - XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("prototypeTarget.xml", getClass())); + XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT); for (int i = 0; i < 10; i++) { TestBean tb = (TestBean) xbf.getBean("testBeanPrototype"); tb.doSomething(); @@ -47,7 +52,7 @@ public class PrototypeTargetTests { @Test public void testSingletonProxyWithPrototypeTarget() { TestBeanImpl.constructionCount = 0; - XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("prototypeTarget.xml", getClass())); + XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT); for (int i = 0; i < 10; i++) { TestBean tb = (TestBean) xbf.getBean("testBeanSingleton"); tb.doSomething(); diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/ProxyFactoryTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/framework/ProxyFactoryTests.java index 4866d03243..c778802f8d 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/ProxyFactoryTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/framework/ProxyFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * 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. @@ -20,19 +20,26 @@ package org.springframework.aop.framework; import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.*; +import java.lang.reflect.Method; + import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.junit.Test; import org.springframework.aop.Advisor; +import org.springframework.aop.MethodBeforeAdvice; import org.springframework.aop.interceptor.DebugInterceptor; -import org.springframework.aop.interceptor.NopInterceptor; import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.DefaultIntroductionAdvisor; import org.springframework.aop.support.DefaultPointcutAdvisor; +import org.springframework.aop.support.DelegatingIntroductionInterceptor; import org.springframework.beans.IOther; import org.springframework.beans.ITestBean; import org.springframework.beans.TestBean; +import test.advice.MethodCounter; +import test.interceptor.NopInterceptor; +import test.util.TimeStamped; + /** * Also tests AdvisedSupport and ProxyCreatorSupport superclasses. * @@ -41,7 +48,7 @@ import org.springframework.beans.TestBean; * @author Chris Beams * @since 14.05.2003 */ -public class ProxyFactoryTests { +public final class ProxyFactoryTests { @Test public void testIndexOfMethods() { @@ -311,3 +318,42 @@ public class ProxyFactoryTests { } } + + +/** + * Simple before advice example that we can use for counting checks. + * + * @author Rod Johnson + */ +@SuppressWarnings("serial") +class CountingBeforeAdvice extends MethodCounter implements MethodBeforeAdvice { + + public void before(Method m, Object[] args, Object target) throws Throwable { + count(m); + } + +} + + +@SuppressWarnings("serial") +class TimestampIntroductionInterceptor extends DelegatingIntroductionInterceptor + implements TimeStamped { + + private long ts; + + public TimestampIntroductionInterceptor() { + } + + public TimestampIntroductionInterceptor(long ts) { + this.ts = ts; + } + + public void setTime(long ts) { + this.ts = ts; + } + + public long getTimeStamp() { + return ts; + } + +} diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/TimestampIntroductionInterceptor.java b/org.springframework.aop/src/test/java/org/springframework/aop/framework/TimestampIntroductionInterceptor.java deleted file mode 100644 index 2584d2575c..0000000000 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/TimestampIntroductionInterceptor.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2002-2005 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.framework; - -import org.springframework.aop.support.DelegatingIntroductionInterceptor; - -public class TimestampIntroductionInterceptor extends DelegatingIntroductionInterceptor - implements TimeStamped { - - private long ts; - - public TimestampIntroductionInterceptor() { - } - - public TimestampIntroductionInterceptor(long ts) { - this.ts = ts; - } - - public void setTime(long ts) { - this.ts = ts; - } - - public long getTimeStamp() { - return ts; - } - -} diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java index fa9499fe5f..943535713a 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java @@ -34,7 +34,8 @@ import org.aopalliance.intercept.MethodInvocation; import org.junit.Ignore; import org.junit.Test; import org.springframework.aop.ThrowsAdvice; -import org.springframework.aop.framework.MethodCounter; + +import test.advice.MethodCounter; /** * Unit tests for {@link ThrowsAdviceInterceptor} @@ -42,7 +43,7 @@ import org.springframework.aop.framework.MethodCounter; * @author Rod Johnson * @author Chris Beams */ -public class ThrowsAdviceInterceptorTests { +public final class ThrowsAdviceInterceptorTests { @Test(expected=IllegalArgumentException.class) public void testNoHandlerMethods() { diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java index 49f143e034..2e7b84ffb0 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 the original author or authors. + * 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. @@ -34,7 +34,7 @@ import org.springframework.util.SerializationTestUtils; * @author Chris Beams * @since 06.04.2004 */ -public class ConcurrencyThrottleInterceptorTests { +public final class ConcurrencyThrottleInterceptorTests { protected static final Log logger = LogFactory.getLog(ConcurrencyThrottleInterceptorTests.class); diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java index da7d051631..1fe27b3dfc 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java @@ -31,7 +31,7 @@ import org.junit.Test; * @author Juergen Hoeller * @author Chris Beams */ -public class CustomizableTraceInterceptorTests { +public final class CustomizableTraceInterceptorTests { @Test(expected=IllegalArgumentException.class) public void testSetEmptyEnterMessage() { diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/DebugInterceptorTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/DebugInterceptorTests.java index 85f4a43c09..471e69930c 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/DebugInterceptorTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/DebugInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * 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. diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisorsTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisorsTests.java index 67bcbd0e0d..3ae9f408ba 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisorsTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisorsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * 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. @@ -28,7 +28,7 @@ import org.springframework.beans.factory.NamedBean; * @author Rod Johnson * @author Chris Beams */ -public class ExposeBeanNameAdvisorsTests { +public final class ExposeBeanNameAdvisorsTests { private class RequiresBeanNameBoundTestBean extends TestBean { private final String beanName; diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/exposeInvocation.xml b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests-context.xml similarity index 82% rename from org.springframework.aop/src/test/java/org/springframework/aop/interceptor/exposeInvocation.xml rename to org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests-context.xml index a44795f043..a3ce25dd04 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/exposeInvocation.xml +++ b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests-context.xml @@ -6,7 +6,7 @@ --> - + @@ -19,7 +19,7 @@ - + exposeInvocation,countingBeforeAdvice,nopInterceptor diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java index afb8d8f41b..9f53a141dc 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 the original author or authors. + * 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. @@ -17,23 +17,30 @@ package org.springframework.aop.interceptor; import static org.junit.Assert.assertEquals; +import junit.framework.TestCase; +import org.aopalliance.intercept.MethodInvocation; import org.junit.Test; import org.springframework.beans.ITestBean; +import org.springframework.beans.TestBean; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; /** * Non-XML tests are in AbstractAopProxyTests + * * @author Rod Johnson * @author Chris Beams */ public class ExposeInvocationInterceptorTests { + + private static final Class CLASS = ExposeInvocationInterceptorTests.class; + private static final ClassPathResource CONTEXT = + new ClassPathResource(CLASS.getSimpleName() + "-context.xml", CLASS); @Test public void testXmlConfig() { - XmlBeanFactory bf = new XmlBeanFactory( - new ClassPathResource("org/springframework/aop/interceptor/exposeInvocation.xml")); + XmlBeanFactory bf = new XmlBeanFactory(CONTEXT); ITestBean tb = (ITestBean) bf.getBean("proxy"); String name= "tony"; tb.setName(name); @@ -42,3 +49,30 @@ public class ExposeInvocationInterceptorTests { } } + + +abstract class ExposedInvocationTestBean extends TestBean { + + public String getName() { + MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); + assertions(invocation); + return super.getName(); + } + + public void absquatulate() { + MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); + assertions(invocation); + super.absquatulate(); + } + + protected abstract void assertions(MethodInvocation invocation); +} + + +class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean { + protected void assertions(MethodInvocation invocation) { + TestCase.assertTrue(invocation.getThis() == this); + TestCase.assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(), + ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass())); + } +} diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/PerformanceMonitorInterceptorTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/PerformanceMonitorInterceptorTests.java index e13eaeef7c..5cc35f10ec 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/PerformanceMonitorInterceptorTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/PerformanceMonitorInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * 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. @@ -30,7 +30,7 @@ import org.junit.Test; * @author Rick Evans * @author Chris Beams */ -public class PerformanceMonitorInterceptorTests { +public final class PerformanceMonitorInterceptorTests { @Test public void testSuffixAndPrefixAssignment() { @@ -57,14 +57,12 @@ public class PerformanceMonitorInterceptorTests { expect(mi.proceed()).andReturn(null); log.trace(isA(String.class)); - replay(mi); - replay(log); + replay(mi, log); PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true); interceptor.invokeUnderTrace(mi, log); - verify(log); - verify(mi); + verify(mi, log); } @Test @@ -78,8 +76,7 @@ public class PerformanceMonitorInterceptorTests { expect(mi.proceed()).andThrow(new IllegalArgumentException()); log.trace(isA(String.class)); - replay(mi); - replay(log); + replay(mi, log); PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true); try { @@ -89,8 +86,7 @@ public class PerformanceMonitorInterceptorTests { catch (IllegalArgumentException expected) { } - verify(log); - verify(mi); + verify(mi, log); } } diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java index 5c441c1da8..b3fe5185c1 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * 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. @@ -46,14 +46,12 @@ public final class SimpleTraceInterceptorTests { expect(mi.proceed()).andReturn(null); log.trace(isA(String.class)); - replay(log); - replay(mi); + replay(mi, log); SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true); interceptor.invokeUnderTrace(mi, log); - verify(log); - verify(mi); + verify(mi, log); } public void testExceptionPathStillLogsCorrectly() throws Throwable { @@ -69,8 +67,7 @@ public final class SimpleTraceInterceptorTests { expect(mi.proceed()).andThrow(exception); log.trace(isA(String.class)); - replay(log); - replay(mi); + replay(mi, log); final SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true); @@ -80,8 +77,7 @@ public final class SimpleTraceInterceptorTests { } catch (IllegalArgumentException expected) { } - verify(log); - verify(mi); + verify(mi, log); } } diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java index 6456d925c7..576e335229 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java @@ -25,11 +25,12 @@ import org.springframework.aop.ClassFilter; import org.springframework.aop.MethodMatcher; import org.springframework.aop.Pointcut; import org.springframework.aop.interceptor.ExposeInvocationInterceptor; -import org.springframework.aop.interceptor.NopInterceptor; import org.springframework.aop.target.EmptyTargetSource; import org.springframework.beans.TestBean; import org.springframework.util.SerializationTestUtils; +import test.interceptor.NopInterceptor; + /** * @author Rod Johnson * @author Chris Beams diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java index 940c2824ed..469274e699 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java @@ -21,10 +21,11 @@ import static org.junit.Assert.*; import org.junit.Test; import org.springframework.aop.Pointcut; import org.springframework.aop.framework.ProxyFactory; -import org.springframework.aop.interceptor.NopInterceptor; import org.springframework.beans.ITestBean; import org.springframework.beans.TestBean; +import test.interceptor.NopInterceptor; + /** * @author Rod Johnson * @author Chris Beams diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java index a3d4f35953..4a3a5d7e3a 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java @@ -26,8 +26,6 @@ import org.junit.Test; import org.springframework.aop.IntroductionAdvisor; import org.springframework.aop.IntroductionInterceptor; import org.springframework.aop.framework.ProxyFactory; -import org.springframework.aop.framework.TimeStamped; -import org.springframework.aop.interceptor.SerializableNopInterceptor; import org.springframework.beans.INestedTestBean; import org.springframework.beans.ITestBean; import org.springframework.beans.NestedTestBean; @@ -36,6 +34,9 @@ import org.springframework.beans.SerializablePerson; import org.springframework.beans.TestBean; import org.springframework.util.SerializationTestUtils; +import test.interceptor.SerializableNopInterceptor; +import test.util.TimeStamped; + /** * @author Rod Johnson * @author Chris Beams diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java index f594304c6a..b6e24bc829 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java @@ -22,12 +22,13 @@ import org.junit.Before; import org.junit.Test; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; -import org.springframework.aop.interceptor.NopInterceptor; -import org.springframework.aop.interceptor.SerializableNopInterceptor; import org.springframework.beans.Person; import org.springframework.beans.SerializablePerson; import org.springframework.util.SerializationTestUtils; +import test.interceptor.NopInterceptor; +import test.interceptor.SerializableNopInterceptor; + /** * @author Rod Johnson * @author Chris Beams diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java index 9499ea4d1d..3c1736a907 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java @@ -20,8 +20,6 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.springframework.aop.framework.Advised; -import org.springframework.aop.interceptor.NopInterceptor; -import org.springframework.aop.interceptor.SerializableNopInterceptor; import org.springframework.beans.ITestBean; import org.springframework.beans.Person; import org.springframework.beans.TestBean; @@ -30,6 +28,9 @@ import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.util.SerializationTestUtils; +import test.interceptor.NopInterceptor; +import test.interceptor.SerializableNopInterceptor; + /** * @author Rod Johnson * @author Chris Beams diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/support/regexpSetterTests.xml b/org.springframework.aop/src/test/java/org/springframework/aop/support/regexpSetterTests.xml index 2d14f2dc0c..9633d44244 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/support/regexpSetterTests.xml +++ b/org.springframework.aop/src/test/java/org/springframework/aop/support/regexpSetterTests.xml @@ -9,7 +9,7 @@ 666 - + diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java b/org.springframework.aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java index 865e5f1f3a..c26460c2c2 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java +++ b/org.springframework.aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java @@ -23,7 +23,6 @@ import org.junit.Before; import org.junit.Test; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; -import org.springframework.aop.interceptor.SerializableNopInterceptor; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.beans.Person; import org.springframework.beans.SerializablePerson; @@ -32,6 +31,7 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.util.SerializationTestUtils; import test.beans.SideEffectBean; +import test.interceptor.SerializableNopInterceptor; /** diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/target/prototypeTests.xml b/org.springframework.aop/src/test/java/org/springframework/aop/target/prototypeTests.xml index 524fa79677..84703ecdc7 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/target/prototypeTests.xml +++ b/org.springframework.aop/src/test/java/org/springframework/aop/target/prototypeTests.xml @@ -16,7 +16,7 @@ prototypeTest - + debugInterceptor,test diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/target/threadLocalTests.xml b/org.springframework.aop/src/test/java/org/springframework/aop/target/threadLocalTests.xml index 20b4844304..a20ef2788b 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/target/threadLocalTests.xml +++ b/org.springframework.aop/src/test/java/org/springframework/aop/target/threadLocalTests.xml @@ -11,7 +11,7 @@ prototypeTest - + count, does not understand overloading */ - private HashMap map = new HashMap(); + private HashMap map = new HashMap(); private int allCount; @@ -37,14 +39,14 @@ public class MethodCounter implements Serializable { } protected void count(String methodName) { - Integer i = (Integer) map.get(methodName); + Integer i = map.get(methodName); i = (i != null) ? new Integer(i.intValue() + 1) : new Integer(1); map.put(methodName, i); ++allCount; } public int getCalls(String methodName) { - Integer i = (Integer) map.get(methodName); + Integer i = map.get(methodName); return (i != null ? i.intValue() : 0); } diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/NopInterceptor.java b/org.springframework.aop/src/test/java/test/interceptor/NopInterceptor.java similarity index 93% rename from org.springframework.aop/src/test/java/org/springframework/aop/interceptor/NopInterceptor.java rename to org.springframework.aop/src/test/java/test/interceptor/NopInterceptor.java index 6bbbc4ff17..dcd9c53eca 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/NopInterceptor.java +++ b/org.springframework.aop/src/test/java/test/interceptor/NopInterceptor.java @@ -1,6 +1,5 @@ - /* - * Copyright 2002-2005 the original author or authors. + * 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. @@ -15,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.interceptor; +package test.interceptor; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/SerializableNopInterceptor.java b/org.springframework.aop/src/test/java/test/interceptor/SerializableNopInterceptor.java similarity index 89% rename from org.springframework.aop/src/test/java/org/springframework/aop/interceptor/SerializableNopInterceptor.java rename to org.springframework.aop/src/test/java/test/interceptor/SerializableNopInterceptor.java index 328f6cf9b2..67d1f23e9e 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/interceptor/SerializableNopInterceptor.java +++ b/org.springframework.aop/src/test/java/test/interceptor/SerializableNopInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 the original author or authors. + * 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. @@ -14,17 +14,20 @@ * limitations under the License. */ -package org.springframework.aop.interceptor; +package test.interceptor; import java.io.Serializable; + /** * Subclass of NopInterceptor that is serializable and * can be used to test proxy serialization. * * @author Rod Johnson + * @author Chris Beams */ +@SuppressWarnings("serial") public class SerializableNopInterceptor extends NopInterceptor implements Serializable { /** diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/DefaultLockable.java b/org.springframework.aop/src/test/java/test/mixin/DefaultLockable.java similarity index 90% rename from org.springframework.aop/src/test/java/org/springframework/aop/framework/DefaultLockable.java rename to org.springframework.aop/src/test/java/test/mixin/DefaultLockable.java index b3237f9d29..77c7e96c56 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/DefaultLockable.java +++ b/org.springframework.aop/src/test/java/test/mixin/DefaultLockable.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 the original author or authors. + * 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. @@ -14,7 +14,7 @@ * limitations under the License. */ - package org.springframework.aop.framework; +package test.mixin; /** * Simple implementation of Lockable interface for use in mixins. diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/Lockable.java b/org.springframework.aop/src/test/java/test/mixin/Lockable.java similarity index 88% rename from org.springframework.aop/src/test/java/org/springframework/aop/framework/Lockable.java rename to org.springframework.aop/src/test/java/test/mixin/Lockable.java index 70d6b2cfa5..75b3e3c51c 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/Lockable.java +++ b/org.springframework.aop/src/test/java/test/mixin/Lockable.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 the original author or authors. + * 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.mixin; /** diff --git a/org.springframework.aop/src/test/java/org/springframework/aop/framework/TimeStamped.java b/org.springframework.aop/src/test/java/test/util/TimeStamped.java similarity index 95% rename from org.springframework.aop/src/test/java/org/springframework/aop/framework/TimeStamped.java rename to org.springframework.aop/src/test/java/test/util/TimeStamped.java index e514210ec1..958d8b21f9 100644 --- a/org.springframework.aop/src/test/java/org/springframework/aop/framework/TimeStamped.java +++ b/org.springframework.aop/src/test/java/test/util/TimeStamped.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.util; /** * This interface can be implemented by cacheable objects or cache entries,