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.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 Juergen Hoeller
* @author Chris Beams
*/
public class BridgeMethodResolverTests {
private static TypeVariable findTypeVariable(Class clazz, String name) {
TypeVariable[] variables = clazz.getTypeParameters();
private static TypeVariable<?> findTypeVariable(Class<?> clazz, String name) {
TypeVariable<?>[] variables = clazz.getTypeParameters();
for (int i = 0; i < variables.length; i++) {
TypeVariable variable = variables[i];
TypeVariable<?> variable = variables[i];
if (variable.getName().equals(name)) {
return variable;
}
@ -61,7 +58,7 @@ public class BridgeMethodResolverTests {
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();
for (Method m : methods) {
if (m.getName().equals(name) && m.getReturnType().equals(returnType)) {
@ -108,7 +105,7 @@ public class BridgeMethodResolverTests {
@Test
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 other = MyBar.class.getDeclaredMethod("someMethod", Integer.class, Object.class);
Method bridge = MyBar.class.getDeclaredMethod("someMethod", Object.class, Object.class);
@ -120,17 +117,17 @@ public class BridgeMethodResolverTests {
@Test
public void testCreateTypeVariableMap() throws Exception {
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));
typeVariableMap = GenericTypeResolver.getTypeVariableMap(MyFoo.class);
TypeVariable fooT = findTypeVariable(Foo.class, "T");
TypeVariable<?> fooT = findTypeVariable(Foo.class, "T");
assertEquals(String.class, typeVariableMap.get(fooT));
typeVariableMap = GenericTypeResolver.getTypeVariableMap(ExtendsEnclosing.ExtendsEnclosed.ExtendsReallyDeepNow.class);
TypeVariable r = findTypeVariable(Enclosing.Enclosed.ReallyDeepNow.class, "R");
TypeVariable s = findTypeVariable(Enclosing.Enclosed.class, "S");
TypeVariable t = findTypeVariable(Enclosing.class, "T");
TypeVariable<?> r = findTypeVariable(Enclosing.Enclosed.ReallyDeepNow.class, "R");
TypeVariable<?> s = findTypeVariable(Enclosing.Enclosed.class, "S");
TypeVariable<?> t = findTypeVariable(Enclosing.class, "T");
assertEquals(Long.class, typeVariableMap.get(r));
assertEquals(Integer.class, typeVariableMap.get(s));
assertEquals(String.class, typeVariableMap.get(t));
@ -238,7 +235,7 @@ public class BridgeMethodResolverTests {
Method otherMethod = MessageBroadcasterImpl.class.getMethod("receive", NewMessageEvent.class);
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));
assertTrue("Match not found correctly", BridgeMethodResolver.isBridgeMethodFor(bridgeMethod, bridgedMethod, typeVariableMap));
@ -247,8 +244,8 @@ public class BridgeMethodResolverTests {
@Test
public void testSPR2454() throws Exception {
Map typeVariableMap = GenericTypeResolver.getTypeVariableMap(YourHomer.class);
TypeVariable variable = findTypeVariable(MyHomer.class, "L");
Map<?, ?> typeVariableMap = GenericTypeResolver.getTypeVariableMap(YourHomer.class);
TypeVariable<?> variable = findTypeVariable(MyHomer.class, "L");
assertEquals(AbstractBounded.class, ((ParameterizedType) typeVariableMap.get(variable)).getRawType());
}
@ -402,10 +399,10 @@ public class BridgeMethodResolverTests {
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);
@ -535,7 +532,7 @@ public class BridgeMethodResolverTests {
this.otherObject = otherObject;
}
@Transactional(readOnly = true)
//@Transactional(readOnly = true)
public S loadFromParent() {
return otherObject;
}
@ -548,7 +545,7 @@ public class BridgeMethodResolverTests {
super(object, "From Parent");
}
@Transactional(readOnly = true)
//@Transactional(readOnly = true)
public ConcreteSettings load() {
return super.object;
}
@ -757,7 +754,7 @@ public class BridgeMethodResolverTests {
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
implements EventBroadcaster, BeanNameAware {
implements EventBroadcaster {
private Class<T>[] subscribingEvents;
@ -889,7 +886,7 @@ public class BridgeMethodResolverTests {
public class SettableRepositoryRegistry<R extends SimpleGenericRepository<?>>
implements RepositoryRegistry, InitializingBean {
implements RepositoryRegistry {
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> {
/**
@ -1049,10 +1046,10 @@ public class BridgeMethodResolverTests {
public interface UserDao {
@Transactional
//@Transactional
void save(User user);
@Transactional
//@Transactional
void save(Permission perm);
}
@ -1208,7 +1205,8 @@ public class BridgeMethodResolverTests {
// SPR-3485 classes
//-------------------
private static class ParameterType implements Serializable {
@SuppressWarnings("serial")
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> {
}

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