From 2a30fa07ea545c5187788825febd6e5eb7460275 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 2 Jan 2013 12:43:15 -0800 Subject: [PATCH] Replace test beans with test objects Refactor spring-core tests to replace test beans from 'org.springframework.beans' with lighter test objects in 'org.springframework.tests.sample.objects'. --- .../beans/DerivedTestBean.java | 87 ---- .../springframework/beans/GenericBean.java | 237 ---------- .../org/springframework/beans/ITestBean.java | 71 --- .../beans/IndexedTestBean.java | 145 ------ .../springframework/beans/NestedTestBean.java | 61 --- .../org/springframework/beans/TestBean.java | 442 ------------------ .../core/ConventionsTests.java | 22 +- .../GenericCollectionTypeResolverTests.java | 6 +- ...ableTableParameterNameDiscovererTests.java | 10 +- ...ioritizedParameterNameDiscovererTests.java | 4 +- .../sample/objects/DerivedTestObject.java} | 18 +- .../sample/objects/GenericObject.java} | 28 +- .../sample/objects/ITestInterface.java} | 10 +- .../sample/objects/ITestObject.java} | 20 +- .../tests/sample/objects/TestObject.java | 72 +++ .../tests/sample/objects/package-info.java | 4 + .../util/AutoPopulatingListTests.java | 24 +- .../springframework/util/ClassUtilsTests.java | 30 +- .../util/ReflectionUtilsTests.java | 61 ++- .../util/SerializationTestUtils.java | 4 +- 20 files changed, 196 insertions(+), 1160 deletions(-) delete mode 100644 spring-core/src/test/java/org/springframework/beans/DerivedTestBean.java delete mode 100644 spring-core/src/test/java/org/springframework/beans/GenericBean.java delete mode 100644 spring-core/src/test/java/org/springframework/beans/ITestBean.java delete mode 100644 spring-core/src/test/java/org/springframework/beans/IndexedTestBean.java delete mode 100644 spring-core/src/test/java/org/springframework/beans/NestedTestBean.java delete mode 100644 spring-core/src/test/java/org/springframework/beans/TestBean.java rename spring-core/src/test/java/org/springframework/{beans/CustomEnum.java => tests/sample/objects/DerivedTestObject.java} (70%) rename spring-core/src/test/java/org/springframework/{beans/Colour.java => tests/sample/objects/GenericObject.java} (50%) rename spring-core/src/test/java/org/springframework/{beans/IOther.java => tests/sample/objects/ITestInterface.java} (80%) rename spring-core/src/test/java/org/springframework/{beans/INestedTestBean.java => tests/sample/objects/ITestObject.java} (66%) create mode 100644 spring-core/src/test/java/org/springframework/tests/sample/objects/TestObject.java create mode 100644 spring-core/src/test/java/org/springframework/tests/sample/objects/package-info.java diff --git a/spring-core/src/test/java/org/springframework/beans/DerivedTestBean.java b/spring-core/src/test/java/org/springframework/beans/DerivedTestBean.java deleted file mode 100644 index 70a3fcfe6b..0000000000 --- a/spring-core/src/test/java/org/springframework/beans/DerivedTestBean.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2002-2012 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.beans; - -import java.io.Serializable; - -/** - * @author Juergen Hoeller - * @since 21.08.2003 - */ -@SuppressWarnings("serial") -public class DerivedTestBean extends TestBean implements Serializable { - - private String beanName; - - private boolean initialized; - - private boolean destroyed; - - - public DerivedTestBean() { - } - - public DerivedTestBean(String[] names) { - if (names == null || names.length < 2) { - throw new IllegalArgumentException("Invalid names array"); - } - setName(names[0]); - setBeanName(names[1]); - } - - public static DerivedTestBean create(String[] names) { - return new DerivedTestBean(names); - } - - - @Override - public void setBeanName(String beanName) { - if (this.beanName == null || beanName == null) { - this.beanName = beanName; - } - } - - @Override - public String getBeanName() { - return beanName; - } - - public void setSpouseRef(String name) { - setSpouse(new TestBean(name)); - } - - - public void initialize() { - this.initialized = true; - } - - public boolean wasInitialized() { - return initialized; - } - - - @Override - public void destroy() { - this.destroyed = true; - } - - @Override - public boolean wasDestroyed() { - return destroyed; - } - -} diff --git a/spring-core/src/test/java/org/springframework/beans/GenericBean.java b/spring-core/src/test/java/org/springframework/beans/GenericBean.java deleted file mode 100644 index c4b85fa1f6..0000000000 --- a/spring-core/src/test/java/org/springframework/beans/GenericBean.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * 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. - * 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.beans; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.springframework.core.io.Resource; - -/** - * @author Juergen Hoeller - */ -public class GenericBean { - - private Set integerSet; - - private List resourceList; - - private List> listOfLists; - - private ArrayList listOfArrays; - - private List> listOfMaps; - - private Map plainMap; - - private Map shortMap; - - private HashMap longMap; - - private Map> collectionMap; - - private Map> mapOfMaps; - - private Map> mapOfLists; - - private CustomEnum customEnum; - - private T genericProperty; - - private List genericListProperty; - - - public GenericBean() { - } - - public GenericBean(Set integerSet) { - this.integerSet = integerSet; - } - - public GenericBean(Set integerSet, List resourceList) { - this.integerSet = integerSet; - this.resourceList = resourceList; - } - - public GenericBean(HashSet integerSet, Map shortMap) { - this.integerSet = integerSet; - this.shortMap = shortMap; - } - - public GenericBean(Map shortMap, Resource resource) { - this.shortMap = shortMap; - this.resourceList = Collections.singletonList(resource); - } - - public GenericBean(Map plainMap, Map shortMap) { - this.plainMap = plainMap; - this.shortMap = shortMap; - } - - public GenericBean(HashMap longMap) { - this.longMap = longMap; - } - - public GenericBean(boolean someFlag, Map> collectionMap) { - this.collectionMap = collectionMap; - } - - - public Set getIntegerSet() { - return integerSet; - } - - public void setIntegerSet(Set integerSet) { - this.integerSet = integerSet; - } - - public List getResourceList() { - return resourceList; - } - - public void setResourceList(List resourceList) { - this.resourceList = resourceList; - } - - public List> getListOfLists() { - return listOfLists; - } - - public ArrayList getListOfArrays() { - return listOfArrays; - } - - public void setListOfArrays(ArrayList listOfArrays) { - this.listOfArrays = listOfArrays; - } - - public void setListOfLists(List> listOfLists) { - this.listOfLists = listOfLists; - } - - public List> getListOfMaps() { - return listOfMaps; - } - - public void setListOfMaps(List> listOfMaps) { - this.listOfMaps = listOfMaps; - } - - public Map getPlainMap() { - return plainMap; - } - - public Map getShortMap() { - return shortMap; - } - - public void setShortMap(Map shortMap) { - this.shortMap = shortMap; - } - - public HashMap getLongMap() { - return longMap; - } - - public void setLongMap(HashMap longMap) { - this.longMap = longMap; - } - - public Map> getCollectionMap() { - return collectionMap; - } - - public void setCollectionMap(Map> collectionMap) { - this.collectionMap = collectionMap; - } - - public Map> getMapOfMaps() { - return mapOfMaps; - } - - public void setMapOfMaps(Map> mapOfMaps) { - this.mapOfMaps = mapOfMaps; - } - - public Map> getMapOfLists() { - return mapOfLists; - } - - public void setMapOfLists(Map> mapOfLists) { - this.mapOfLists = mapOfLists; - } - - public T getGenericProperty() { - return genericProperty; - } - - public void setGenericProperty(T genericProperty) { - this.genericProperty = genericProperty; - } - - public List getGenericListProperty() { - return genericListProperty; - } - - public void setGenericListProperty(List genericListProperty) { - this.genericListProperty = genericListProperty; - } - - public CustomEnum getCustomEnum() { - return customEnum; - } - - public void setCustomEnum(CustomEnum customEnum) { - this.customEnum = customEnum; - } - - - public static GenericBean createInstance(Set integerSet) { - return new GenericBean(integerSet); - } - - public static GenericBean createInstance(Set integerSet, List resourceList) { - return new GenericBean(integerSet, resourceList); - } - - public static GenericBean createInstance(HashSet integerSet, Map shortMap) { - return new GenericBean(integerSet, shortMap); - } - - public static GenericBean createInstance(Map shortMap, Resource resource) { - return new GenericBean(shortMap, resource); - } - - public static GenericBean createInstance(Map map, Map shortMap) { - return new GenericBean(map, shortMap); - } - - public static GenericBean createInstance(HashMap longMap) { - return new GenericBean(longMap); - } - - public static GenericBean createInstance(boolean someFlag, Map> collectionMap) { - return new GenericBean(someFlag, collectionMap); - } - -} \ No newline at end of file diff --git a/spring-core/src/test/java/org/springframework/beans/ITestBean.java b/spring-core/src/test/java/org/springframework/beans/ITestBean.java deleted file mode 100644 index cdf5ef510d..0000000000 --- a/spring-core/src/test/java/org/springframework/beans/ITestBean.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2002-2007 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.beans; - -import java.io.IOException; - -/** - * Interface used for {@link org.springframework.beans.TestBean}. - * - *

Two methods are the same as on Person, but if this - * extends person it breaks quite a few tests.. - * - * @author Rod Johnson - * @author Juergen Hoeller - */ -public interface ITestBean { - - int getAge(); - - void setAge(int age); - - String getName(); - - void setName(String name); - - ITestBean getSpouse(); - - void setSpouse(ITestBean spouse); - - ITestBean[] getSpouses(); - - String[] getStringArray(); - - void setStringArray(String[] stringArray); - - /** - * Throws a given (non-null) exception. - */ - void exceptional(Throwable t) throws Throwable; - - Object returnsThis(); - - INestedTestBean getDoctor(); - - INestedTestBean getLawyer(); - - IndexedTestBean getNestedIndexedBean(); - - /** - * Increment the age by one. - * @return the previous age - */ - int haveBirthday(); - - void unreliableFileOperation() throws IOException; - -} \ No newline at end of file diff --git a/spring-core/src/test/java/org/springframework/beans/IndexedTestBean.java b/spring-core/src/test/java/org/springframework/beans/IndexedTestBean.java deleted file mode 100644 index ddb091770e..0000000000 --- a/spring-core/src/test/java/org/springframework/beans/IndexedTestBean.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2002-2006 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.beans; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedMap; -import java.util.SortedSet; -import java.util.TreeSet; - -/** - * @author Juergen Hoeller - * @since 11.11.2003 - */ -public class IndexedTestBean { - - private TestBean[] array; - - private Collection collection; - - private List list; - - private Set set; - - private SortedSet sortedSet; - - private Map map; - - private SortedMap sortedMap; - - - public IndexedTestBean() { - this(true); - } - - public IndexedTestBean(boolean populate) { - if (populate) { - populate(); - } - } - - public void populate() { - TestBean tb0 = new TestBean("name0", 0); - TestBean tb1 = new TestBean("name1", 0); - TestBean tb2 = new TestBean("name2", 0); - TestBean tb3 = new TestBean("name3", 0); - TestBean tb4 = new TestBean("name4", 0); - TestBean tb5 = new TestBean("name5", 0); - TestBean tb6 = new TestBean("name6", 0); - TestBean tb7 = new TestBean("name7", 0); - TestBean tbX = new TestBean("nameX", 0); - TestBean tbY = new TestBean("nameY", 0); - this.array = new TestBean[] {tb0, tb1}; - this.list = new ArrayList(); - this.list.add(tb2); - this.list.add(tb3); - this.set = new TreeSet(); - this.set.add(tb6); - this.set.add(tb7); - this.map = new HashMap(); - this.map.put("key1", tb4); - this.map.put("key2", tb5); - this.map.put("key.3", tb5); - List list = new ArrayList(); - list.add(tbX); - list.add(tbY); - this.map.put("key4", list); - } - - - public TestBean[] getArray() { - return array; - } - - public void setArray(TestBean[] array) { - this.array = array; - } - - public Collection getCollection() { - return collection; - } - - public void setCollection(Collection collection) { - this.collection = collection; - } - - public List getList() { - return list; - } - - public void setList(List list) { - this.list = list; - } - - public Set getSet() { - return set; - } - - public void setSet(Set set) { - this.set = set; - } - - public SortedSet getSortedSet() { - return sortedSet; - } - - public void setSortedSet(SortedSet sortedSet) { - this.sortedSet = sortedSet; - } - - public Map getMap() { - return map; - } - - public void setMap(Map map) { - this.map = map; - } - - public SortedMap getSortedMap() { - return sortedMap; - } - - public void setSortedMap(SortedMap sortedMap) { - this.sortedMap = sortedMap; - } - -} \ No newline at end of file diff --git a/spring-core/src/test/java/org/springframework/beans/NestedTestBean.java b/spring-core/src/test/java/org/springframework/beans/NestedTestBean.java deleted file mode 100644 index 412891c439..0000000000 --- a/spring-core/src/test/java/org/springframework/beans/NestedTestBean.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2002-2012 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.beans; - -/** - * Simple nested test bean used for testing bean factories, AOP framework etc. - * - * @author Trevor D. Cook - * @since 30.09.2003 - */ -public class NestedTestBean implements INestedTestBean { - - private String company = ""; - - public NestedTestBean() { - } - - public NestedTestBean(String company) { - setCompany(company); - } - - public void setCompany(String company) { - this.company = (company != null ? company : ""); - } - - @Override - public String getCompany() { - return company; - } - - public boolean equals(Object obj) { - if (!(obj instanceof NestedTestBean)) { - return false; - } - NestedTestBean ntb = (NestedTestBean) obj; - return this.company.equals(ntb.company); - } - - public int hashCode() { - return this.company.hashCode(); - } - - public String toString() { - return "NestedTestBean: " + this.company; - } - -} \ No newline at end of file diff --git a/spring-core/src/test/java/org/springframework/beans/TestBean.java b/spring-core/src/test/java/org/springframework/beans/TestBean.java deleted file mode 100644 index 06ad95816d..0000000000 --- a/spring-core/src/test/java/org/springframework/beans/TestBean.java +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Copyright 2002-2012 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.beans; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import org.springframework.util.ObjectUtils; - -/** - * Simple test bean used for testing bean factories, the AOP framework etc. - * - * @author Rod Johnson - * @author Juergen Hoeller - * @since 15 April 2001 - */ -public class TestBean implements ITestBean, IOther, Comparable { - - private String beanName; - - private String country; - - private boolean postProcessed; - - private String name; - - private String sex; - - private int age; - - private boolean jedi; - - private ITestBean[] spouses; - - private String touchy; - - private String[] stringArray; - - private Integer[] someIntegerArray; - - private Date date = new Date(); - - private Float myFloat = new Float(0.0); - - private Collection friends = new LinkedList(); - - private Set someSet = new HashSet(); - - private Map someMap = new HashMap(); - - private List someList = new ArrayList(); - - private Properties someProperties = new Properties(); - - private INestedTestBean doctor = new NestedTestBean(); - - private INestedTestBean lawyer = new NestedTestBean(); - - private IndexedTestBean nestedIndexedBean; - - private boolean destroyed; - - private Number someNumber; - - private Colour favouriteColour; - - private Boolean someBoolean; - - private List otherColours; - - private List pets; - - - public TestBean() { - } - - public TestBean(String name) { - this.name = name; - } - - public TestBean(ITestBean spouse) { - this.spouses = new ITestBean[] {spouse}; - } - - public TestBean(String name, int age) { - this.name = name; - this.age = age; - } - - public TestBean(ITestBean spouse, Properties someProperties) { - this.spouses = new ITestBean[] {spouse}; - this.someProperties = someProperties; - } - - public TestBean(List someList) { - this.someList = someList; - } - - public TestBean(Set someSet) { - this.someSet = someSet; - } - - public TestBean(Map someMap) { - this.someMap = someMap; - } - - public TestBean(Properties someProperties) { - this.someProperties = someProperties; - } - - - public void setBeanName(String beanName) { - this.beanName = beanName; - } - - public String getBeanName() { - return beanName; - } - - public void setPostProcessed(boolean postProcessed) { - this.postProcessed = postProcessed; - } - - public boolean isPostProcessed() { - return postProcessed; - } - - @Override - public String getName() { - return name; - } - - @Override - public void setName(String name) { - this.name = name; - } - - public String getSex() { - return sex; - } - - public void setSex(String sex) { - this.sex = sex; - if (this.name == null) { - this.name = sex; - } - } - - @Override - public int getAge() { - return age; - } - - @Override - public void setAge(int age) { - this.age = age; - } - - public boolean isJedi() { - return jedi; - } - - public void setJedi(boolean jedi) { - this.jedi = jedi; - } - - @Override - public ITestBean getSpouse() { - return (spouses != null ? spouses[0] : null); - } - - @Override - public void setSpouse(ITestBean spouse) { - this.spouses = new ITestBean[] {spouse}; - } - - @Override - public ITestBean[] getSpouses() { - return spouses; - } - - public String getTouchy() { - return touchy; - } - - public void setTouchy(String touchy) throws Exception { - if (touchy.indexOf('.') != -1) { - throw new Exception("Can't contain a ."); - } - if (touchy.indexOf(',') != -1) { - throw new NumberFormatException("Number format exception: contains a ,"); - } - this.touchy = touchy; - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - @Override - public String[] getStringArray() { - return stringArray; - } - - @Override - public void setStringArray(String[] stringArray) { - this.stringArray = stringArray; - } - - public Integer[] getSomeIntegerArray() { - return someIntegerArray; - } - - public void setSomeIntegerArray(Integer[] someIntegerArray) { - this.someIntegerArray = someIntegerArray; - } - - public Date getDate() { - return date; - } - - public void setDate(Date date) { - this.date = date; - } - - public Float getMyFloat() { - return myFloat; - } - - public void setMyFloat(Float myFloat) { - this.myFloat = myFloat; - } - - public Collection getFriends() { - return friends; - } - - public void setFriends(Collection friends) { - this.friends = friends; - } - - public Set getSomeSet() { - return someSet; - } - - public void setSomeSet(Set someSet) { - this.someSet = someSet; - } - - public Map getSomeMap() { - return someMap; - } - - public void setSomeMap(Map someMap) { - this.someMap = someMap; - } - - public List getSomeList() { - return someList; - } - - public void setSomeList(List someList) { - this.someList = someList; - } - - public Properties getSomeProperties() { - return someProperties; - } - - public void setSomeProperties(Properties someProperties) { - this.someProperties = someProperties; - } - - @Override - public INestedTestBean getDoctor() { - return doctor; - } - - public void setDoctor(INestedTestBean doctor) { - this.doctor = doctor; - } - - @Override - public INestedTestBean getLawyer() { - return lawyer; - } - - public void setLawyer(INestedTestBean lawyer) { - this.lawyer = lawyer; - } - - public Number getSomeNumber() { - return someNumber; - } - - public void setSomeNumber(Number someNumber) { - this.someNumber = someNumber; - } - - public Colour getFavouriteColour() { - return favouriteColour; - } - - public void setFavouriteColour(Colour favouriteColour) { - this.favouriteColour = favouriteColour; - } - - public Boolean getSomeBoolean() { - return someBoolean; - } - - public void setSomeBoolean(Boolean someBoolean) { - this.someBoolean = someBoolean; - } - - @Override - public IndexedTestBean getNestedIndexedBean() { - return nestedIndexedBean; - } - - public void setNestedIndexedBean(IndexedTestBean nestedIndexedBean) { - this.nestedIndexedBean = nestedIndexedBean; - } - - public List getOtherColours() { - return otherColours; - } - - public void setOtherColours(List otherColours) { - this.otherColours = otherColours; - } - - public List getPets() { - return pets; - } - - public void setPets(List pets) { - this.pets = pets; - } - - - /** - * @see ITestBean#exceptional(Throwable) - */ - @Override - public void exceptional(Throwable t) throws Throwable { - if (t != null) { - throw t; - } - } - - @Override - public void unreliableFileOperation() throws IOException { - throw new IOException(); - } - /** - * @see ITestBean#returnsThis() - */ - @Override - public Object returnsThis() { - return this; - } - - /** - * @see IOther#absquatulate() - */ - @Override - public void absquatulate() { - } - - @Override - public int haveBirthday() { - return age++; - } - - - public void destroy() { - this.destroyed = true; - } - - public boolean wasDestroyed() { - return destroyed; - } - - - public boolean equals(Object other) { - if (this == other) { - return true; - } - if (other == null || !(other instanceof TestBean)) { - return false; - } - TestBean tb2 = (TestBean) other; - return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age); - } - - public int hashCode() { - return this.age; - } - - @Override - public int compareTo(Object other) { - if (this.name != null && other instanceof TestBean) { - return this.name.compareTo(((TestBean) other).getName()); - } - else { - return 1; - } - } - - public String toString() { - return this.name; - } - -} \ No newline at end of file diff --git a/spring-core/src/test/java/org/springframework/core/ConventionsTests.java b/spring-core/src/test/java/org/springframework/core/ConventionsTests.java index 19d9b264f0..b906164710 100644 --- a/spring-core/src/test/java/org/springframework/core/ConventionsTests.java +++ b/spring-core/src/test/java/org/springframework/core/ConventionsTests.java @@ -23,7 +23,7 @@ import java.util.Set; import junit.framework.TestCase; -import org.springframework.beans.TestBean; +import org.springframework.tests.sample.objects.TestObject; /** * @author Rob Harrop @@ -31,23 +31,23 @@ import org.springframework.beans.TestBean; public class ConventionsTests extends TestCase { public void testSimpleObject() { - TestBean testBean = new TestBean(); - assertEquals("Incorrect singular variable name", "testBean", Conventions.getVariableName(testBean)); + TestObject testObject = new TestObject(); + assertEquals("Incorrect singular variable name", "testObject", Conventions.getVariableName(testObject)); } public void testArray() { - TestBean[] testBeans = new TestBean[0]; - assertEquals("Incorrect plural array form", "testBeanList", Conventions.getVariableName(testBeans)); + TestObject[] testObjects = new TestObject[0]; + assertEquals("Incorrect plural array form", "testObjectList", Conventions.getVariableName(testObjects)); } public void testCollections() { - List list = new ArrayList(); - list.add(new TestBean()); - assertEquals("Incorrect plural List form", "testBeanList", Conventions.getVariableName(list)); + List list = new ArrayList(); + list.add(new TestObject()); + assertEquals("Incorrect plural List form", "testObjectList", Conventions.getVariableName(list)); - Set set = new HashSet(); - set.add(new TestBean()); - assertEquals("Incorrect plural Set form", "testBeanList", Conventions.getVariableName(set)); + Set set = new HashSet(); + set.add(new TestObject()); + assertEquals("Incorrect plural Set form", "testObjectList", Conventions.getVariableName(set)); List emptyList = new ArrayList(); try { diff --git a/spring-core/src/test/java/org/springframework/core/GenericCollectionTypeResolverTests.java b/spring-core/src/test/java/org/springframework/core/GenericCollectionTypeResolverTests.java index bb70889aae..c598269137 100644 --- a/spring-core/src/test/java/org/springframework/core/GenericCollectionTypeResolverTests.java +++ b/spring-core/src/test/java/org/springframework/core/GenericCollectionTypeResolverTests.java @@ -25,8 +25,8 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.springframework.beans.GenericBean; import org.springframework.core.io.Resource; +import org.springframework.tests.sample.objects.GenericObject; /** * @author Serge Bogatyrjov @@ -93,11 +93,11 @@ public class GenericCollectionTypeResolverTests extends AbstractGenericsTests { } public void testProgrammaticListIntrospection() throws Exception { - Method setter = GenericBean.class.getMethod("setResourceList", List.class); + Method setter = GenericObject.class.getMethod("setResourceList", List.class); assertEquals(Resource.class, GenericCollectionTypeResolver.getCollectionParameterType(new MethodParameter(setter, 0))); - Method getter = GenericBean.class.getMethod("getResourceList"); + Method getter = GenericObject.class.getMethod("getResourceList"); assertEquals(Resource.class, GenericCollectionTypeResolver.getCollectionReturnType(getter)); } diff --git a/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java b/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java index 0580ae54c2..a151571379 100644 --- a/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java +++ b/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java @@ -25,7 +25,7 @@ import java.util.Date; import junit.framework.TestCase; import org.junit.Ignore; -import org.springframework.beans.TestBean; +import org.springframework.tests.sample.objects.TestObject; /** * @author Adrian Colyer @@ -35,14 +35,14 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase { private LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer(); public void testMethodParameterNameDiscoveryNoArgs() throws NoSuchMethodException { - Method getName = TestBean.class.getMethod("getName", new Class[0]); + Method getName = TestObject.class.getMethod("getName", new Class[0]); String[] names = discoverer.getParameterNames(getName); assertNotNull("should find method info", names); assertEquals("no argument names", 0, names.length); } public void testMethodParameterNameDiscoveryWithArgs() throws NoSuchMethodException { - Method setName = TestBean.class.getMethod("setName", new Class[] { String.class }); + Method setName = TestObject.class.getMethod("setName", new Class[] { String.class }); String[] names = discoverer.getParameterNames(setName); assertNotNull("should find method info", names); assertEquals("one argument", 1, names.length); @@ -50,14 +50,14 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase { } public void testConsParameterNameDiscoveryNoArgs() throws NoSuchMethodException { - Constructor noArgsCons = TestBean.class.getConstructor(new Class[0]); + Constructor noArgsCons = TestObject.class.getConstructor(new Class[0]); String[] names = discoverer.getParameterNames(noArgsCons); assertNotNull("should find cons info", names); assertEquals("no argument names", 0, names.length); } public void testConsParameterNameDiscoveryArgs() throws NoSuchMethodException { - Constructor twoArgCons = TestBean.class.getConstructor(new Class[] { String.class, int.class }); + Constructor twoArgCons = TestObject.class.getConstructor(new Class[] { String.class, int.class }); String[] names = discoverer.getParameterNames(twoArgCons); assertNotNull("should find cons info", names); assertEquals("one argument", 2, names.length); diff --git a/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java b/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java index eea35b88e6..cd16ed0446 100644 --- a/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java +++ b/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java @@ -22,7 +22,7 @@ import java.util.Arrays; import junit.framework.TestCase; -import org.springframework.beans.TestBean; +import org.springframework.tests.sample.objects.TestObject; public class PrioritizedParameterNameDiscovererTests extends TestCase { @@ -56,7 +56,7 @@ public class PrioritizedParameterNameDiscovererTests extends TestCase { private final Class anyClass = Object.class; public PrioritizedParameterNameDiscovererTests() throws SecurityException, NoSuchMethodException { - anyMethod = TestBean.class.getMethod("getAge", (Class[]) null); + anyMethod = TestObject.class.getMethod("getAge", (Class[]) null); } public void testNoParametersDiscoverers() { diff --git a/spring-core/src/test/java/org/springframework/beans/CustomEnum.java b/spring-core/src/test/java/org/springframework/tests/sample/objects/DerivedTestObject.java similarity index 70% rename from spring-core/src/test/java/org/springframework/beans/CustomEnum.java rename to spring-core/src/test/java/org/springframework/tests/sample/objects/DerivedTestObject.java index 1e43492191..45ab490a7d 100644 --- a/spring-core/src/test/java/org/springframework/beans/CustomEnum.java +++ b/spring-core/src/test/java/org/springframework/tests/sample/objects/DerivedTestObject.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2013 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,11 @@ * limitations under the License. */ -package org.springframework.beans; +package org.springframework.tests.sample.objects; -/** - * @author Juergen Hoeller - */ -public enum CustomEnum { +import java.io.Serializable; - VALUE_1, VALUE_2; +@SuppressWarnings("serial") +public class DerivedTestObject extends TestObject implements Serializable { - public String toString() { - return "CustomEnum: " + name(); - } - -} \ No newline at end of file +} diff --git a/spring-core/src/test/java/org/springframework/beans/Colour.java b/spring-core/src/test/java/org/springframework/tests/sample/objects/GenericObject.java similarity index 50% rename from spring-core/src/test/java/org/springframework/beans/Colour.java rename to spring-core/src/test/java/org/springframework/tests/sample/objects/GenericObject.java index a992a2ebfc..efd0455fdc 100644 --- a/spring-core/src/test/java/org/springframework/beans/Colour.java +++ b/spring-core/src/test/java/org/springframework/tests/sample/objects/GenericObject.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,23 +14,23 @@ * limitations under the License. */ -package org.springframework.beans; +package org.springframework.tests.sample.objects; -import org.springframework.core.enums.ShortCodedLabeledEnum; +import java.util.List; -/** - * @author Rob Harrop - */ -@SuppressWarnings("serial") -public class Colour extends ShortCodedLabeledEnum { +import org.springframework.core.io.Resource; - public static final Colour RED = new Colour(0, "RED"); - public static final Colour BLUE = new Colour(1, "BLUE"); - public static final Colour GREEN = new Colour(2, "GREEN"); - public static final Colour PURPLE = new Colour(3, "PURPLE"); - private Colour(int code, String label) { - super(code, label); +public class GenericObject { + + private List resourceList; + + public List getResourceList() { + return this.resourceList; + } + + public void setResourceList(List resourceList) { + this.resourceList = resourceList; } } diff --git a/spring-core/src/test/java/org/springframework/beans/IOther.java b/spring-core/src/test/java/org/springframework/tests/sample/objects/ITestInterface.java similarity index 80% rename from spring-core/src/test/java/org/springframework/beans/IOther.java rename to spring-core/src/test/java/org/springframework/tests/sample/objects/ITestInterface.java index d7fb346185..4aca1f255b 100644 --- a/spring-core/src/test/java/org/springframework/beans/IOther.java +++ b/spring-core/src/test/java/org/springframework/tests/sample/objects/ITestInterface.java @@ -1,6 +1,5 @@ - /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,10 +14,11 @@ * limitations under the License. */ -package org.springframework.beans; +package org.springframework.tests.sample.objects; -public interface IOther { + +public interface ITestInterface { void absquatulate(); -} \ No newline at end of file +} diff --git a/spring-core/src/test/java/org/springframework/beans/INestedTestBean.java b/spring-core/src/test/java/org/springframework/tests/sample/objects/ITestObject.java similarity index 66% rename from spring-core/src/test/java/org/springframework/beans/INestedTestBean.java rename to spring-core/src/test/java/org/springframework/tests/sample/objects/ITestObject.java index e0ae5f20a3..ca795cb0c1 100644 --- a/spring-core/src/test/java/org/springframework/beans/INestedTestBean.java +++ b/spring-core/src/test/java/org/springframework/tests/sample/objects/ITestObject.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,10 +14,20 @@ * limitations under the License. */ -package org.springframework.beans; +package org.springframework.tests.sample.objects; -public interface INestedTestBean { +public interface ITestObject { - public String getCompany(); + String getName(); -} \ No newline at end of file + void setName(String name); + + int getAge(); + + void setAge(int age); + + TestObject getSpouse(); + + void setSpouse(TestObject spouse); + +} diff --git a/spring-core/src/test/java/org/springframework/tests/sample/objects/TestObject.java b/spring-core/src/test/java/org/springframework/tests/sample/objects/TestObject.java new file mode 100644 index 0000000000..68ce8c644b --- /dev/null +++ b/spring-core/src/test/java/org/springframework/tests/sample/objects/TestObject.java @@ -0,0 +1,72 @@ +/* + * Copyright 2002-2013 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.tests.sample.objects; + +public class TestObject implements ITestObject, ITestInterface, Comparable { + + private String name; + + private int age; + + private TestObject spouse; + + public TestObject() { + } + + public TestObject(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return this.age; + } + + public void setAge(int age) { + this.age = age; + } + + public TestObject getSpouse() { + return this.spouse; + } + + public void setSpouse(TestObject spouse) { + this.spouse = spouse; + } + + @Override + public void absquatulate() { + } + + @Override + public int compareTo(Object o) { + if (this.name != null && o instanceof TestObject) { + return this.name.compareTo(((TestObject) o).getName()); + } + else { + return 1; + } + } +} diff --git a/spring-core/src/test/java/org/springframework/tests/sample/objects/package-info.java b/spring-core/src/test/java/org/springframework/tests/sample/objects/package-info.java new file mode 100644 index 0000000000..98c15ca647 --- /dev/null +++ b/spring-core/src/test/java/org/springframework/tests/sample/objects/package-info.java @@ -0,0 +1,4 @@ +/** + * General purpose sample objects that can be used with tests. + */ +package org.springframework.tests.sample.objects; diff --git a/spring-core/src/test/java/org/springframework/util/AutoPopulatingListTests.java b/spring-core/src/test/java/org/springframework/util/AutoPopulatingListTests.java index ff97d15d92..460e81b297 100644 --- a/spring-core/src/test/java/org/springframework/util/AutoPopulatingListTests.java +++ b/spring-core/src/test/java/org/springframework/util/AutoPopulatingListTests.java @@ -20,7 +20,7 @@ import java.util.LinkedList; import junit.framework.*; -import org.springframework.beans.TestBean; +import org.springframework.tests.sample.objects.TestObject; /** * @author Rob Harrop @@ -29,11 +29,11 @@ import org.springframework.beans.TestBean; public class AutoPopulatingListTests extends TestCase { public void testWithClass() throws Exception { - doTestWithClass(new AutoPopulatingList(TestBean.class)); + doTestWithClass(new AutoPopulatingList(TestObject.class)); } public void testWithClassAndUserSuppliedBackingList() throws Exception { - doTestWithClass(new AutoPopulatingList(new LinkedList(), TestBean.class)); + doTestWithClass(new AutoPopulatingList(new LinkedList(), TestObject.class)); } public void testWithElementFactory() throws Exception { @@ -49,7 +49,7 @@ public class AutoPopulatingListTests extends TestCase { for (int x = 0; x < 10; x++) { Object element = list.get(x); assertNotNull("Element is null", list.get(x)); - assertTrue("Element is incorrect type", element instanceof TestBean); + assertTrue("Element is incorrect type", element instanceof TestObject); assertNotSame(lastElement, element); lastElement = element; } @@ -59,10 +59,10 @@ public class AutoPopulatingListTests extends TestCase { list.add(11, helloWorld); assertEquals(helloWorld, list.get(11)); - assertTrue(list.get(10) instanceof TestBean); - assertTrue(list.get(12) instanceof TestBean); - assertTrue(list.get(13) instanceof TestBean); - assertTrue(list.get(20) instanceof TestBean); + assertTrue(list.get(10) instanceof TestObject); + assertTrue(list.get(12) instanceof TestObject); + assertTrue(list.get(13) instanceof TestObject); + assertTrue(list.get(20) instanceof TestObject); } private void doTestWithElementFactory(AutoPopulatingList list) { @@ -70,14 +70,14 @@ public class AutoPopulatingListTests extends TestCase { for(int x = 0; x < list.size(); x++) { Object element = list.get(x); - if(element instanceof TestBean) { - assertEquals(x, ((TestBean) element).getAge()); + if(element instanceof TestObject) { + assertEquals(x, ((TestObject) element).getAge()); } } } public void testSerialization() throws Exception { - AutoPopulatingList list = new AutoPopulatingList(TestBean.class); + AutoPopulatingList list = new AutoPopulatingList(TestObject.class); assertEquals(list, SerializationTestUtils.serializeAndDeserialize(list)); } @@ -86,7 +86,7 @@ public class AutoPopulatingListTests extends TestCase { @Override public Object createElement(int index) { - TestBean bean = new TestBean(); + TestObject bean = new TestObject(); bean.setAge(index); return bean; } diff --git a/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java b/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java index e8ab847406..f99216bbbe 100644 --- a/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java @@ -28,10 +28,10 @@ import java.util.List; import junit.framework.TestCase; -import org.springframework.beans.DerivedTestBean; -import org.springframework.beans.IOther; -import org.springframework.beans.ITestBean; -import org.springframework.beans.TestBean; +import org.springframework.tests.sample.objects.DerivedTestObject; +import org.springframework.tests.sample.objects.ITestInterface; +import org.springframework.tests.sample.objects.ITestObject; +import org.springframework.tests.sample.objects.TestObject; /** * @author Colin Sampaleanu @@ -61,11 +61,11 @@ public class ClassUtilsTests extends TestCase { assertEquals(String[].class, ClassUtils.forName(String[].class.getName(), classLoader)); assertEquals(String[][].class, ClassUtils.forName(String[][].class.getName(), classLoader)); assertEquals(String[][][].class, ClassUtils.forName(String[][][].class.getName(), classLoader)); - assertEquals(TestBean.class, ClassUtils.forName("org.springframework.beans.TestBean", classLoader)); - assertEquals(TestBean[].class, ClassUtils.forName("org.springframework.beans.TestBean[]", classLoader)); - assertEquals(TestBean[].class, ClassUtils.forName(TestBean[].class.getName(), classLoader)); - assertEquals(TestBean[][].class, ClassUtils.forName("org.springframework.beans.TestBean[][]", classLoader)); - assertEquals(TestBean[][].class, ClassUtils.forName(TestBean[][].class.getName(), classLoader)); + assertEquals(TestObject.class, ClassUtils.forName("org.springframework.tests.sample.objects.TestObject", classLoader)); + assertEquals(TestObject[].class, ClassUtils.forName("org.springframework.tests.sample.objects.TestObject[]", classLoader)); + assertEquals(TestObject[].class, ClassUtils.forName(TestObject[].class.getName(), classLoader)); + assertEquals(TestObject[][].class, ClassUtils.forName("org.springframework.tests.sample.objects.TestObject[][]", classLoader)); + assertEquals(TestObject[][].class, ClassUtils.forName(TestObject[][].class.getName(), classLoader)); assertEquals(short[][][].class, ClassUtils.forName("[[[S", classLoader)); } @@ -201,11 +201,11 @@ public class ClassUtilsTests extends TestCase { } public void testCountOverloadedMethods() { - assertFalse(ClassUtils.hasAtLeastOneMethodWithName(TestBean.class, "foobar")); + assertFalse(ClassUtils.hasAtLeastOneMethodWithName(TestObject.class, "foobar")); // no args - assertTrue(ClassUtils.hasAtLeastOneMethodWithName(TestBean.class, "hashCode")); + assertTrue(ClassUtils.hasAtLeastOneMethodWithName(TestObject.class, "hashCode")); // matches although it takes an arg - assertTrue(ClassUtils.hasAtLeastOneMethodWithName(TestBean.class, "setAge")); + assertTrue(ClassUtils.hasAtLeastOneMethodWithName(TestObject.class, "setAge")); } public void testNoArgsStaticMethod() throws IllegalAccessException, InvocationTargetException { @@ -260,12 +260,12 @@ public class ClassUtilsTests extends TestCase { } public void testGetAllInterfaces() { - DerivedTestBean testBean = new DerivedTestBean(); + DerivedTestObject testBean = new DerivedTestObject(); List ifcs = Arrays.asList(ClassUtils.getAllInterfaces(testBean)); assertEquals("Correct number of interfaces", 4, ifcs.size()); assertTrue("Contains Serializable", ifcs.contains(Serializable.class)); - assertTrue("Contains ITestBean", ifcs.contains(ITestBean.class)); - assertTrue("Contains IOther", ifcs.contains(IOther.class)); + assertTrue("Contains ITestBean", ifcs.contains(ITestObject.class)); + assertTrue("Contains IOther", ifcs.contains(ITestInterface.class)); } public void testClassNamesToString() { diff --git a/spring-core/src/test/java/org/springframework/util/ReflectionUtilsTests.java b/spring-core/src/test/java/org/springframework/util/ReflectionUtilsTests.java index d0eb51d285..44025a090f 100644 --- a/spring-core/src/test/java/org/springframework/util/ReflectionUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/ReflectionUtilsTests.java @@ -35,7 +35,7 @@ import java.util.List; import org.junit.Ignore; import org.junit.Test; -import org.springframework.beans.TestBean; +import org.springframework.tests.sample.objects.TestObject; /** * @author Rob Harrop @@ -47,19 +47,19 @@ public class ReflectionUtilsTests { @Test public void findField() { - Field field = ReflectionUtils.findField(TestBeanSubclassWithPublicField.class, "publicField", String.class); + Field field = ReflectionUtils.findField(TestObjectSubclassWithPublicField.class, "publicField", String.class); assertNotNull(field); assertEquals("publicField", field.getName()); assertEquals(String.class, field.getType()); assertTrue("Field should be public.", Modifier.isPublic(field.getModifiers())); - field = ReflectionUtils.findField(TestBeanSubclassWithNewField.class, "prot", String.class); + field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "prot", String.class); assertNotNull(field); assertEquals("prot", field.getName()); assertEquals(String.class, field.getType()); assertTrue("Field should be protected.", Modifier.isProtected(field.getModifiers())); - field = ReflectionUtils.findField(TestBeanSubclassWithNewField.class, "name", String.class); + field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "name", String.class); assertNotNull(field); assertEquals("name", field.getName()); assertEquals(String.class, field.getType()); @@ -68,8 +68,8 @@ public class ReflectionUtilsTests { @Test public void setField() { - final TestBeanSubclassWithNewField testBean = new TestBeanSubclassWithNewField(); - final Field field = ReflectionUtils.findField(TestBeanSubclassWithNewField.class, "name", String.class); + final TestObjectSubclassWithNewField testBean = new TestObjectSubclassWithNewField(); + final Field field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "name", String.class); ReflectionUtils.makeAccessible(field); @@ -83,8 +83,8 @@ public class ReflectionUtilsTests { @Test(expected = IllegalStateException.class) public void setFieldIllegal() { - final TestBeanSubclassWithNewField testBean = new TestBeanSubclassWithNewField(); - final Field field = ReflectionUtils.findField(TestBeanSubclassWithNewField.class, "name", String.class); + final TestObjectSubclassWithNewField testBean = new TestObjectSubclassWithNewField(); + final Field field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "name", String.class); ReflectionUtils.setField(field, testBean, "FooBar"); } @@ -92,11 +92,11 @@ public class ReflectionUtilsTests { public void invokeMethod() throws Exception { String rob = "Rob Harrop"; - TestBean bean = new TestBean(); + TestObject bean = new TestObject(); bean.setName(rob); - Method getName = TestBean.class.getMethod("getName", (Class[]) null); - Method setName = TestBean.class.getMethod("setName", new Class[] { String.class }); + Method getName = TestObject.class.getMethod("getName", (Class[]) null); + Method setName = TestObject.class.getMethod("setName", new Class[] { String.class }); Object name = ReflectionUtils.invokeMethod(getName, bean); assertEquals("Incorrect name returned", rob, name); @@ -123,7 +123,7 @@ public class ReflectionUtilsTests { @Test public void copySrcToDestinationOfIncorrectClass() { - TestBean src = new TestBean(); + TestObject src = new TestObject(); String dest = new String(); try { ReflectionUtils.shallowCopyFieldState(src, dest); @@ -135,7 +135,7 @@ public class ReflectionUtilsTests { @Test public void rejectsNullSrc() { - TestBean src = null; + TestObject src = null; String dest = new String(); try { ReflectionUtils.shallowCopyFieldState(src, dest); @@ -147,7 +147,7 @@ public class ReflectionUtilsTests { @Test public void rejectsNullDest() { - TestBean src = new TestBean(); + TestObject src = new TestObject(); String dest = null; try { ReflectionUtils.shallowCopyFieldState(src, dest); @@ -159,15 +159,15 @@ public class ReflectionUtilsTests { @Test public void validCopy() { - TestBean src = new TestBean(); - TestBean dest = new TestBean(); + TestObject src = new TestObject(); + TestObject dest = new TestObject(); testValidCopy(src, dest); } @Test public void validCopyOnSubTypeWithNewField() { - TestBeanSubclassWithNewField src = new TestBeanSubclassWithNewField(); - TestBeanSubclassWithNewField dest = new TestBeanSubclassWithNewField(); + TestObjectSubclassWithNewField src = new TestObjectSubclassWithNewField(); + TestObjectSubclassWithNewField dest = new TestObjectSubclassWithNewField(); src.magic = 11; // Will check inherited fields are copied @@ -180,8 +180,8 @@ public class ReflectionUtilsTests { @Test public void validCopyToSubType() { - TestBean src = new TestBean(); - TestBeanSubclassWithNewField dest = new TestBeanSubclassWithNewField(); + TestObject src = new TestObject(); + TestObjectSubclassWithNewField dest = new TestObjectSubclassWithNewField(); dest.magic = 11; testValidCopy(src, dest); // Should have left this one alone @@ -190,28 +190,27 @@ public class ReflectionUtilsTests { @Test public void validCopyToSubTypeWithFinalField() { - TestBeanSubclassWithFinalField src = new TestBeanSubclassWithFinalField(); - TestBeanSubclassWithFinalField dest = new TestBeanSubclassWithFinalField(); + TestObjectSubclassWithFinalField src = new TestObjectSubclassWithFinalField(); + TestObjectSubclassWithFinalField dest = new TestObjectSubclassWithFinalField(); // Check that this doesn't fail due to attempt to assign final testValidCopy(src, dest); } - private void testValidCopy(TestBean src, TestBean dest) { + private void testValidCopy(TestObject src, TestObject dest) { src.setName("freddie"); src.setAge(15); - src.setSpouse(new TestBean()); + src.setSpouse(new TestObject()); assertFalse(src.getAge() == dest.getAge()); ReflectionUtils.shallowCopyFieldState(src, dest); assertEquals(src.getAge(), dest.getAge()); assertEquals(src.getSpouse(), dest.getSpouse()); - assertEquals(src.getDoctor(), dest.getDoctor()); } @Test public void doWithProtectedMethods() { ListSavingMethodCallback mc = new ListSavingMethodCallback(); - ReflectionUtils.doWithMethods(TestBean.class, mc, new ReflectionUtils.MethodFilter() { + ReflectionUtils.doWithMethods(TestObject.class, mc, new ReflectionUtils.MethodFilter() { @Override public boolean matches(Method m) { return Modifier.isProtected(m.getModifiers()); @@ -227,7 +226,7 @@ public class ReflectionUtilsTests { @Test public void duplicatesFound() { ListSavingMethodCallback mc = new ListSavingMethodCallback(); - ReflectionUtils.doWithMethods(TestBeanSubclass.class, mc); + ReflectionUtils.doWithMethods(TestObjectSubclass.class, mc); int absquatulateCount = 0; for (String name : mc.getMethodNames()) { if (name.equals("absquatulate")) { @@ -370,7 +369,7 @@ public class ReflectionUtilsTests { } } - private static class TestBeanSubclass extends TestBean { + private static class TestObjectSubclass extends TestObject { @Override public void absquatulate() { @@ -378,20 +377,20 @@ public class ReflectionUtilsTests { } } - private static class TestBeanSubclassWithPublicField extends TestBean { + private static class TestObjectSubclassWithPublicField extends TestObject { @SuppressWarnings("unused") public String publicField = "foo"; } - private static class TestBeanSubclassWithNewField extends TestBean { + private static class TestObjectSubclassWithNewField extends TestObject { private int magic; protected String prot = "foo"; } - private static class TestBeanSubclassWithFinalField extends TestBean { + private static class TestObjectSubclassWithFinalField extends TestObject { @SuppressWarnings("unused") private final String foo = "will break naive copy that doesn't exclude statics"; diff --git a/spring-core/src/test/java/org/springframework/util/SerializationTestUtils.java b/spring-core/src/test/java/org/springframework/util/SerializationTestUtils.java index 39a7582e83..0d7fcdd3c4 100644 --- a/spring-core/src/test/java/org/springframework/util/SerializationTestUtils.java +++ b/spring-core/src/test/java/org/springframework/util/SerializationTestUtils.java @@ -17,7 +17,7 @@ import java.io.Serializable; import junit.framework.TestCase; -import org.springframework.beans.TestBean; +import org.springframework.tests.sample.objects.TestObject; /** * Utilities for testing serializability of objects. @@ -64,7 +64,7 @@ public class SerializationTestUtils extends TestCase { } public void testWithNonSerializableObject() throws IOException { - TestBean o = new TestBean(); + TestObject o = new TestObject(); assertFalse(o instanceof Serializable); assertFalse(isSerializable(o));