From 3c0015c1ec09e858ddc518af5629531399114883 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Fri, 12 Dec 2008 18:08:15 +0000 Subject: [PATCH] moving unit tests from .testsuite -> .aop --- .../aop/framework/AbstractAopProxyTests.java | 4 ++- .../aop/framework/CglibProxyTests.java | 6 +++-- .../aop/framework/JdkDynamicProxyTests.java | 25 ++++++++----------- .../aop/framework/ProxyFactoryBeanTests.java | 12 ++++----- .../AdvisorAdapterRegistrationTests.java | 22 +++++----------- .../aop/framework/throwsAdvice.xml | 23 +++++------------ 6 files changed, 35 insertions(+), 57 deletions(-) diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java index 081ee34b8a4..88ba4613b9d 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java @@ -68,6 +68,7 @@ import org.springframework.util.StopWatch; /** * @author Rod Johnson * @author Juergen Hoeller + * @author Chris Beams * @since 13.03.2003 */ public abstract class AbstractAopProxyTests { @@ -800,7 +801,8 @@ public abstract class AbstractAopProxyTests { target.setAge(21); ProxyFactory pc = new ProxyFactory(target); - class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped { + @SuppressWarnings("serial") + class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped { /** * @see org.springframework.aop.framework.TimeStamped#getTimeStamp() */ diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibProxyTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibProxyTests.java index d4721595fc0..75415c4080a 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibProxyTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibProxyTests.java @@ -16,6 +16,7 @@ package org.springframework.aop.framework; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.*; import java.io.Serializable; @@ -43,6 +44,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * @author Juergen Hoeller * @author Rob Harrop * @author Ramnivas Laddad + * @author Chris Beams */ public class CglibProxyTests extends AbstractAopProxyTests { @@ -65,7 +67,7 @@ public class CglibProxyTests extends AbstractAopProxyTests { @Test public void testNullConfig() { try { - AopProxy aop = new Cglib2AopProxy(null); + new Cglib2AopProxy(null); fail("Shouldn't allow null interceptors"); } catch (IllegalArgumentException ex) { @@ -276,7 +278,7 @@ public class CglibProxyTests extends AbstractAopProxyTests { as.addAdvice(new NopInterceptor()); cglib = new Cglib2AopProxy(as); - ITestBean proxy2 = (ITestBean) cglib.getProxy(); + assertThat(cglib.getProxy(), instanceOf(ITestBean.class)); } @Test diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java index 40308bba269..96233abea46 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java @@ -16,11 +16,14 @@ package org.springframework.aop.framework; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; import static org.junit.Assert.*; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; -import org.easymock.MockControl; import org.springframework.aop.interceptor.ExposeInvocationInterceptor; import org.springframework.aop.support.AopUtils; @@ -31,6 +34,7 @@ import org.springframework.beans.TestBean; /** * @author Rod Johnson * @author Juergen Hoeller + * @author Chris Beams * @since 13.03.2003 */ public class JdkDynamicProxyTests extends AbstractAopProxyTests { @@ -48,7 +52,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests { public void testNullConfig() { try { - JdkDynamicAopProxy aop = new JdkDynamicAopProxy(null); + new JdkDynamicAopProxy(null); fail("Shouldn't allow null interceptors"); } catch (IllegalArgumentException ex) { @@ -71,27 +75,18 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests { public void testInterceptorIsInvokedWithNoTarget() throws Throwable { // Test return value int age = 25; - MockControl miControl = MockControl.createControl(MethodInterceptor.class); - MethodInterceptor mi = (MethodInterceptor) miControl.getMock(); + MethodInterceptor mi = createMock(MethodInterceptor.class); AdvisedSupport pc = new AdvisedSupport(new Class[] { ITestBean.class }); pc.addAdvice(mi); AopProxy aop = createAopProxy(pc); - // Really would like to permit null arg:can't get exact mi - mi.invoke(null); - //mi.invoke(new MethodInvocationImpl(aop, null, ITestBean.class, - // ITestBean.class.getMethod("getAge", null), - // null, l, r)); - //miControl. - //miControl.setReturnValue(new Integer(age)); - // Have disabled strong argument checking - miControl.setDefaultReturnValue(new Integer(age)); - miControl.replay(); + expect(mi.invoke(null)).andReturn(age); + replay(mi); ITestBean tb = (ITestBean) aop.getProxy(); assertTrue("correct return value", tb.getAge() == age); - miControl.verify(); + verify(mi); } public void testTargetCanGetInvocationWithPrivateClass() throws Throwable { diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java index d5596967088..10cf28b66cd 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java @@ -16,18 +16,18 @@ package org.springframework.aop.framework; +import java.io.FileNotFoundException; +import java.io.IOException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.LinkedList; import java.util.List; -import javax.servlet.ServletException; - import junit.framework.TestCase; + import org.aopalliance.aop.Advice; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; - import org.springframework.aop.ClassFilter; import org.springframework.aop.IntroductionAdvisor; import org.springframework.aop.IntroductionInterceptor; @@ -425,16 +425,16 @@ public class ProxyFactoryBeanTests extends TestCase { assertEquals(0, th.getCalls()); // Handler knows how to handle this exception - expected = new ServletException(); + expected = new FileNotFoundException(); try { echo.echoException(1, expected); fail(); } - catch (ServletException ex) { + catch (IOException ex) { assertEquals(expected, ex); } // One match - assertEquals(1, th.getCalls("servletException")); + assertEquals(1, th.getCalls("ioException")); } // These two fail the whole bean factory diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java index 63bdb88bed4..10df4fa2ba0 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java @@ -16,10 +16,10 @@ package org.springframework.aop.framework.adapter; -import junit.framework.*; +import static org.junit.Assert.*; +import org.junit.Test; import org.springframework.aop.*; -import org.springframework.aop.support.*; import org.springframework.aop.framework.Advised; import org.springframework.beans.ITestBean; import org.springframework.context.ApplicationContext; @@ -29,13 +29,11 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * TestCase for AdvisorAdapterRegistrationManager mechanism. * * @author Dmitriy Kopylenko + * @author Chris Beams */ -public class AdvisorAdapterRegistrationTests extends TestCase { - - public AdvisorAdapterRegistrationTests(String name) { - super(name); - } +public class AdvisorAdapterRegistrationTests { + @Test public void testAdvisorAdapterRegistrationManagerNotPresentInContext() { ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withoutBPPContext.xml"); ITestBean tb = (ITestBean) ctx.getBean("testBean"); @@ -50,6 +48,7 @@ public class AdvisorAdapterRegistrationTests extends TestCase { } } + @Test public void testAdvisorAdapterRegistrationManagerPresentInContext() { ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withBPPContext.xml"); ITestBean tb = (ITestBean) ctx.getBean("testBean"); @@ -69,13 +68,4 @@ public class AdvisorAdapterRegistrationTests extends TestCase { return (SimpleBeforeAdviceImpl) advisor.getAdvice(); } - // temporary suite method to make tests work on JRockit! - // Alef knows more about this. - public static Test suite() { - TestSuite suite = new TestSuite(); - suite.addTest(new AdvisorAdapterRegistrationTests("testAdvisorAdapterRegistrationManagerNotPresentInContext")); - suite.addTest(new AdvisorAdapterRegistrationTests("testAdvisorAdapterRegistrationManagerPresentInContext")); - return suite; - } - } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/throwsAdvice.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/throwsAdvice.xml index 5185ae39299..e70d7b4e8e5 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/throwsAdvice.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/throwsAdvice.xml @@ -9,29 +9,18 @@ - - + - - + - - - - + + - + countingBeforeAdvice,nopInterceptor,throwsAdvice,target - - - \ No newline at end of file + \ No newline at end of file