moving unit tests from .testsuite -> .core

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@431 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Chris Beams 2008-12-16 17:04:43 +00:00
parent 73c1bbfeb8
commit dfce78549e
2 changed files with 27 additions and 83 deletions

View File

@ -39,21 +39,18 @@ import java.util.concurrent.Delayed;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;
/** /**
* @author Rob Harrop * @author Rob Harrop
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams
*/ */
public class BridgeMethodResolverTests { public class BridgeMethodResolverTests {
private static TypeVariable findTypeVariable(Class clazz, String name) { private static TypeVariable<?> findTypeVariable(Class<?> clazz, String name) {
TypeVariable[] variables = clazz.getTypeParameters(); TypeVariable<?>[] variables = clazz.getTypeParameters();
for (int i = 0; i < variables.length; i++) { for (int i = 0; i < variables.length; i++) {
TypeVariable variable = variables[i]; TypeVariable<?> variable = variables[i];
if (variable.getName().equals(name)) { if (variable.getName().equals(name)) {
return variable; return variable;
} }
@ -61,7 +58,7 @@ public class BridgeMethodResolverTests {
return null; return null;
} }
private static Method findMethodWithReturnType(String name, Class returnType, Class targetType) { private static Method findMethodWithReturnType(String name, Class<?> returnType, Class<SettingsDaoImpl> targetType) {
Method[] methods = targetType.getMethods(); Method[] methods = targetType.getMethods();
for (Method m : methods) { for (Method m : methods) {
if (m.getName().equals(name) && m.getReturnType().equals(returnType)) { if (m.getName().equals(name) && m.getReturnType().equals(returnType)) {
@ -108,7 +105,7 @@ public class BridgeMethodResolverTests {
@Test @Test
public void testIsBridgeMethodFor() throws Exception { public void testIsBridgeMethodFor() throws Exception {
Map typeParameterMap = GenericTypeResolver.getTypeVariableMap(MyBar.class); Map<TypeVariable, Type> typeParameterMap = GenericTypeResolver.getTypeVariableMap(MyBar.class);
Method bridged = MyBar.class.getDeclaredMethod("someMethod", String.class, Object.class); Method bridged = MyBar.class.getDeclaredMethod("someMethod", String.class, Object.class);
Method other = MyBar.class.getDeclaredMethod("someMethod", Integer.class, Object.class); Method other = MyBar.class.getDeclaredMethod("someMethod", Integer.class, Object.class);
Method bridge = MyBar.class.getDeclaredMethod("someMethod", Object.class, Object.class); Method bridge = MyBar.class.getDeclaredMethod("someMethod", Object.class, Object.class);
@ -120,17 +117,17 @@ public class BridgeMethodResolverTests {
@Test @Test
public void testCreateTypeVariableMap() throws Exception { public void testCreateTypeVariableMap() throws Exception {
Map<TypeVariable, Type> typeVariableMap = GenericTypeResolver.getTypeVariableMap(MyBar.class); Map<TypeVariable, Type> typeVariableMap = GenericTypeResolver.getTypeVariableMap(MyBar.class);
TypeVariable barT = findTypeVariable(InterBar.class, "T"); TypeVariable<?> barT = findTypeVariable(InterBar.class, "T");
assertEquals(String.class, typeVariableMap.get(barT)); assertEquals(String.class, typeVariableMap.get(barT));
typeVariableMap = GenericTypeResolver.getTypeVariableMap(MyFoo.class); typeVariableMap = GenericTypeResolver.getTypeVariableMap(MyFoo.class);
TypeVariable fooT = findTypeVariable(Foo.class, "T"); TypeVariable<?> fooT = findTypeVariable(Foo.class, "T");
assertEquals(String.class, typeVariableMap.get(fooT)); assertEquals(String.class, typeVariableMap.get(fooT));
typeVariableMap = GenericTypeResolver.getTypeVariableMap(ExtendsEnclosing.ExtendsEnclosed.ExtendsReallyDeepNow.class); typeVariableMap = GenericTypeResolver.getTypeVariableMap(ExtendsEnclosing.ExtendsEnclosed.ExtendsReallyDeepNow.class);
TypeVariable r = findTypeVariable(Enclosing.Enclosed.ReallyDeepNow.class, "R"); TypeVariable<?> r = findTypeVariable(Enclosing.Enclosed.ReallyDeepNow.class, "R");
TypeVariable s = findTypeVariable(Enclosing.Enclosed.class, "S"); TypeVariable<?> s = findTypeVariable(Enclosing.Enclosed.class, "S");
TypeVariable t = findTypeVariable(Enclosing.class, "T"); TypeVariable<?> t = findTypeVariable(Enclosing.class, "T");
assertEquals(Long.class, typeVariableMap.get(r)); assertEquals(Long.class, typeVariableMap.get(r));
assertEquals(Integer.class, typeVariableMap.get(s)); assertEquals(Integer.class, typeVariableMap.get(s));
assertEquals(String.class, typeVariableMap.get(t)); assertEquals(String.class, typeVariableMap.get(t));
@ -238,7 +235,7 @@ public class BridgeMethodResolverTests {
Method otherMethod = MessageBroadcasterImpl.class.getMethod("receive", NewMessageEvent.class); Method otherMethod = MessageBroadcasterImpl.class.getMethod("receive", NewMessageEvent.class);
assertFalse(otherMethod.isBridge()); assertFalse(otherMethod.isBridge());
Map typeVariableMap = GenericTypeResolver.getTypeVariableMap(MessageBroadcasterImpl.class); Map<TypeVariable, Type> typeVariableMap = GenericTypeResolver.getTypeVariableMap(MessageBroadcasterImpl.class);
assertFalse("Match identified incorrectly", BridgeMethodResolver.isBridgeMethodFor(bridgeMethod, otherMethod, typeVariableMap)); assertFalse("Match identified incorrectly", BridgeMethodResolver.isBridgeMethodFor(bridgeMethod, otherMethod, typeVariableMap));
assertTrue("Match not found correctly", BridgeMethodResolver.isBridgeMethodFor(bridgeMethod, bridgedMethod, typeVariableMap)); assertTrue("Match not found correctly", BridgeMethodResolver.isBridgeMethodFor(bridgeMethod, bridgedMethod, typeVariableMap));
@ -247,8 +244,8 @@ public class BridgeMethodResolverTests {
@Test @Test
public void testSPR2454() throws Exception { public void testSPR2454() throws Exception {
Map typeVariableMap = GenericTypeResolver.getTypeVariableMap(YourHomer.class); Map<?, ?> typeVariableMap = GenericTypeResolver.getTypeVariableMap(YourHomer.class);
TypeVariable variable = findTypeVariable(MyHomer.class, "L"); TypeVariable<?> variable = findTypeVariable(MyHomer.class, "L");
assertEquals(AbstractBounded.class, ((ParameterizedType) typeVariableMap.get(variable)).getRawType()); assertEquals(AbstractBounded.class, ((ParameterizedType) typeVariableMap.get(variable)).getRawType());
} }
@ -402,10 +399,10 @@ public class BridgeMethodResolverTests {
public static abstract class Bar<T> { public static abstract class Bar<T> {
void someMethod(Map m, Object otherArg) { void someMethod(Map<?, ?> m, Object otherArg) {
} }
void someMethod(T theArg, Map m) { void someMethod(T theArg, Map<?, ?> m) {
} }
abstract void someMethod(T theArg, Object otherArg); abstract void someMethod(T theArg, Object otherArg);
@ -535,7 +532,7 @@ public class BridgeMethodResolverTests {
this.otherObject = otherObject; this.otherObject = otherObject;
} }
@Transactional(readOnly = true) //@Transactional(readOnly = true)
public S loadFromParent() { public S loadFromParent() {
return otherObject; return otherObject;
} }
@ -548,7 +545,7 @@ public class BridgeMethodResolverTests {
super(object, "From Parent"); super(object, "From Parent");
} }
@Transactional(readOnly = true) //@Transactional(readOnly = true)
public ConcreteSettings load() { public ConcreteSettings load() {
return super.object; return super.object;
} }
@ -757,7 +754,7 @@ public class BridgeMethodResolverTests {
public void unsubscribe(); public void unsubscribe();
public void setChannel(Channel channel); public void setChannel(Channel<?> channel);
} }
@ -767,7 +764,7 @@ public class BridgeMethodResolverTests {
public abstract class GenericEventBroadcasterImpl<T extends Event> extends GenericBroadcasterImpl public abstract class GenericEventBroadcasterImpl<T extends Event> extends GenericBroadcasterImpl
implements EventBroadcaster, BeanNameAware { implements EventBroadcaster {
private Class<T>[] subscribingEvents; private Class<T>[] subscribingEvents;
@ -889,7 +886,7 @@ public class BridgeMethodResolverTests {
public class SettableRepositoryRegistry<R extends SimpleGenericRepository<?>> public class SettableRepositoryRegistry<R extends SimpleGenericRepository<?>>
implements RepositoryRegistry, InitializingBean { implements RepositoryRegistry {
protected void injectInto(R rep) { protected void injectInto(R rep) {
} }
@ -924,7 +921,7 @@ public class BridgeMethodResolverTests {
} }
public class GenericHibernateRepository<T, ID extends Serializable> extends HibernateDaoSupport public class GenericHibernateRepository<T, ID extends Serializable>
implements ConvenientGenericRepository<T, ID> { implements ConvenientGenericRepository<T, ID> {
/** /**
@ -1049,10 +1046,10 @@ public class BridgeMethodResolverTests {
public interface UserDao { public interface UserDao {
@Transactional //@Transactional
void save(User user); void save(User user);
@Transactional //@Transactional
void save(Permission perm); void save(Permission perm);
} }
@ -1208,6 +1205,7 @@ public class BridgeMethodResolverTests {
// SPR-3485 classes // SPR-3485 classes
//------------------- //-------------------
@SuppressWarnings("serial")
private static class ParameterType implements Serializable { private static class ParameterType implements Serializable {
} }
@ -1251,7 +1249,7 @@ public class BridgeMethodResolverTests {
} }
public interface IExternalMessageProvider<S extends ExternalMessage, T extends ExternalMessageSearchConditions> public interface IExternalMessageProvider<S extends ExternalMessage, T extends ExternalMessageSearchConditions<?>>
extends SearchProvider<S, T> { extends SearchProvider<S, T> {
} }

View File

@ -1,54 +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.core;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import junit.framework.TestCase;
/**
* @author Serge Bogatyrjov
*/
public abstract class AbstractGenericsTests extends TestCase {
protected Class<?> targetClass;
protected String methods[];
protected Type expectedResults[];
protected void executeTest() throws NoSuchMethodException {
String methodName = getName().substring(4);
methodName = methodName.substring(0, 1).toLowerCase() + methodName.substring(1);
for (int i = 0; i < this.methods.length; i++) {
if (methodName.equals(this.methods[i])) {
Method method = this.targetClass.getMethod(methodName);
Type type = getType(method);
assertEquals(this.expectedResults[i], type);
return;
}
}
throw new IllegalStateException("Bad test data");
}
protected abstract Type getType(Method method);
}