Polishing
This commit is contained in:
parent
52f21bdf54
commit
b9a2d0af98
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -29,9 +28,7 @@ public class NopInterceptor implements MethodInterceptor {
|
|||
|
||||
private int count;
|
||||
|
||||
/**
|
||||
* @see org.aopalliance.intercept.MethodInterceptor#invoke(MethodInvocation)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
increment();
|
||||
|
|
@ -46,6 +43,8 @@ public class NopInterceptor implements MethodInterceptor {
|
|||
++count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof NopInterceptor)) {
|
||||
return false;
|
||||
|
|
@ -56,4 +55,9 @@ public class NopInterceptor implements MethodInterceptor {
|
|||
return this.count == ((NopInterceptor) other).count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return NopInterceptor.class.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -29,8 +29,10 @@ import org.springframework.util.ObjectUtils;
|
|||
public class SerializablePerson implements Person, Serializable {
|
||||
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
|
||||
|
||||
@Override
|
||||
public int getAge() {
|
||||
return age;
|
||||
|
|
@ -59,6 +61,7 @@ public class SerializablePerson implements Person, Serializable {
|
|||
return o;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof SerializablePerson)) {
|
||||
return false;
|
||||
|
|
@ -67,4 +70,9 @@ public class SerializablePerson implements Person, Serializable {
|
|||
return p.age == age && ObjectUtils.nullSafeEquals(name, p.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return SerializablePerson.class.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -36,13 +36,15 @@ import org.springframework.beans.factory.parsing.ReaderEventListener;
|
|||
*/
|
||||
public class CollectingReaderEventListener implements ReaderEventListener {
|
||||
|
||||
private final List defaults = new LinkedList();
|
||||
private final List<DefaultsDefinition> defaults = new LinkedList<DefaultsDefinition>();
|
||||
|
||||
private final Map componentDefinitions = new LinkedHashMap<>(8);
|
||||
private final Map<String, ComponentDefinition> componentDefinitions =
|
||||
new LinkedHashMap<String, ComponentDefinition>(8);
|
||||
|
||||
private final Map aliasMap = new LinkedHashMap<>(8);
|
||||
private final Map<String, List<AliasDefinition>> aliasMap =
|
||||
new LinkedHashMap<String, List<AliasDefinition>>(8);
|
||||
|
||||
private final List imports = new LinkedList();
|
||||
private final List<ImportDefinition> imports = new LinkedList<ImportDefinition>();
|
||||
|
||||
|
||||
@Override
|
||||
|
|
@ -50,7 +52,7 @@ public class CollectingReaderEventListener implements ReaderEventListener {
|
|||
this.defaults.add(defaultsDefinition);
|
||||
}
|
||||
|
||||
public List getDefaults() {
|
||||
public List<DefaultsDefinition> getDefaults() {
|
||||
return Collections.unmodifiableList(this.defaults);
|
||||
}
|
||||
|
||||
|
|
@ -60,27 +62,27 @@ public class CollectingReaderEventListener implements ReaderEventListener {
|
|||
}
|
||||
|
||||
public ComponentDefinition getComponentDefinition(String name) {
|
||||
return (ComponentDefinition) this.componentDefinitions.get(name);
|
||||
return this.componentDefinitions.get(name);
|
||||
}
|
||||
|
||||
public ComponentDefinition[] getComponentDefinitions() {
|
||||
Collection collection = this.componentDefinitions.values();
|
||||
return (ComponentDefinition[]) collection.toArray(new ComponentDefinition[collection.size()]);
|
||||
Collection<ComponentDefinition> collection = this.componentDefinitions.values();
|
||||
return collection.toArray(new ComponentDefinition[collection.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void aliasRegistered(AliasDefinition aliasDefinition) {
|
||||
List aliases = (List) this.aliasMap.get(aliasDefinition.getBeanName());
|
||||
if(aliases == null) {
|
||||
aliases = new ArrayList();
|
||||
List<AliasDefinition> aliases = this.aliasMap.get(aliasDefinition.getBeanName());
|
||||
if (aliases == null) {
|
||||
aliases = new ArrayList<AliasDefinition>();
|
||||
this.aliasMap.put(aliasDefinition.getBeanName(), aliases);
|
||||
}
|
||||
aliases.add(aliasDefinition);
|
||||
}
|
||||
|
||||
public List getAliases(String beanName) {
|
||||
List aliases = (List) this.aliasMap.get(beanName);
|
||||
return aliases == null ? null : Collections.unmodifiableList(aliases);
|
||||
public List<AliasDefinition> getAliases(String beanName) {
|
||||
List<AliasDefinition> aliases = this.aliasMap.get(beanName);
|
||||
return (aliases != null ? Collections.unmodifiableList(aliases) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -88,7 +90,7 @@ public class CollectingReaderEventListener implements ReaderEventListener {
|
|||
this.imports.add(importDefinition);
|
||||
}
|
||||
|
||||
public List getImports() {
|
||||
public List<ImportDefinition> getImports() {
|
||||
return Collections.unmodifiableList(this.imports);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -76,13 +76,13 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
|
||||
private Float myFloat = new Float(0.0);
|
||||
|
||||
private Collection<? super Object> friends = new LinkedList<>();
|
||||
private Collection<? super Object> friends = new LinkedList<Object>();
|
||||
|
||||
private Set<?> someSet = new HashSet<>();
|
||||
private Set<?> someSet = new HashSet<Object>();
|
||||
|
||||
private Map<?, ?> someMap = new HashMap<>();
|
||||
private Map<?, ?> someMap = new HashMap<Object, Object>();
|
||||
|
||||
private List<?> someList = new ArrayList<>();
|
||||
private List<?> someList = new ArrayList<Object>();
|
||||
|
||||
private Properties someProperties = new Properties();
|
||||
|
||||
|
|
@ -255,10 +255,12 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
this.stringArray = stringArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer[] getSomeIntegerArray() {
|
||||
return someIntegerArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSomeIntegerArray(Integer[] someIntegerArray) {
|
||||
this.someIntegerArray = someIntegerArray;
|
||||
}
|
||||
|
|
@ -461,6 +463,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
|
|
@ -472,6 +475,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.age;
|
||||
}
|
||||
|
|
@ -486,6 +490,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -58,6 +58,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
|
||||
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
|
||||
context.refresh();
|
||||
|
||||
AsyncMethodBean asyncTest = context.getBean("asyncTest", AsyncMethodBean.class);
|
||||
asyncTest.doNothing(5);
|
||||
asyncTest.doSomething(10);
|
||||
|
|
@ -73,6 +74,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
|
||||
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
|
||||
context.refresh();
|
||||
|
||||
SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class);
|
||||
asyncTest.doNothing(5);
|
||||
asyncTest.doSomething(10);
|
||||
|
|
@ -91,6 +93,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
|
||||
context.registerBeanDefinition("e2", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
|
||||
context.refresh();
|
||||
|
||||
AsyncMethodWithQualifierBean asyncTest = context.getBean("asyncTest", AsyncMethodWithQualifierBean.class);
|
||||
asyncTest.doNothing(5);
|
||||
asyncTest.doSomething(10);
|
||||
|
|
@ -111,6 +114,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
|
||||
context.registerBeanDefinition("e2", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
|
||||
context.refresh();
|
||||
|
||||
SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class);
|
||||
asyncTest.doNothing(5);
|
||||
asyncTest.doSomething(10);
|
||||
|
|
@ -128,6 +132,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
|
||||
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
|
||||
context.refresh();
|
||||
|
||||
AsyncClassBean asyncTest = context.getBean("asyncTest", AsyncClassBean.class);
|
||||
asyncTest.doSomething(10);
|
||||
Future<String> future = asyncTest.returnSomething(20);
|
||||
|
|
@ -141,6 +146,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBean.class));
|
||||
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
|
||||
context.refresh();
|
||||
|
||||
AsyncClassBean asyncTest = context.getBean("asyncTest", AsyncClassBean.class);
|
||||
asyncTest.doSomething(10);
|
||||
Future<String> future = asyncTest.returnSomething(20);
|
||||
|
|
@ -155,6 +161,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
|
||||
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
|
||||
context.refresh();
|
||||
|
||||
RegularInterface asyncTest = context.getBean("asyncTest", RegularInterface.class);
|
||||
asyncTest.doSomething(10);
|
||||
Future<String> future = asyncTest.returnSomething(20);
|
||||
|
|
@ -168,6 +175,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBeanWithInterface.class));
|
||||
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
|
||||
context.refresh();
|
||||
|
||||
RegularInterface asyncTest = context.getBean("asyncTest", RegularInterface.class);
|
||||
asyncTest.doSomething(10);
|
||||
Future<String> future = asyncTest.returnSomething(20);
|
||||
|
|
@ -182,6 +190,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
|
||||
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
|
||||
context.refresh();
|
||||
|
||||
AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class);
|
||||
asyncTest.doSomething(10);
|
||||
Future<String> future = asyncTest.returnSomething(20);
|
||||
|
|
@ -195,6 +204,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncInterfaceBean.class));
|
||||
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
|
||||
context.refresh();
|
||||
|
||||
AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class);
|
||||
asyncTest.doSomething(10);
|
||||
Future<String> future = asyncTest.returnSomething(20);
|
||||
|
|
@ -209,6 +219,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
|
||||
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
|
||||
context.refresh();
|
||||
|
||||
AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class);
|
||||
asyncTest.doSomething(10);
|
||||
Future<String> future = asyncTest.returnSomething(20);
|
||||
|
|
@ -222,6 +233,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncInterfaceBean.class));
|
||||
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
|
||||
context.refresh();
|
||||
|
||||
AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class);
|
||||
asyncTest.doSomething(10);
|
||||
Future<String> future = asyncTest.returnSomething(20);
|
||||
|
|
@ -236,6 +248,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
|
||||
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
|
||||
context.refresh();
|
||||
|
||||
AsyncMethodsInterface asyncTest = context.getBean("asyncTest", AsyncMethodsInterface.class);
|
||||
asyncTest.doNothing(5);
|
||||
asyncTest.doSomething(10);
|
||||
|
|
@ -250,6 +263,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodsInterfaceBean.class));
|
||||
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
|
||||
context.refresh();
|
||||
|
||||
AsyncMethodsInterface asyncTest = context.getBean("asyncTest", AsyncMethodsInterface.class);
|
||||
asyncTest.doNothing(5);
|
||||
asyncTest.doSomething(10);
|
||||
|
|
@ -264,6 +278,7 @@ public class AsyncExecutionTests {
|
|||
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncMethodsInterfaceBean.class));
|
||||
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
|
||||
context.refresh();
|
||||
|
||||
AsyncMethodsInterface asyncTest = context.getBean("asyncTest", AsyncMethodsInterface.class);
|
||||
asyncTest.doSomething(10);
|
||||
Future<String> future = asyncTest.returnSomething(20);
|
||||
|
|
@ -461,7 +476,7 @@ public class AsyncExecutionTests {
|
|||
private final AsyncInterface proxy;
|
||||
|
||||
public DynamicAsyncInterfaceBean() {
|
||||
ProxyFactory pf = new ProxyFactory(new HashMap<>());
|
||||
ProxyFactory pf = new ProxyFactory(new HashMap<String, String>());
|
||||
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
|
|
@ -531,7 +546,7 @@ public class AsyncExecutionTests {
|
|||
private final AsyncMethodsInterface proxy;
|
||||
|
||||
public DynamicAsyncMethodsInterfaceBean() {
|
||||
ProxyFactory pf = new ProxyFactory(new HashMap<>());
|
||||
ProxyFactory pf = new ProxyFactory(new HashMap<String, String>());
|
||||
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -37,7 +37,7 @@ public class AnnotationAwareOrderComparatorTests {
|
|||
|
||||
@Test
|
||||
public void sortInstances() {
|
||||
List<Object> list = new ArrayList<>();
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.add(new B());
|
||||
list.add(new A());
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
|
|
@ -47,7 +47,7 @@ public class AnnotationAwareOrderComparatorTests {
|
|||
|
||||
@Test
|
||||
public void sortInstancesWithSubclass() {
|
||||
List<Object> list = new ArrayList<>();
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.add(new B());
|
||||
list.add(new C());
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
|
|
@ -57,7 +57,7 @@ public class AnnotationAwareOrderComparatorTests {
|
|||
|
||||
@Test
|
||||
public void sortClasses() {
|
||||
List<Object> list = new ArrayList<>();
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.add(B.class);
|
||||
list.add(A.class);
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
|
|
@ -67,7 +67,7 @@ public class AnnotationAwareOrderComparatorTests {
|
|||
|
||||
@Test
|
||||
public void sortClassesWithSubclass() {
|
||||
List<Object> list = new ArrayList<>();
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.add(B.class);
|
||||
list.add(C.class);
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -23,71 +23,83 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class ToStringCreatorTests extends TestCase {
|
||||
public class ToStringCreatorTests {
|
||||
|
||||
private SomeObject s1, s2, s3;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
s1 = new SomeObject() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "A";
|
||||
}
|
||||
};
|
||||
s2 = new SomeObject() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "B";
|
||||
}
|
||||
};
|
||||
s3 = new SomeObject() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "C";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void testDefaultStyleMap() {
|
||||
final Map map = getMap();
|
||||
@Test
|
||||
public void defaultStyleMap() {
|
||||
final Map<String, String> map = getMap();
|
||||
Object stringy = new Object() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("familyFavoriteSport", map).toString();
|
||||
}
|
||||
};
|
||||
assertEquals("[ToStringCreatorTests.4@" + ObjectUtils.getIdentityHexString(stringy)
|
||||
+ " familyFavoriteSport = map['Keri' -> 'Softball', 'Scot' -> 'Fishing', 'Keith' -> 'Flag Football']]",
|
||||
assertEquals("[ToStringCreatorTests.4@" + ObjectUtils.getIdentityHexString(stringy) +
|
||||
" familyFavoriteSport = map['Keri' -> 'Softball', 'Scot' -> 'Fishing', 'Keith' -> 'Flag Football']]",
|
||||
stringy.toString());
|
||||
}
|
||||
|
||||
private Map getMap() {
|
||||
Map map = new LinkedHashMap(3);
|
||||
private Map<String, String> getMap() {
|
||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("Keri", "Softball");
|
||||
map.put("Scot", "Fishing");
|
||||
map.put("Keith", "Flag Football");
|
||||
return map;
|
||||
}
|
||||
|
||||
public void testDefaultStyleArray() {
|
||||
SomeObject[] array = new SomeObject[] { s1, s2, s3 };
|
||||
@Test
|
||||
public void defaultStyleArray() {
|
||||
SomeObject[] array = new SomeObject[] {s1, s2, s3};
|
||||
String str = new ToStringCreator(array).toString();
|
||||
assertEquals("[@" + ObjectUtils.getIdentityHexString(array)
|
||||
+ " array<ToStringCreatorTests.SomeObject>[A, B, C]]", str);
|
||||
assertEquals("[@" + ObjectUtils.getIdentityHexString(array) +
|
||||
" array<ToStringCreatorTests.SomeObject>[A, B, C]]", str);
|
||||
}
|
||||
|
||||
public void testPrimitiveArrays() {
|
||||
int[] integers = new int[] { 0, 1, 2, 3, 4 };
|
||||
@Test
|
||||
public void primitiveArrays() {
|
||||
int[] integers = new int[] {0, 1, 2, 3, 4};
|
||||
String str = new ToStringCreator(integers).toString();
|
||||
assertEquals("[@" + ObjectUtils.getIdentityHexString(integers) + " array<Integer>[0, 1, 2, 3, 4]]", str);
|
||||
}
|
||||
|
||||
public void testList() {
|
||||
List list = new ArrayList();
|
||||
@Test
|
||||
public void appendList() {
|
||||
List<SomeObject> list = new ArrayList<SomeObject>();
|
||||
list.add(s1);
|
||||
list.add(s2);
|
||||
list.add(s3);
|
||||
|
|
@ -96,32 +108,32 @@ public class ToStringCreatorTests extends TestCase {
|
|||
str);
|
||||
}
|
||||
|
||||
public void testSet() {
|
||||
Set set = new LinkedHashSet<>(3);
|
||||
@Test
|
||||
public void appendSet() {
|
||||
Set<SomeObject> set = new LinkedHashSet<SomeObject>();
|
||||
set.add(s1);
|
||||
set.add(s2);
|
||||
set.add(s3);
|
||||
String str = new ToStringCreator(this).append("myLetters", set).toString();
|
||||
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) + " myLetters = set[A, B, C]]",
|
||||
str);
|
||||
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) + " myLetters = set[A, B, C]]", str);
|
||||
}
|
||||
|
||||
public void testClass() {
|
||||
@Test
|
||||
public void appendClass() {
|
||||
String str = new ToStringCreator(this).append("myClass", this.getClass()).toString();
|
||||
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this)
|
||||
+ " myClass = ToStringCreatorTests]", str);
|
||||
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) +
|
||||
" myClass = ToStringCreatorTests]", str);
|
||||
}
|
||||
|
||||
public void testMethod() throws Exception {
|
||||
String str = new ToStringCreator(this).append("myMethod", this.getClass().getMethod("testMethod"))
|
||||
.toString();
|
||||
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this)
|
||||
+ " myMethod = testMethod@ToStringCreatorTests]", str);
|
||||
@Test
|
||||
public void appendMethod() throws Exception {
|
||||
String str = new ToStringCreator(this).append("myMethod", this.getClass().getMethod("appendMethod")).toString();
|
||||
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) +
|
||||
" myMethod = appendMethod@ToStringCreatorTests]", str);
|
||||
}
|
||||
|
||||
|
||||
public static class SomeObject {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -20,16 +20,26 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Colin Sampaleanu
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 21.11.2003
|
||||
*/
|
||||
public class MethodInvokerTests extends TestCase {
|
||||
public class MethodInvokerTests {
|
||||
|
||||
public void testPlainMethodInvoker() throws Exception {
|
||||
@Rule
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void plainMethodInvoker() throws Exception {
|
||||
// sanity check: singleton, non-static should work
|
||||
TestClass1 tc1 = new TestClass1();
|
||||
MethodInvoker mi = new MethodInvoker();
|
||||
|
|
@ -43,14 +53,14 @@ public class MethodInvokerTests extends TestCase {
|
|||
mi = new MethodInvoker();
|
||||
mi.setTargetClass(TestClass1.class);
|
||||
mi.setTargetMethod("supertypes");
|
||||
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello"});
|
||||
mi.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello"});
|
||||
mi.prepare();
|
||||
assertEquals("hello", mi.invoke());
|
||||
|
||||
mi = new MethodInvoker();
|
||||
mi.setTargetClass(TestClass1.class);
|
||||
mi.setTargetMethod("supertypes2");
|
||||
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello", "bogus"});
|
||||
mi.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello", "bogus"});
|
||||
mi.prepare();
|
||||
assertEquals("hello", mi.invoke());
|
||||
|
||||
|
|
@ -58,31 +68,25 @@ public class MethodInvokerTests extends TestCase {
|
|||
mi = new MethodInvoker();
|
||||
mi.setTargetClass(TestClass1.class);
|
||||
mi.setTargetMethod("supertypes2");
|
||||
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello", Boolean.TRUE});
|
||||
try {
|
||||
mi.prepare();
|
||||
fail("Shouldn't have matched without argument conversion");
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
// expected
|
||||
}
|
||||
mi.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello", Boolean.TRUE});
|
||||
|
||||
exception.expect(NoSuchMethodException.class);
|
||||
mi.prepare();
|
||||
}
|
||||
|
||||
public void testStringWithMethodInvoker() throws Exception {
|
||||
try {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
methodInvoker.setArguments(new Object[] {new String("no match")});
|
||||
methodInvoker.prepare();
|
||||
fail("Should have thrown a NoSuchMethodException");
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
// expected
|
||||
}
|
||||
@Test
|
||||
public void stringWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
methodInvoker.setArguments(new Object[] {"no match"});
|
||||
|
||||
exception.expect(NoSuchMethodException.class);
|
||||
methodInvoker.prepare();
|
||||
}
|
||||
|
||||
public void testPurchaserWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void purchaserWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
|
|
@ -92,7 +96,8 @@ public class MethodInvokerTests extends TestCase {
|
|||
assertEquals("purchaser: hello", greeting);
|
||||
}
|
||||
|
||||
public void testShopperWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void shopperWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
|
|
@ -102,7 +107,8 @@ public class MethodInvokerTests extends TestCase {
|
|||
assertEquals("purchaser: may I help you?", greeting);
|
||||
}
|
||||
|
||||
public void testSalesmanWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void salesmanWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
|
|
@ -112,7 +118,8 @@ public class MethodInvokerTests extends TestCase {
|
|||
assertEquals("greetable: how are sales?", greeting);
|
||||
}
|
||||
|
||||
public void testCustomerWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void customerWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
|
|
@ -122,7 +129,8 @@ public class MethodInvokerTests extends TestCase {
|
|||
assertEquals("customer: good day", greeting);
|
||||
}
|
||||
|
||||
public void testRegularWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void regularWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
|
|
@ -132,7 +140,8 @@ public class MethodInvokerTests extends TestCase {
|
|||
assertEquals("regular: welcome back Kotter", greeting);
|
||||
}
|
||||
|
||||
public void testVIPWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void vipWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
|
|
@ -216,13 +225,13 @@ public class MethodInvokerTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
private static interface Greetable {
|
||||
private interface Greetable {
|
||||
|
||||
String getGreeting();
|
||||
}
|
||||
|
||||
|
||||
private static interface Person extends Greetable {
|
||||
private interface Person extends Greetable {
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -18,39 +18,44 @@ package org.springframework.jdbc.object;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
|
||||
public class GenericSqlQuery extends SqlQuery {
|
||||
/**
|
||||
* A concrete variant of {@link SqlQuery} which can be configured
|
||||
* with a {@link RowMapper}.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
* @see #setRowMapperClass
|
||||
*/
|
||||
public class GenericSqlQuery<T> extends SqlQuery<T> {
|
||||
|
||||
Class rowMapperClass;
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Class<? extends RowMapper> rowMapperClass;
|
||||
|
||||
RowMapper rowMapper;
|
||||
|
||||
public void setRowMapperClass(Class rowMapperClass)
|
||||
throws IllegalAccessException, InstantiationException {
|
||||
/**
|
||||
* Set a {@link RowMapper} class for this query, creating a fresh
|
||||
* {@link RowMapper} instance per execution.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void setRowMapperClass(Class<? extends RowMapper> rowMapperClass) {
|
||||
this.rowMapperClass = rowMapperClass;
|
||||
if (!RowMapper.class.isAssignableFrom(rowMapperClass))
|
||||
throw new IllegalStateException("The specified class '" +
|
||||
rowMapperClass.getName() + " is not a sub class of " +
|
||||
"'org.springframework.jdbc.core.RowMapper'");
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
super.afterPropertiesSet();
|
||||
Assert.notNull(rowMapperClass, "The 'rowMapperClass' property is required");
|
||||
Assert.notNull(this.rowMapperClass, "'rowMapperClass' is required");
|
||||
}
|
||||
|
||||
protected RowMapper newRowMapper(Object[] parameters, Map context) {
|
||||
try {
|
||||
return (RowMapper) rowMapperClass.newInstance();
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw new InvalidDataAccessResourceUsageException("Unable to instantiate RowMapper", e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new InvalidDataAccessResourceUsageException("Unable to instantiate RowMapper", e);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected RowMapper<T> newRowMapper(Object[] parameters, Map context) {
|
||||
return BeanUtils.instantiateClass(this.rowMapperClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.springframework.jdbc.object;
|
||||
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
|
@ -25,13 +24,11 @@ import java.sql.Types;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
|
@ -43,13 +40,14 @@ import static org.mockito.BDDMockito.*;
|
|||
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class GenericSqlQueryTests {
|
||||
public class GenericSqlQueryTests {
|
||||
|
||||
private static final String SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED =
|
||||
"select id, forename from custmr where id = ? and country = ?";
|
||||
"select id, forename from custmr where id = ? and country = ?";
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
private DefaultListableBeanFactory beanFactory;
|
||||
|
||||
private Connection connection;
|
||||
|
||||
|
|
@ -57,10 +55,11 @@ public class GenericSqlQueryTests {
|
|||
|
||||
private ResultSet resultSet;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.beanFactory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory).loadBeanDefinitions(
|
||||
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
|
||||
new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml"));
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
this.connection = mock(Connection.class);
|
||||
|
|
@ -72,18 +71,18 @@ public class GenericSqlQueryTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPlaceHoldersCustomerQuery() throws SQLException {
|
||||
SqlQuery query = (SqlQuery) beanFactory.getBean("queryWithPlaceHolders");
|
||||
public void testCustomerQueryWithPlaceholders() throws SQLException {
|
||||
SqlQuery<?> query = (SqlQuery<?>) beanFactory.getBean("queryWithPlaceholders");
|
||||
doTestCustomerQuery(query, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedParameterCustomerQuery() throws SQLException {
|
||||
SqlQuery query = (SqlQuery) beanFactory.getBean("queryWithNamedParameters");
|
||||
public void testCustomerQueryWithNamedParameters() throws SQLException {
|
||||
SqlQuery<?> query = (SqlQuery<?>) beanFactory.getBean("queryWithNamedParameters");
|
||||
doTestCustomerQuery(query, true);
|
||||
}
|
||||
|
||||
private void doTestCustomerQuery(SqlQuery query, boolean namedParameters) throws SQLException {
|
||||
private void doTestCustomerQuery(SqlQuery<?> query, boolean namedParameters) throws SQLException {
|
||||
given(resultSet.next()).willReturn(true);
|
||||
given(resultSet.getInt("id")).willReturn(1);
|
||||
given(resultSet.getString("forename")).willReturn("rod");
|
||||
|
|
@ -91,15 +90,15 @@ public class GenericSqlQueryTests {
|
|||
given(preparedStatement.executeQuery()).willReturn(resultSet);
|
||||
given(connection.prepareStatement(SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED)).willReturn(preparedStatement);
|
||||
|
||||
List queryResults;
|
||||
List<?> queryResults;
|
||||
if (namedParameters) {
|
||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
||||
params.put("id", new Integer(1));
|
||||
params.put("id", 1);
|
||||
params.put("country", "UK");
|
||||
queryResults = query.executeByNamedParam(params);
|
||||
}
|
||||
else {
|
||||
Object[] params = new Object[] {new Integer(1), "UK"};
|
||||
Object[] params = new Object[] {1, "UK"};
|
||||
queryResults = query.execute(params);
|
||||
}
|
||||
assertTrue("Customer was returned correctly", queryResults.size() == 1);
|
||||
|
|
@ -108,7 +107,7 @@ public class GenericSqlQueryTests {
|
|||
assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
|
||||
|
||||
verify(resultSet).close();
|
||||
verify(preparedStatement).setObject(1, new Integer(1), Types.INTEGER);
|
||||
verify(preparedStatement).setObject(1, 1, Types.INTEGER);
|
||||
verify(preparedStatement).setString(2, "UK");
|
||||
verify(preparedStatement).close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
|
||||
|
||||
<bean id="dataSource" class="org.springframework.jdbc.datasource.TestDataSourceWrapper"/>
|
||||
|
||||
<bean id="queryWithPlaceHolders" class="org.springframework.jdbc.object.GenericSqlQuery">
|
||||
<bean id="queryWithPlaceholders" class="org.springframework.jdbc.object.GenericSqlQuery">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
<property name="sql" value="select id, forename from custmr where id = ? and country = ?"/>
|
||||
<property name="parameters">
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
<constructor-arg index="0" value="amount"/>
|
||||
<constructor-arg index="1">
|
||||
<util:constant static-field="java.sql.Types.INTEGER"/>
|
||||
</constructor-arg>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
<bean class="org.springframework.jdbc.core.SqlParameter">
|
||||
<constructor-arg index="0" value="custid"/>
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
</bean>
|
||||
</list>
|
||||
</property>
|
||||
<property name="rowMapperClass" value="org.springframework.jdbc.object.CustomerMapper"/>
|
||||
<property name="rowMapperClass" value="org.springframework.jdbc.object.CustomerMapper"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -63,7 +63,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
|
|||
|
||||
@Before
|
||||
public void setUp() {
|
||||
converter = new Jaxb2CollectionHttpMessageConverter<>();
|
||||
converter = new Jaxb2CollectionHttpMessageConverter<Collection<Object>>();
|
||||
rootElementListType = new ParameterizedTypeReference<List<RootElement>>() {}.getType();
|
||||
rootElementSetType = new ParameterizedTypeReference<Set<RootElement>>() {}.getType();
|
||||
typeListType = new ParameterizedTypeReference<List<TestType>>() {}.getType();
|
||||
|
|
@ -157,7 +157,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
|
|||
assertEquals("", result.iterator().next().external);
|
||||
}
|
||||
catch (HttpMessageNotReadableException ex) {
|
||||
// Some parsers raise exception by default
|
||||
// Some parsers raise an exception
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +212,6 @@ public class Jaxb2CollectionHttpMessageConverterTests {
|
|||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@XmlRootElement
|
||||
public static class RootElement {
|
||||
|
||||
|
|
@ -247,6 +246,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@XmlType
|
||||
public static class TestType {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -13,9 +13,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.accept;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
package org.springframework.web.accept;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
|
@ -24,6 +23,7 @@ import java.util.Map;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockServletContext;
|
||||
|
|
@ -31,8 +31,11 @@ import org.springframework.util.StringUtils;
|
|||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link ContentNegotiationManagerFactoryBean} tests.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ContentNegotiationManagerFactoryBeanTests {
|
||||
|
|
@ -43,6 +46,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
|||
|
||||
private MockHttpServletRequest servletRequest;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
TestServletContext servletContext = new TestServletContext();
|
||||
|
|
@ -55,6 +59,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
|||
this.factoryBean.setServletContext(this.servletRequest.getServletContext());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void defaultSettings() throws Exception {
|
||||
this.factoryBean.afterPropertiesSet();
|
||||
|
|
@ -149,17 +154,14 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
|||
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest));
|
||||
|
||||
// SPR-10513
|
||||
|
||||
this.servletRequest.addHeader("Accept", MediaType.ALL_VALUE);
|
||||
|
||||
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest));
|
||||
}
|
||||
|
||||
|
||||
private static class TestServletContext extends MockServletContext {
|
||||
|
||||
private final Map<String, String> mimeTypes = new HashMap<>();
|
||||
|
||||
private final Map<String, String> mimeTypes = new HashMap<String, String>();
|
||||
|
||||
public Map<String, String> getMimeTypes() {
|
||||
return this.mimeTypes;
|
||||
|
|
|
|||
Loading…
Reference in New Issue