polishing .aop tests

This commit is contained in:
Chris Beams 2008-12-20 23:01:02 +00:00
parent 0f4ab0a987
commit 5dd4e5220a
33 changed files with 107 additions and 80 deletions

View File

@ -27,7 +27,8 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.DerivedTestBean; import org.springframework.beans.DerivedTestBean;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
import test.util.SerializationTestUtils;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
* Unit tests for the {@link DefaultScopedObject} class. * Unit tests for the {@link DefaultScopedObject} class.
* *
* @author Rick Evans * @author Rick Evans
* @author Chris Beams
*/ */
public final class DefaultScopedObjectTests { public final class DefaultScopedObjectTests {

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,11 +26,19 @@ import org.springframework.core.io.ClassPathResource;
* @author Mark Fisher * @author Mark Fisher
* @author Chris Beams * @author Chris Beams
*/ */
public class ScopedProxyAutowireTests { public final class ScopedProxyAutowireTests {
private static final Class<?> CLASS = ScopedProxyAutowireTests.class;
private static final String CLASSNAME = CLASS.getSimpleName();
private static final ClassPathResource SCOPED_AUTOWIRE_TRUE_CONTEXT =
new ClassPathResource(CLASSNAME + "-scopedAutowireTrue.xml", CLASS);
private static final ClassPathResource SCOPED_AUTOWIRE_FALSE_CONTEXT =
new ClassPathResource(CLASSNAME + "-scopedAutowireFalse.xml", CLASS);
@Test @Test
public void testScopedProxyInheritsAutowireCandidateFalse() { public void testScopedProxyInheritsAutowireCandidateFalse() {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("scopedAutowireFalse.xml", getClass())); XmlBeanFactory bf = new XmlBeanFactory(SCOPED_AUTOWIRE_FALSE_CONTEXT);
TestBean autowired = (TestBean) bf.getBean("autowired"); TestBean autowired = (TestBean) bf.getBean("autowired");
TestBean unscoped = (TestBean) bf.getBean("unscoped"); TestBean unscoped = (TestBean) bf.getBean("unscoped");
assertSame(unscoped, autowired.getChild()); assertSame(unscoped, autowired.getChild());
@ -38,7 +46,7 @@ public class ScopedProxyAutowireTests {
@Test @Test
public void testScopedProxyReplacesAutowireCandidateTrue() { public void testScopedProxyReplacesAutowireCandidateTrue() {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("scopedAutowireTrue.xml", getClass())); XmlBeanFactory bf = new XmlBeanFactory(SCOPED_AUTOWIRE_TRUE_CONTEXT);
TestBean autowired = (TestBean) bf.getBean("autowired"); TestBean autowired = (TestBean) bf.getBean("autowired");
TestBean scoped = (TestBean) bf.getBean("scoped"); TestBean scoped = (TestBean) bf.getBean("scoped");
assertSame(scoped, autowired.getChild()); assertSame(scoped, autowired.getChild());

View File

@ -23,7 +23,8 @@ import java.io.IOException;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
import test.util.SerializationTestUtils;
/** /**
* @author Rod Johnson * @author Rod Johnson

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,15 +27,15 @@ import org.springframework.aop.Pointcut;
import org.springframework.aop.interceptor.ExposeInvocationInterceptor; import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.aop.target.EmptyTargetSource; import org.springframework.aop.target.EmptyTargetSource;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
import test.interceptor.NopInterceptor; import test.interceptor.NopInterceptor;
import test.util.SerializationTestUtils;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class AopUtilsTests { public final class AopUtilsTests {
@Test @Test
public void testPointcutCanNeverApply() { public void testPointcutCanNeverApply() {

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +28,7 @@ import org.springframework.core.NestedRuntimeException;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class ClassFiltersTests { public final class ClassFiltersTests {
private ClassFilter exceptionFilter = new RootClassFilter(Exception.class); private ClassFilter exceptionFilter = new RootClassFilter(Exception.class);

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,7 +31,7 @@ import org.springframework.core.NestedRuntimeException;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class ComposablePointcutTests { public final class ComposablePointcutTests {
public static MethodMatcher GETTER_METHOD_MATCHER = new StaticMethodMatcher() { public static MethodMatcher GETTER_METHOD_MATCHER = new StaticMethodMatcher() {
public boolean matches(Method m, Class<?> targetClass) { public boolean matches(Method m, Class<?> targetClass) {

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ import test.interceptor.NopInterceptor;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class ControlFlowPointcutTests { public final class ControlFlowPointcutTests {
@Test @Test
public void testMatches() { public void testMatches() {

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,9 +32,9 @@ import org.springframework.beans.NestedTestBean;
import org.springframework.beans.Person; import org.springframework.beans.Person;
import org.springframework.beans.SerializablePerson; import org.springframework.beans.SerializablePerson;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
import test.interceptor.SerializableNopInterceptor; import test.interceptor.SerializableNopInterceptor;
import test.util.SerializationTestUtils;
import test.util.TimeStamped; import test.util.TimeStamped;
/** /**
@ -42,7 +42,7 @@ import test.util.TimeStamped;
* @author Chris Beams * @author Chris Beams
* @since 13.05.2003 * @since 13.05.2003
*/ */
public class DelegatingIntroductionInterceptorTests { public final class DelegatingIntroductionInterceptorTests {
@Test(expected=IllegalArgumentException.class) @Test(expected=IllegalArgumentException.class)
public void testNullTarget() throws Exception { public void testNullTarget() throws Exception {

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,7 +19,7 @@ package org.springframework.aop.support;
/** /**
* @author Dmitriy Kopylenko * @author Dmitriy Kopylenko
*/ */
public class JdkRegexpMethodPointcutTests extends AbstractRegexpMethodPointcutTests { public final class JdkRegexpMethodPointcutTests extends AbstractRegexpMethodPointcutTests {
protected AbstractRegexpMethodPointcut getRegexpMethodPointcut() { protected AbstractRegexpMethodPointcut getRegexpMethodPointcut() {
return new JdkRegexpMethodPointcut(); return new JdkRegexpMethodPointcut();

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,13 +25,14 @@ import org.springframework.aop.MethodMatcher;
import org.springframework.beans.IOther; import org.springframework.beans.IOther;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
import test.util.SerializationTestUtils;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class MethodMatchersTests { public final class MethodMatchersTests {
private final Method EXCEPTION_GETMESSAGE; private final Method EXCEPTION_GETMESSAGE;
@ -106,20 +107,20 @@ public class MethodMatchersTests {
public StartsWithMatcher(String s) { public StartsWithMatcher(String s) {
this.prefix = s; this.prefix = s;
} }
public boolean matches(Method m, Class targetClass) { public boolean matches(Method m, Class<?> targetClass) {
return m.getName().startsWith(prefix); return m.getName().startsWith(prefix);
} }
} }
private static class TestDynamicMethodMatcherWhichMatches extends DynamicMethodMatcher { private static class TestDynamicMethodMatcherWhichMatches extends DynamicMethodMatcher {
public boolean matches(Method m, Class targetClass, Object[] args) { public boolean matches(Method m, Class<?> targetClass, Object[] args) {
return true; return true;
} }
} }
private static class TestDynamicMethodMatcherWhichDoesNotMatch extends DynamicMethodMatcher { private static class TestDynamicMethodMatcherWhichDoesNotMatch extends DynamicMethodMatcher {
public boolean matches(Method m, Class targetClass, Object[] args) { public boolean matches(Method m, Class<?> targetClass, Object[] args) {
return false; return false;
} }
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,16 +24,16 @@ import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.Person; import org.springframework.beans.Person;
import org.springframework.beans.SerializablePerson; import org.springframework.beans.SerializablePerson;
import org.springframework.util.SerializationTestUtils;
import test.interceptor.NopInterceptor; import test.interceptor.NopInterceptor;
import test.interceptor.SerializableNopInterceptor; import test.interceptor.SerializableNopInterceptor;
import test.util.SerializationTestUtils;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class NameMatchMethodPointcutTests { public final class NameMatchMethodPointcutTests {
protected NameMatchMethodPointcut pc; protected NameMatchMethodPointcut pc;

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,7 @@ import org.springframework.beans.TestBean;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class PointcutsTests { public final class PointcutsTests {
public static Method TEST_BEAN_SET_AGE; public static Method TEST_BEAN_SET_AGE;
public static Method TEST_BEAN_GET_AGE; public static Method TEST_BEAN_GET_AGE;

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,20 +26,26 @@ import org.springframework.beans.TestBean;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.util.SerializationTestUtils;
import test.interceptor.NopInterceptor; import test.interceptor.NopInterceptor;
import test.interceptor.SerializableNopInterceptor; import test.interceptor.SerializableNopInterceptor;
import test.util.SerializationTestUtils;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class RegexpMethodPointcutAdvisorIntegrationTests { public final class RegexpMethodPointcutAdvisorIntegrationTests {
private static final Class<?> CLASS = RegexpMethodPointcutAdvisorIntegrationTests.class;
private static final String CLASSNAME = CLASS.getSimpleName();
private static final ClassPathResource CONTEXT =
new ClassPathResource(CLASSNAME + "-context.xml", CLASS);
@Test @Test
public void testSinglePattern() throws Throwable { public void testSinglePattern() throws Throwable {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource("regexpSetterTests.xml", getClass())); BeanFactory bf = new XmlBeanFactory(CONTEXT);
ITestBean advised = (ITestBean) bf.getBean("settersAdvised"); ITestBean advised = (ITestBean) bf.getBean("settersAdvised");
// Interceptor behind regexp advisor // Interceptor behind regexp advisor
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor"); NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
@ -57,7 +63,7 @@ public class RegexpMethodPointcutAdvisorIntegrationTests {
@Test @Test
public void testMultiplePatterns() throws Throwable { public void testMultiplePatterns() throws Throwable {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource("regexpSetterTests.xml", getClass())); BeanFactory bf = new XmlBeanFactory(CONTEXT);
// This is a CGLIB proxy, so we can proxy it to the target class // This is a CGLIB proxy, so we can proxy it to the target class
TestBean advised = (TestBean) bf.getBean("settersAndAbsquatulateAdvised"); TestBean advised = (TestBean) bf.getBean("settersAndAbsquatulateAdvised");
// Interceptor behind regexp advisor // Interceptor behind regexp advisor
@ -80,7 +86,7 @@ public class RegexpMethodPointcutAdvisorIntegrationTests {
@Test @Test
public void testSerialization() throws Throwable { public void testSerialization() throws Throwable {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource("regexpSetterTests.xml", getClass())); BeanFactory bf = new XmlBeanFactory(CONTEXT);
// This is a CGLIB proxy, so we can proxy it to the target class // This is a CGLIB proxy, so we can proxy it to the target class
Person p = (Person) bf.getBean("serializableSettersAdvised"); Person p = (Person) bf.getBean("serializableSettersAdvised");
// Interceptor behind regexp advisor // Interceptor behind regexp advisor

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,13 +30,13 @@ import org.springframework.core.io.ClassPathResource;
* @author Chris Beams * @author Chris Beams
* @since 2.0 * @since 2.0
*/ */
public class CommonsPoolTargetSourceProxyTests { public final class CommonsPoolTargetSourceProxyTests {
@Test @Test
public void testProxy() throws Exception { public void testProxy() throws Exception {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
reader.loadBeanDefinitions(new ClassPathResource("commonsPoolProxyTests.xml", getClass())); reader.loadBeanDefinitions(new ClassPathResource("CommonsPoolTargetSourceProxyTests-context.xml", getClass()));
beanFactory.preInstantiateSingletons(); beanFactory.preInstantiateSingletons();
ITestBean bean = (ITestBean)beanFactory.getBean("testBean"); ITestBean bean = (ITestBean)beanFactory.getBean("testBean");
assertTrue(AopUtils.isAopProxy(bean)); assertTrue(AopUtils.isAopProxy(bean));

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,17 +28,17 @@ import org.springframework.beans.Person;
import org.springframework.beans.SerializablePerson; import org.springframework.beans.SerializablePerson;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.util.SerializationTestUtils;
import test.beans.SideEffectBean; import test.beans.SideEffectBean;
import test.interceptor.SerializableNopInterceptor; import test.interceptor.SerializableNopInterceptor;
import test.util.SerializationTestUtils;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class HotSwappableTargetSourceTests { public final class HotSwappableTargetSourceTests {
/** Initial count value set in bean factory XML */ /** Initial count value set in bean factory XML */
private static final int INITIAL_COUNT = 10; private static final int INITIAL_COUNT = 10;
@ -47,7 +47,8 @@ public class HotSwappableTargetSourceTests {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.beanFactory = new XmlBeanFactory(new ClassPathResource("hotSwapTests.xml", getClass())); this.beanFactory = new XmlBeanFactory(
new ClassPathResource("HotSwappableTargetSourceTests-context.xml", getClass()));
} }
/** /**

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,7 +27,7 @@ import org.springframework.aop.framework.ProxyFactory;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class LazyCreationTargetSourceTests { public final class LazyCreationTargetSourceTests {
@Test @Test
public void testCreateLazy() { public void testCreateLazy() {

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,11 +31,21 @@ import org.springframework.core.io.ClassPathResource;
* @author Chris Beams * @author Chris Beams
* @since 07.01.2005 * @since 07.01.2005
*/ */
public class LazyInitTargetSourceTests { public final class LazyInitTargetSourceTests {
private static final Class<?> CLASS = LazyInitTargetSourceTests.class;
private static final String CLASSNAME = CLASS.getSimpleName();
private static final ClassPathResource SINGLETON_CONTEXT =
new ClassPathResource(CLASSNAME + "-singleton.xml", CLASS);
private static final ClassPathResource CUSTOM_TARGET_CONTEXT =
new ClassPathResource(CLASSNAME + "-customTarget.xml", CLASS);
private static final ClassPathResource FACTORY_BEAN_CONTEXT =
new ClassPathResource(CLASSNAME + "-factoryBean.xml", CLASS);
@Test @Test
public void testLazyInitSingletonTargetSource() { public void testLazyInitSingletonTargetSource() {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("lazyInitSingletonTests.xml", getClass())); XmlBeanFactory bf = new XmlBeanFactory(SINGLETON_CONTEXT);
bf.preInstantiateSingletons(); bf.preInstantiateSingletons();
ITestBean tb = (ITestBean) bf.getBean("proxy"); ITestBean tb = (ITestBean) bf.getBean("proxy");
@ -46,7 +56,7 @@ public class LazyInitTargetSourceTests {
@Test @Test
public void testCustomLazyInitSingletonTargetSource() { public void testCustomLazyInitSingletonTargetSource() {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("customLazyInitTarget.xml", getClass())); XmlBeanFactory bf = new XmlBeanFactory(CUSTOM_TARGET_CONTEXT);
bf.preInstantiateSingletons(); bf.preInstantiateSingletons();
ITestBean tb = (ITestBean) bf.getBean("proxy"); ITestBean tb = (ITestBean) bf.getBean("proxy");
@ -57,7 +67,7 @@ public class LazyInitTargetSourceTests {
@Test @Test
public void testLazyInitFactoryBeanTargetSource() { public void testLazyInitFactoryBeanTargetSource() {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("lazyInitFactoryBean.xml", getClass())); XmlBeanFactory bf = new XmlBeanFactory(FACTORY_BEAN_CONTEXT);
bf.preInstantiateSingletons(); bf.preInstantiateSingletons();
Set<?> set1 = (Set<?>) bf.getBean("proxy1"); Set<?> set1 = (Set<?>) bf.getBean("proxy1");

View File

@ -25,16 +25,17 @@ import org.springframework.beans.SerializablePerson;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.util.SerializationTestUtils;
import test.util.SerializationTestUtils;
/** /**
* Unit tests relating to the abstract AbstractPrototypeBasedTargetSource * Unit tests relating to the abstract {@link AbstractPrototypeBasedTargetSource}
* and not subclasses. * and not subclasses.
* *
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class PrototypeBasedTargetSourceTests { public final class PrototypeBasedTargetSourceTests {
@Test @Test
public void testSerializability() throws Exception { public void testSerializability() throws Exception {

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,10 @@ import test.beans.SideEffectBean;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class PrototypeTargetSourceTests { public final class PrototypeTargetSourceTests {
private static final ClassPathResource CONTEXT =
new ClassPathResource("PrototypeTargetSourceTests-context.xml", PrototypeTargetSourceTests.class);
/** Initial count value set in bean factory XML */ /** Initial count value set in bean factory XML */
private static final int INITIAL_COUNT = 10; private static final int INITIAL_COUNT = 10;
@ -40,7 +43,7 @@ public class PrototypeTargetSourceTests {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.beanFactory = new XmlBeanFactory(new ClassPathResource("prototypeTests.xml", getClass())); this.beanFactory = new XmlBeanFactory(CONTEXT);
} }
/** /**

View File

@ -32,6 +32,9 @@ import test.beans.SideEffectBean;
* @author Chris Beams * @author Chris Beams
*/ */
public class ThreadLocalTargetSourceTests { public class ThreadLocalTargetSourceTests {
private static final ClassPathResource CONTEXT =
new ClassPathResource("ThreadLocalTargetSourceTests-context.xml", ThreadLocalTargetSourceTests.class);
/** Initial count value set in bean factory XML */ /** Initial count value set in bean factory XML */
private static final int INITIAL_COUNT = 10; private static final int INITIAL_COUNT = 10;
@ -40,7 +43,7 @@ public class ThreadLocalTargetSourceTests {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.beanFactory = new XmlBeanFactory(new ClassPathResource("threadLocalTests.xml", getClass())); this.beanFactory = new XmlBeanFactory(CONTEXT);
} }
/** /**

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,7 +24,7 @@ import org.junit.Test;
* @author Rob Harrop * @author Rob Harrop
* @author Chris Beams * @author Chris Beams
*/ */
public class RefreshableTargetSourceTests { public final class RefreshableTargetSourceTests {
/** /**
* Test what happens when checking for refresh but not refreshing object. * Test what happens when checking for refresh but not refreshing object.

View File

@ -3,7 +3,9 @@
* of the Apache Software License. * of the Apache Software License.
*/ */
package org.springframework.util; package test.util;
import static org.junit.Assert.*;
import java.awt.Point; import java.awt.Point;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -15,18 +17,18 @@ import java.io.ObjectOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Serializable; import java.io.Serializable;
import junit.framework.TestCase; import org.junit.Test;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
/** /**
* Utilities for testing serializability of objects. * Utilities for testing serializability of objects.
* Exposes static methods for use in other test cases. * Exposes static methods for use in other test cases.
* Extends TestCase only to test itself. * Contains {@link org.junit.Test} methods to test itself.
* *
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams
*/ */
public class SerializationTestUtils extends TestCase { public final class SerializationTestUtils {
public static void testSerialization(Object o) throws IOException { public static void testSerialization(Object o) throws IOException {
OutputStream baos = new ByteArrayOutputStream(); OutputStream baos = new ByteArrayOutputStream();
@ -59,25 +61,16 @@ public class SerializationTestUtils extends TestCase {
return o2; return o2;
} }
public SerializationTestUtils(String s) { @Test(expected=NotSerializableException.class)
super(s);
}
public void testWithNonSerializableObject() throws IOException { public void testWithNonSerializableObject() throws IOException {
TestBean o = new TestBean(); TestBean o = new TestBean();
assertFalse(o instanceof Serializable); assertFalse(o instanceof Serializable);
assertFalse(isSerializable(o)); assertFalse(isSerializable(o));
try { testSerialization(o);
testSerialization(o);
fail();
}
catch (NotSerializableException ex) {
// Ok
}
} }
@Test
public void testWithSerializableObject() throws Exception { public void testWithSerializableObject() throws Exception {
int x = 5; int x = 5;
int y = 10; int y = 10;