Polish various test classes
This commit is contained in:
parent
e865d63c29
commit
1ade9b5433
|
@ -1,51 +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);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
@ -16,48 +16,48 @@
|
||||||
|
|
||||||
package org.springframework.core;
|
package org.springframework.core;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class AttributeAccessorSupportTests extends TestCase {
|
public class AttributeAccessorSupportTests {
|
||||||
|
|
||||||
private static final String NAME = "foo";
|
private static final String NAME = "foo";
|
||||||
|
|
||||||
private static final String VALUE = "bar";
|
private static final String VALUE = "bar";
|
||||||
|
|
||||||
private AttributeAccessor attributeAccessor;
|
private AttributeAccessor attributeAccessor = new SimpleAttributeAccessorSupport();
|
||||||
|
|
||||||
@Override
|
@Test
|
||||||
@SuppressWarnings("serial")
|
public void setAndGet() throws Exception {
|
||||||
protected void setUp() throws Exception {
|
|
||||||
this.attributeAccessor = new AttributeAccessorSupport() {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSetAndGet() throws Exception {
|
|
||||||
this.attributeAccessor.setAttribute(NAME, VALUE);
|
this.attributeAccessor.setAttribute(NAME, VALUE);
|
||||||
assertEquals(VALUE, this.attributeAccessor.getAttribute(NAME));
|
assertEquals(VALUE, this.attributeAccessor.getAttribute(NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetAndHas() throws Exception {
|
@Test
|
||||||
|
public void setAndHas() throws Exception {
|
||||||
assertFalse(this.attributeAccessor.hasAttribute(NAME));
|
assertFalse(this.attributeAccessor.hasAttribute(NAME));
|
||||||
this.attributeAccessor.setAttribute(NAME, VALUE);
|
this.attributeAccessor.setAttribute(NAME, VALUE);
|
||||||
assertTrue(this.attributeAccessor.hasAttribute(NAME));
|
assertTrue(this.attributeAccessor.hasAttribute(NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemove() throws Exception {
|
@Test
|
||||||
|
public void remove() throws Exception {
|
||||||
assertFalse(this.attributeAccessor.hasAttribute(NAME));
|
assertFalse(this.attributeAccessor.hasAttribute(NAME));
|
||||||
this.attributeAccessor.setAttribute(NAME, VALUE);
|
this.attributeAccessor.setAttribute(NAME, VALUE);
|
||||||
assertEquals(VALUE, this.attributeAccessor.removeAttribute(NAME));
|
assertEquals(VALUE, this.attributeAccessor.removeAttribute(NAME));
|
||||||
assertFalse(this.attributeAccessor.hasAttribute(NAME));
|
assertFalse(this.attributeAccessor.hasAttribute(NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAttributeNames() throws Exception {
|
@Test
|
||||||
|
public void attributeNames() throws Exception {
|
||||||
this.attributeAccessor.setAttribute(NAME, VALUE);
|
this.attributeAccessor.setAttribute(NAME, VALUE);
|
||||||
this.attributeAccessor.setAttribute("abc", "123");
|
this.attributeAccessor.setAttribute("abc", "123");
|
||||||
String[] attributeNames = this.attributeAccessor.attributeNames();
|
String[] attributeNames = this.attributeAccessor.attributeNames();
|
||||||
|
@ -65,8 +65,9 @@ public class AttributeAccessorSupportTests extends TestCase {
|
||||||
assertTrue(Arrays.binarySearch(attributeNames, NAME) > -1);
|
assertTrue(Arrays.binarySearch(attributeNames, NAME) > -1);
|
||||||
assertTrue(Arrays.binarySearch(attributeNames, "abc") > -1);
|
assertTrue(Arrays.binarySearch(attributeNames, "abc") > -1);
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
protected void tearDown() throws Exception {
|
@SuppressWarnings("serial")
|
||||||
this.attributeAccessor.removeAttribute(NAME);
|
private static class SimpleAttributeAccessorSupport extends AttributeAccessorSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
@ -394,20 +394,20 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface Adder<T> {
|
public static interface Adder<T> {
|
||||||
|
|
||||||
void add(T item);
|
void add(T item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract class AbstractDateAdder implements Adder<Date> {
|
public static abstract class AbstractDateAdder implements Adder<Date> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void add(Date date);
|
public abstract void add(Date date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class DateAdder extends AbstractDateAdder {
|
public static class DateAdder extends AbstractDateAdder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(Date date) {
|
public void add(Date date) {
|
||||||
|
@ -415,7 +415,7 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class Enclosing<T> {
|
public static class Enclosing<T> {
|
||||||
|
|
||||||
public class Enclosed<S> {
|
public class Enclosed<S> {
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class ExtendsEnclosing extends Enclosing<String> {
|
public static class ExtendsEnclosing extends Enclosing<String> {
|
||||||
|
|
||||||
public class ExtendsEnclosed extends Enclosed<Integer> {
|
public class ExtendsEnclosed extends Enclosed<Integer> {
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface Boo<E, T extends Serializable> {
|
public static interface Boo<E, T extends Serializable> {
|
||||||
|
|
||||||
void foo(E e);
|
void foo(E e);
|
||||||
|
|
||||||
|
@ -451,7 +451,7 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class MyBoo implements Boo<String, Integer> {
|
public static class MyBoo implements Boo<String, Integer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void foo(String e) {
|
public void foo(String e) {
|
||||||
|
@ -465,17 +465,17 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface Settings {
|
public static interface Settings {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface ConcreteSettings extends Settings {
|
public static interface ConcreteSettings extends Settings {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface Dao<T, S> {
|
public static interface Dao<T, S> {
|
||||||
|
|
||||||
T load();
|
T load();
|
||||||
|
|
||||||
|
@ -483,21 +483,22 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface SettingsDao<T extends Settings, S> extends Dao<T, S> {
|
public static interface SettingsDao<T extends Settings, S> extends Dao<T, S> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
T load();
|
T load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface ConcreteSettingsDao extends SettingsDao<ConcreteSettings, String> {
|
public static interface ConcreteSettingsDao extends
|
||||||
|
SettingsDao<ConcreteSettings, String> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String loadFromParent();
|
String loadFromParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
abstract class AbstractDaoImpl<T, S> implements Dao<T, S> {
|
static abstract class AbstractDaoImpl<T, S> implements Dao<T, S> {
|
||||||
|
|
||||||
protected T object;
|
protected T object;
|
||||||
|
|
||||||
|
@ -516,7 +517,8 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SettingsDaoImpl extends AbstractDaoImpl<ConcreteSettings, String> implements ConcreteSettingsDao {
|
static class SettingsDaoImpl extends AbstractDaoImpl<ConcreteSettings, String>
|
||||||
|
implements ConcreteSettingsDao {
|
||||||
|
|
||||||
protected SettingsDaoImpl(ConcreteSettings object) {
|
protected SettingsDaoImpl(ConcreteSettings object) {
|
||||||
super(object, "From Parent");
|
super(object, "From Parent");
|
||||||
|
@ -693,13 +695,13 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface Event {
|
public static interface Event {
|
||||||
|
|
||||||
int getPriority();
|
int getPriority();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class GenericEvent implements Event {
|
public static class GenericEvent implements Event {
|
||||||
|
|
||||||
private int priority;
|
private int priority;
|
||||||
|
|
||||||
|
@ -723,23 +725,24 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface UserInitiatedEvent {
|
public static interface UserInitiatedEvent {
|
||||||
|
|
||||||
//public Session getInitiatorSession();
|
//public Session getInitiatorSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract class BaseUserInitiatedEvent extends GenericEvent implements UserInitiatedEvent {
|
public static abstract class BaseUserInitiatedEvent extends GenericEvent implements
|
||||||
|
UserInitiatedEvent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class MessageEvent extends BaseUserInitiatedEvent {
|
public static class MessageEvent extends BaseUserInitiatedEvent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface Channel<E extends Event> {
|
public static interface Channel<E extends Event> {
|
||||||
|
|
||||||
void send(E event);
|
void send(E event);
|
||||||
|
|
||||||
|
@ -749,11 +752,11 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface Broadcaster {
|
public static interface Broadcaster {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface EventBroadcaster extends Broadcaster {
|
public static interface EventBroadcaster extends Broadcaster {
|
||||||
|
|
||||||
public void subscribe();
|
public void subscribe();
|
||||||
|
|
||||||
|
@ -763,13 +766,14 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class GenericBroadcasterImpl implements Broadcaster {
|
public static class GenericBroadcasterImpl implements Broadcaster {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings({ "unused", "unchecked" })
|
@SuppressWarnings({ "unused", "unchecked" })
|
||||||
public abstract class GenericEventBroadcasterImpl<T extends Event> extends GenericBroadcasterImpl
|
public static abstract class GenericEventBroadcasterImpl<T extends Event> extends
|
||||||
|
GenericBroadcasterImpl
|
||||||
implements EventBroadcaster {
|
implements EventBroadcaster {
|
||||||
|
|
||||||
private Class<T>[] subscribingEvents;
|
private Class<T>[] subscribingEvents;
|
||||||
|
@ -810,34 +814,35 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface Receiver<E extends Event> {
|
public static interface Receiver<E extends Event> {
|
||||||
|
|
||||||
void receive(E event);
|
void receive(E event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface MessageBroadcaster extends Receiver<MessageEvent> {
|
public static interface MessageBroadcaster extends Receiver<MessageEvent> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class RemovedMessageEvent extends MessageEvent {
|
public static class RemovedMessageEvent extends MessageEvent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class NewMessageEvent extends MessageEvent {
|
public static class NewMessageEvent extends MessageEvent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class ModifiedMessageEvent extends MessageEvent {
|
public static class ModifiedMessageEvent extends MessageEvent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class MessageBroadcasterImpl extends GenericEventBroadcasterImpl<MessageEvent>
|
public static class MessageBroadcasterImpl extends
|
||||||
|
GenericEventBroadcasterImpl<MessageEvent>
|
||||||
implements MessageBroadcaster {
|
implements MessageBroadcaster {
|
||||||
|
|
||||||
public MessageBroadcasterImpl() {
|
public MessageBroadcasterImpl() {
|
||||||
|
@ -869,7 +874,7 @@ public class BridgeMethodResolverTests {
|
||||||
// SPR-2454 Test Classes
|
// SPR-2454 Test Classes
|
||||||
//-----------------------------
|
//-----------------------------
|
||||||
|
|
||||||
public interface SimpleGenericRepository<T> {
|
public static interface SimpleGenericRepository<T> {
|
||||||
|
|
||||||
public Class<T> getPersistentClass();
|
public Class<T> getPersistentClass();
|
||||||
|
|
||||||
|
@ -885,14 +890,14 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface RepositoryRegistry {
|
public static interface RepositoryRegistry {
|
||||||
|
|
||||||
<T> SimpleGenericRepository<T> getFor(Class<T> entityType);
|
<T> SimpleGenericRepository<T> getFor(Class<T> entityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class SettableRepositoryRegistry<R extends SimpleGenericRepository<?>>
|
public static class SettableRepositoryRegistry<R extends SimpleGenericRepository<?>>
|
||||||
implements RepositoryRegistry {
|
implements RepositoryRegistry {
|
||||||
|
|
||||||
protected void injectInto(R rep) {
|
protected void injectInto(R rep) {
|
||||||
|
@ -917,7 +922,8 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface ConvenientGenericRepository<T, ID extends Serializable> extends SimpleGenericRepository<T> {
|
public static interface ConvenientGenericRepository<T, ID extends Serializable>
|
||||||
|
extends SimpleGenericRepository<T> {
|
||||||
|
|
||||||
T findById(ID id, boolean lock);
|
T findById(ID id, boolean lock);
|
||||||
|
|
||||||
|
@ -929,7 +935,7 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class GenericHibernateRepository<T, ID extends Serializable>
|
public static class GenericHibernateRepository<T, ID extends Serializable>
|
||||||
implements ConvenientGenericRepository<T, ID> {
|
implements ConvenientGenericRepository<T, ID> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -992,7 +998,8 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class HibernateRepositoryRegistry extends SettableRepositoryRegistry<GenericHibernateRepository<?, ?>> {
|
public static class HibernateRepositoryRegistry extends
|
||||||
|
SettableRepositoryRegistry<GenericHibernateRepository<?, ?>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectInto(GenericHibernateRepository<?, ?> rep) {
|
public void injectInto(GenericHibernateRepository<?, ?> rep) {
|
||||||
|
@ -1009,13 +1016,13 @@ public class BridgeMethodResolverTests {
|
||||||
// SPR-2603 classes
|
// SPR-2603 classes
|
||||||
//-------------------
|
//-------------------
|
||||||
|
|
||||||
public interface Homer<E> {
|
public static interface Homer<E> {
|
||||||
|
|
||||||
void foo(E e);
|
void foo(E e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class MyHomer<T extends Bounded<T>, L extends T> implements Homer<L> {
|
public static class MyHomer<T extends Bounded<T>, L extends T> implements Homer<L> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void foo(L t) {
|
public void foo(L t) {
|
||||||
|
@ -1024,7 +1031,8 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class YourHomer<T extends AbstractBounded<T>, L extends T> extends MyHomer<T, L> {
|
public static class YourHomer<T extends AbstractBounded<T>, L extends T> extends
|
||||||
|
MyHomer<T, L> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void foo(L t) {
|
public void foo(L t) {
|
||||||
|
@ -1033,17 +1041,18 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface GenericDao<T> {
|
public static interface GenericDao<T> {
|
||||||
|
|
||||||
public void saveOrUpdate(T t);
|
public void saveOrUpdate(T t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface ConvenienceGenericDao<T> extends GenericDao<T> {
|
public static interface ConvenienceGenericDao<T> extends GenericDao<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class GenericSqlMapDao<T extends Serializable> implements ConvenienceGenericDao<T> {
|
public static class GenericSqlMapDao<T extends Serializable> implements
|
||||||
|
ConvenienceGenericDao<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveOrUpdate(T t) {
|
public void saveOrUpdate(T t) {
|
||||||
|
@ -1052,7 +1061,8 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class GenericSqlMapIntegerDao<T extends Number> extends GenericSqlMapDao<T> {
|
public static class GenericSqlMapIntegerDao<T extends Number> extends
|
||||||
|
GenericSqlMapDao<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveOrUpdate(T t) {
|
public void saveOrUpdate(T t) {
|
||||||
|
@ -1060,15 +1070,15 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class Permission {
|
public static class Permission {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class User {
|
public static class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface UserDao {
|
public static interface UserDao {
|
||||||
|
|
||||||
//@Transactional
|
//@Transactional
|
||||||
void save(User user);
|
void save(User user);
|
||||||
|
@ -1078,7 +1088,7 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract class AbstractDao<T> {
|
public static abstract class AbstractDao<T> {
|
||||||
|
|
||||||
public void save(T t) {
|
public void save(T t) {
|
||||||
}
|
}
|
||||||
|
@ -1088,7 +1098,7 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class UserDaoImpl extends AbstractDao<User> implements UserDao {
|
public static class UserDaoImpl extends AbstractDao<User> implements UserDao {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(Permission perm) {
|
public void save(Permission perm) {
|
||||||
|
@ -1100,27 +1110,28 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface DaoInterface<T,P> {
|
public static interface DaoInterface<T, P> {
|
||||||
T get(P id);
|
T get(P id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract class BusinessGenericDao<T, PK extends Serializable> implements DaoInterface<T, PK> {
|
public static abstract class BusinessGenericDao<T, PK extends Serializable>
|
||||||
|
implements DaoInterface<T, PK> {
|
||||||
|
|
||||||
public void save(T object) {
|
public void save(T object) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class Business<T> {
|
public static class Business<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class BusinessDao extends BusinessGenericDao<Business<?>, Long> {
|
public static class BusinessDao extends BusinessGenericDao<Business<?>, Long> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(Business<?> business) {
|
public void save(Business<?> business) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Business<?> get(Long id) {
|
public Business<?> get(Long id) {
|
||||||
|
@ -1197,7 +1208,7 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface IGenericInterface<D extends DomainObjectSuper> {
|
public static interface IGenericInterface<D extends DomainObjectSuper> {
|
||||||
|
|
||||||
<T> void doSomething(final D domainObject, final T value);
|
<T> void doSomething(final D domainObject, final T value);
|
||||||
}
|
}
|
||||||
|
@ -1262,7 +1273,7 @@ public class BridgeMethodResolverTests {
|
||||||
// SPR-3534 classes
|
// SPR-3534 classes
|
||||||
//-------------------
|
//-------------------
|
||||||
|
|
||||||
public interface SearchProvider<RETURN_TYPE, CONDITIONS_TYPE> {
|
public static interface SearchProvider<RETURN_TYPE, CONDITIONS_TYPE> {
|
||||||
|
|
||||||
Collection<RETURN_TYPE> findBy(CONDITIONS_TYPE conditions);
|
Collection<RETURN_TYPE> findBy(CONDITIONS_TYPE conditions);
|
||||||
}
|
}
|
||||||
|
@ -1272,7 +1283,7 @@ public class BridgeMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface IExternalMessageProvider<S extends ExternalMessage, T extends ExternalMessageSearchConditions<?>>
|
public static interface IExternalMessageProvider<S extends ExternalMessage, T extends ExternalMessageSearchConditions<?>>
|
||||||
extends SearchProvider<S, T> {
|
extends SearchProvider<S, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
@ -16,71 +16,57 @@
|
||||||
|
|
||||||
package org.springframework.core;
|
package org.springframework.core;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractControlFlowTests extends TestCase {
|
public class ControlFlowTests {
|
||||||
|
|
||||||
protected abstract ControlFlow createControlFlow();
|
@Test
|
||||||
|
public void underClassAndMethod() {
|
||||||
/*
|
|
||||||
* Class to test for boolean under(Class)
|
|
||||||
*/
|
|
||||||
public void testUnderClassAndMethod() {
|
|
||||||
new One().test();
|
new One().test();
|
||||||
new Two().testing();
|
new Two().testing();
|
||||||
new Three().test();
|
new Three().test();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static class One {
|
||||||
public void testUnderPackage() {
|
|
||||||
ControlFlow cflow = new ControlFlow();
|
|
||||||
assertFalse(cflow.underPackage("org.springframework.aop"));
|
|
||||||
assertTrue(cflow.underPackage("org.springframework.aop.support"));
|
|
||||||
assertFalse(cflow.underPackage("com.interface21"));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
void test() {
|
||||||
public class One {
|
ControlFlow cflow = ControlFlowFactory.createControlFlow();
|
||||||
|
|
||||||
public void test() {
|
|
||||||
ControlFlow cflow = createControlFlow();
|
|
||||||
assertTrue(cflow.under(One.class));
|
assertTrue(cflow.under(One.class));
|
||||||
assertTrue(cflow.under(AbstractControlFlowTests.class));
|
assertTrue(cflow.under(ControlFlowTests.class));
|
||||||
assertFalse(cflow.under(Two.class));
|
assertFalse(cflow.under(Two.class));
|
||||||
assertTrue(cflow.under(One.class, "test"));
|
assertTrue(cflow.under(One.class, "test"));
|
||||||
assertFalse(cflow.under(One.class, "hashCode"));
|
assertFalse(cflow.under(One.class, "hashCode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class Two {
|
||||||
|
|
||||||
public class Two {
|
void testing() {
|
||||||
|
ControlFlow cflow = ControlFlowFactory.createControlFlow();
|
||||||
public void testing() {
|
|
||||||
ControlFlow cflow = createControlFlow();
|
|
||||||
assertTrue(cflow.under(Two.class));
|
assertTrue(cflow.under(Two.class));
|
||||||
assertTrue(cflow.under(AbstractControlFlowTests.class));
|
assertTrue(cflow.under(ControlFlowTests.class));
|
||||||
assertFalse(cflow.under(One.class));
|
assertFalse(cflow.under(One.class));
|
||||||
assertFalse(cflow.under(Two.class, "test"));
|
assertFalse(cflow.under(Two.class, "test"));
|
||||||
assertTrue(cflow.under(Two.class, "testing"));
|
assertTrue(cflow.under(Two.class, "testing"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class Three {
|
||||||
|
|
||||||
public class Three {
|
void test() {
|
||||||
|
|
||||||
public void test() {
|
|
||||||
testing();
|
testing();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testing() {
|
private void testing() {
|
||||||
ControlFlow cflow = createControlFlow();
|
ControlFlow cflow = ControlFlowFactory.createControlFlow();
|
||||||
assertTrue(cflow.under(Three.class));
|
assertTrue(cflow.under(Three.class));
|
||||||
assertTrue(cflow.under(AbstractControlFlowTests.class));
|
assertTrue(cflow.under(ControlFlowTests.class));
|
||||||
assertFalse(cflow.under(One.class));
|
assertFalse(cflow.under(One.class));
|
||||||
assertTrue(cflow.under(Three.class, "test"));
|
assertTrue(cflow.under(Three.class, "test"));
|
||||||
assertTrue(cflow.under(Three.class, "testing"));
|
assertTrue(cflow.under(Three.class, "testing"));
|
|
@ -1,38 +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.core;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests with ControlFlowFactory return.
|
|
||||||
*
|
|
||||||
* @author Rod Johnson
|
|
||||||
*/
|
|
||||||
public class DefaultControlFlowTests extends AbstractControlFlowTests {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Necessary only because Eclipse won't run test suite unless
|
|
||||||
* it declares some methods as well as inherited methods.
|
|
||||||
*/
|
|
||||||
public void testThisClassPlease() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ControlFlow createControlFlow() {
|
|
||||||
return ControlFlowFactory.createControlFlow();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 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,103 +25,141 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.tests.sample.objects.GenericObject;
|
import org.springframework.tests.sample.objects.GenericObject;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Serge Bogatyrjov
|
* @author Serge Bogatyrjov
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class GenericCollectionTypeResolverTests extends AbstractGenericsTests {
|
public class GenericCollectionTypeResolverTests {
|
||||||
|
|
||||||
@Override
|
protected Class<?> targetClass;
|
||||||
protected void setUp() throws Exception {
|
|
||||||
|
protected String[] methods;
|
||||||
|
|
||||||
|
protected Type[] expectedResults;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
this.targetClass = Foo.class;
|
this.targetClass = Foo.class;
|
||||||
this.methods = new String[] {"a", "b", "b2", "b3", "c", "d", "d2", "d3", "e", "e2", "e3"};
|
this.methods = new String[] { "a", "b", "b2", "b3", "c", "d", "d2", "d3", "e",
|
||||||
this.expectedResults = new Class[] {
|
"e2", "e3" };
|
||||||
Integer.class, null, Set.class, Set.class, null, Integer.class,
|
this.expectedResults = new Class[] { Integer.class, null, Set.class, Set.class,
|
||||||
Integer.class, Integer.class, Integer.class, Integer.class, Integer.class};
|
null, Integer.class, Integer.class, Integer.class, Integer.class,
|
||||||
|
Integer.class, Integer.class };
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void executeTest(String methodName) throws NoSuchMethodException {
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Type getType(Method method) {
|
protected Type getType(Method method) {
|
||||||
return GenericCollectionTypeResolver.getMapValueReturnType(method);
|
return GenericCollectionTypeResolver.getMapValueReturnType(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testA() throws Exception {
|
@Test
|
||||||
executeTest();
|
public void a() throws Exception {
|
||||||
|
executeTest("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testB() throws Exception {
|
@Test
|
||||||
executeTest();
|
public void b() throws Exception {
|
||||||
|
executeTest("b");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testB2() throws Exception {
|
@Test
|
||||||
executeTest();
|
public void b2() throws Exception {
|
||||||
|
executeTest("b2");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testB3() throws Exception {
|
@Test
|
||||||
executeTest();
|
public void b3() throws Exception {
|
||||||
|
executeTest("b3");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testC() throws Exception {
|
@Test
|
||||||
executeTest();
|
public void c() throws Exception {
|
||||||
|
executeTest("c");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testD() throws Exception {
|
@Test
|
||||||
executeTest();
|
public void d() throws Exception {
|
||||||
|
executeTest("d");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testD2() throws Exception {
|
@Test
|
||||||
executeTest();
|
public void d2() throws Exception {
|
||||||
|
executeTest("d2");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testD3() throws Exception {
|
@Test
|
||||||
executeTest();
|
public void d3() throws Exception {
|
||||||
|
executeTest("d3");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testE() throws Exception {
|
@Test
|
||||||
executeTest();
|
public void e() throws Exception {
|
||||||
|
executeTest("e");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testE2() throws Exception {
|
@Test
|
||||||
executeTest();
|
public void e2() throws Exception {
|
||||||
|
executeTest("e2");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testE3() throws Exception {
|
@Test
|
||||||
executeTest();
|
public void e3() throws Exception {
|
||||||
|
executeTest("e3");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testProgrammaticListIntrospection() throws Exception {
|
@Test
|
||||||
|
public void programmaticListIntrospection() throws Exception {
|
||||||
Method setter = GenericObject.class.getMethod("setResourceList", List.class);
|
Method setter = GenericObject.class.getMethod("setResourceList", List.class);
|
||||||
assertEquals(Resource.class,
|
assertEquals(
|
||||||
GenericCollectionTypeResolver.getCollectionParameterType(new MethodParameter(setter, 0)));
|
Resource.class,
|
||||||
|
GenericCollectionTypeResolver.getCollectionParameterType(new MethodParameter(
|
||||||
|
setter, 0)));
|
||||||
|
|
||||||
Method getter = GenericObject.class.getMethod("getResourceList");
|
Method getter = GenericObject.class.getMethod("getResourceList");
|
||||||
assertEquals(Resource.class,
|
assertEquals(Resource.class,
|
||||||
GenericCollectionTypeResolver.getCollectionReturnType(getter));
|
GenericCollectionTypeResolver.getCollectionReturnType(getter));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClassResolution() {
|
@Test
|
||||||
assertEquals(String.class, GenericCollectionTypeResolver.getCollectionType(CustomSet.class));
|
public void classResolution() {
|
||||||
assertEquals(String.class, GenericCollectionTypeResolver.getMapKeyType(CustomMap.class));
|
assertEquals(String.class,
|
||||||
assertEquals(Integer.class, GenericCollectionTypeResolver.getMapValueType(CustomMap.class));
|
GenericCollectionTypeResolver.getCollectionType(CustomSet.class));
|
||||||
|
assertEquals(String.class,
|
||||||
|
GenericCollectionTypeResolver.getMapKeyType(CustomMap.class));
|
||||||
|
assertEquals(Integer.class,
|
||||||
|
GenericCollectionTypeResolver.getMapValueType(CustomMap.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static abstract class CustomSet<T> extends AbstractSet<String> {
|
||||||
private abstract class CustomSet<T> extends AbstractSet<String> {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static abstract class CustomMap<T> extends AbstractMap<String, Integer> {
|
||||||
private abstract class CustomMap<T> extends AbstractMap<String, Integer> {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static abstract class OtherCustomMap<T> implements Map<String, Integer> {
|
||||||
private abstract class OtherCustomMap<T> implements Map<String, Integer> {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
private interface Foo {
|
private static interface Foo {
|
||||||
|
|
||||||
Map<String, Integer> a();
|
Map<String, Integer> a();
|
||||||
|
|
||||||
|
|
|
@ -1,38 +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.core;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests with ControlFlowFactory return.
|
|
||||||
*
|
|
||||||
* @author Rod Johnson
|
|
||||||
*/
|
|
||||||
public class Jdk14ControlFlowTests extends AbstractControlFlowTests {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Necessary only because Eclipse won't run test suite unless it declares
|
|
||||||
* some methods as well as inherited methods
|
|
||||||
*/
|
|
||||||
public void testThisClassPlease() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ControlFlow createControlFlow() {
|
|
||||||
return ControlFlowFactory.createControlFlow();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue