moving unit tests from .testsuite -> .aop

This commit is contained in:
Chris Beams 2008-12-12 18:08:15 +00:00
parent c563f97b90
commit 3c0015c1ec
6 changed files with 35 additions and 57 deletions

View File

@ -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()
*/

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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;
}
}

View File

@ -9,29 +9,18 @@
<beans>
<!-- Simple target -->
<bean id="target" class="org.springframework.aop.framework.adapter.ThrowsAdviceInterceptorTests$Echo">
</bean>
<bean id="target" class="org.springframework.aop.framework.Echo"/>
<bean id="nopInterceptor" class="org.springframework.aop.interceptor.NopInterceptor">
</bean>
<bean id="nopInterceptor" class="org.springframework.aop.interceptor.NopInterceptor"/>
<bean id="countingBeforeAdvice"
class="org.springframework.aop.framework.CountingBeforeAdvice"
/>
<bean id="throwsAdvice"
class="org.springframework.aop.framework.adapter.ThrowsAdviceInterceptorTests$MyThrowsHandler">
</bean>
<bean id="countingBeforeAdvice" class="org.springframework.aop.framework.CountingBeforeAdvice" />
<bean id="throwsAdvice" class="org.springframework.aop.framework.MyThrowsHandler"/>
<bean id="throwsAdvised"
class="org.springframework.aop.framework.ProxyFactoryBean"
>
<bean id="throwsAdvised" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="interceptorNames">
<value>countingBeforeAdvice,nopInterceptor,throwsAdvice,target</value>
</property>
</bean>
</beans>
</beans>