Browse Source

Polishing

pull/1260/head
Juergen Hoeller 9 years ago
parent
commit
b9a2d0af98
  1. 14
      spring-aop/src/test/java/org/springframework/tests/aop/interceptor/NopInterceptor.java
  2. 10
      spring-aop/src/test/java/org/springframework/tests/sample/beans/SerializablePerson.java
  3. 34
      spring-beans/src/test/java/org/springframework/tests/beans/CollectingReaderEventListener.java
  4. 15
      spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java
  5. 21
      spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java
  6. 10
      spring-core/src/test/java/org/springframework/core/annotation/AnnotationAwareOrderComparatorTests.java
  7. 76
      spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java
  8. 77
      spring-core/src/test/java/org/springframework/util/MethodInvokerTests.java
  9. 49
      spring-jdbc/src/main/java/org/springframework/jdbc/object/GenericSqlQuery.java
  10. 35
      spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java
  11. 8
      spring-jdbc/src/test/resources/org/springframework/jdbc/object/GenericSqlQueryTests-context.xml
  12. 8
      spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java
  13. 16
      spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java

14
spring-aop/src/test/java/org/springframework/tests/aop/interceptor/NopInterceptor.java

@ -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"); * 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.
@ -29,9 +28,7 @@ public class NopInterceptor implements MethodInterceptor {
private int count; private int count;
/**
* @see org.aopalliance.intercept.MethodInterceptor#invoke(MethodInvocation)
*/
@Override @Override
public Object invoke(MethodInvocation invocation) throws Throwable { public Object invoke(MethodInvocation invocation) throws Throwable {
increment(); increment();
@ -46,6 +43,8 @@ public class NopInterceptor implements MethodInterceptor {
++count; ++count;
} }
@Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (!(other instanceof NopInterceptor)) { if (!(other instanceof NopInterceptor)) {
return false; return false;
@ -56,4 +55,9 @@ public class NopInterceptor implements MethodInterceptor {
return this.count == ((NopInterceptor) other).count; return this.count == ((NopInterceptor) other).count;
} }
@Override
public int hashCode() {
return NopInterceptor.class.hashCode();
}
} }

10
spring-aop/src/test/java/org/springframework/tests/sample/beans/SerializablePerson.java

@ -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"); * 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.
@ -29,8 +29,10 @@ import org.springframework.util.ObjectUtils;
public class SerializablePerson implements Person, Serializable { public class SerializablePerson implements Person, Serializable {
private String name; private String name;
private int age; private int age;
@Override @Override
public int getAge() { public int getAge() {
return age; return age;
@ -59,6 +61,7 @@ public class SerializablePerson implements Person, Serializable {
return o; return o;
} }
public boolean equals(Object other) { public boolean equals(Object other) {
if (!(other instanceof SerializablePerson)) { if (!(other instanceof SerializablePerson)) {
return false; return false;
@ -67,4 +70,9 @@ public class SerializablePerson implements Person, Serializable {
return p.age == age && ObjectUtils.nullSafeEquals(name, p.name); return p.age == age && ObjectUtils.nullSafeEquals(name, p.name);
} }
@Override
public int hashCode() {
return SerializablePerson.class.hashCode();
}
} }

34
spring-beans/src/test/java/org/springframework/tests/beans/CollectingReaderEventListener.java

@ -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"); * 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.
@ -36,13 +36,15 @@ import org.springframework.beans.factory.parsing.ReaderEventListener;
*/ */
public class CollectingReaderEventListener implements 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 @Override
@ -50,7 +52,7 @@ public class CollectingReaderEventListener implements ReaderEventListener {
this.defaults.add(defaultsDefinition); this.defaults.add(defaultsDefinition);
} }
public List getDefaults() { public List<DefaultsDefinition> getDefaults() {
return Collections.unmodifiableList(this.defaults); return Collections.unmodifiableList(this.defaults);
} }
@ -60,27 +62,27 @@ public class CollectingReaderEventListener implements ReaderEventListener {
} }
public ComponentDefinition getComponentDefinition(String name) { public ComponentDefinition getComponentDefinition(String name) {
return (ComponentDefinition) this.componentDefinitions.get(name); return this.componentDefinitions.get(name);
} }
public ComponentDefinition[] getComponentDefinitions() { public ComponentDefinition[] getComponentDefinitions() {
Collection collection = this.componentDefinitions.values(); Collection<ComponentDefinition> collection = this.componentDefinitions.values();
return (ComponentDefinition[]) collection.toArray(new ComponentDefinition[collection.size()]); return collection.toArray(new ComponentDefinition[collection.size()]);
} }
@Override @Override
public void aliasRegistered(AliasDefinition aliasDefinition) { public void aliasRegistered(AliasDefinition aliasDefinition) {
List aliases = (List) this.aliasMap.get(aliasDefinition.getBeanName()); List<AliasDefinition> aliases = this.aliasMap.get(aliasDefinition.getBeanName());
if(aliases == null) { if (aliases == null) {
aliases = new ArrayList(); aliases = new ArrayList<AliasDefinition>();
this.aliasMap.put(aliasDefinition.getBeanName(), aliases); this.aliasMap.put(aliasDefinition.getBeanName(), aliases);
} }
aliases.add(aliasDefinition); aliases.add(aliasDefinition);
} }
public List getAliases(String beanName) { public List<AliasDefinition> getAliases(String beanName) {
List aliases = (List) this.aliasMap.get(beanName); List<AliasDefinition> aliases = this.aliasMap.get(beanName);
return aliases == null ? null : Collections.unmodifiableList(aliases); return (aliases != null ? Collections.unmodifiableList(aliases) : null);
} }
@Override @Override
@ -88,7 +90,7 @@ public class CollectingReaderEventListener implements ReaderEventListener {
this.imports.add(importDefinition); this.imports.add(importDefinition);
} }
public List getImports() { public List<ImportDefinition> getImports() {
return Collections.unmodifiableList(this.imports); return Collections.unmodifiableList(this.imports);
} }

15
spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java

@ -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"); * 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.
@ -76,13 +76,13 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
private Float myFloat = new Float(0.0); 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(); private Properties someProperties = new Properties();
@ -255,10 +255,12 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
this.stringArray = stringArray; this.stringArray = stringArray;
} }
@Override
public Integer[] getSomeIntegerArray() { public Integer[] getSomeIntegerArray() {
return someIntegerArray; return someIntegerArray;
} }
@Override
public void setSomeIntegerArray(Integer[] someIntegerArray) { public void setSomeIntegerArray(Integer[] someIntegerArray) {
this.someIntegerArray = someIntegerArray; this.someIntegerArray = someIntegerArray;
} }
@ -461,6 +463,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
} }
@Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (this == other) { if (this == other) {
return true; 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); return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age);
} }
@Override
public int hashCode() { public int hashCode() {
return this.age; return this.age;
} }
@ -486,6 +490,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
} }
} }
@Override
public String toString() { public String toString() {
return this.name; return this.name;
} }

21
spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java

@ -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"); * 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.
@ -58,6 +58,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
context.refresh(); context.refresh();
AsyncMethodBean asyncTest = context.getBean("asyncTest", AsyncMethodBean.class); AsyncMethodBean asyncTest = context.getBean("asyncTest", AsyncMethodBean.class);
asyncTest.doNothing(5); asyncTest.doNothing(5);
asyncTest.doSomething(10); asyncTest.doSomething(10);
@ -73,6 +74,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
context.refresh(); context.refresh();
SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class); SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class);
asyncTest.doNothing(5); asyncTest.doNothing(5);
asyncTest.doSomething(10); asyncTest.doSomething(10);
@ -91,6 +93,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class)); context.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
context.registerBeanDefinition("e2", new RootBeanDefinition(ThreadPoolTaskExecutor.class)); context.registerBeanDefinition("e2", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
context.refresh(); context.refresh();
AsyncMethodWithQualifierBean asyncTest = context.getBean("asyncTest", AsyncMethodWithQualifierBean.class); AsyncMethodWithQualifierBean asyncTest = context.getBean("asyncTest", AsyncMethodWithQualifierBean.class);
asyncTest.doNothing(5); asyncTest.doNothing(5);
asyncTest.doSomething(10); asyncTest.doSomething(10);
@ -111,6 +114,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class)); context.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
context.registerBeanDefinition("e2", new RootBeanDefinition(ThreadPoolTaskExecutor.class)); context.registerBeanDefinition("e2", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
context.refresh(); context.refresh();
SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class); SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class);
asyncTest.doNothing(5); asyncTest.doNothing(5);
asyncTest.doSomething(10); asyncTest.doSomething(10);
@ -128,6 +132,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
context.refresh(); context.refresh();
AsyncClassBean asyncTest = context.getBean("asyncTest", AsyncClassBean.class); AsyncClassBean asyncTest = context.getBean("asyncTest", AsyncClassBean.class);
asyncTest.doSomething(10); asyncTest.doSomething(10);
Future<String> future = asyncTest.returnSomething(20); Future<String> future = asyncTest.returnSomething(20);
@ -141,6 +146,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBean.class)); context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBean.class));
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
context.refresh(); context.refresh();
AsyncClassBean asyncTest = context.getBean("asyncTest", AsyncClassBean.class); AsyncClassBean asyncTest = context.getBean("asyncTest", AsyncClassBean.class);
asyncTest.doSomething(10); asyncTest.doSomething(10);
Future<String> future = asyncTest.returnSomething(20); Future<String> future = asyncTest.returnSomething(20);
@ -155,6 +161,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
context.refresh(); context.refresh();
RegularInterface asyncTest = context.getBean("asyncTest", RegularInterface.class); RegularInterface asyncTest = context.getBean("asyncTest", RegularInterface.class);
asyncTest.doSomething(10); asyncTest.doSomething(10);
Future<String> future = asyncTest.returnSomething(20); Future<String> future = asyncTest.returnSomething(20);
@ -168,6 +175,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBeanWithInterface.class)); context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBeanWithInterface.class));
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
context.refresh(); context.refresh();
RegularInterface asyncTest = context.getBean("asyncTest", RegularInterface.class); RegularInterface asyncTest = context.getBean("asyncTest", RegularInterface.class);
asyncTest.doSomething(10); asyncTest.doSomething(10);
Future<String> future = asyncTest.returnSomething(20); Future<String> future = asyncTest.returnSomething(20);
@ -182,6 +190,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
context.refresh(); context.refresh();
AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class); AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class);
asyncTest.doSomething(10); asyncTest.doSomething(10);
Future<String> future = asyncTest.returnSomething(20); Future<String> future = asyncTest.returnSomething(20);
@ -195,6 +204,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncInterfaceBean.class)); context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncInterfaceBean.class));
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
context.refresh(); context.refresh();
AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class); AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class);
asyncTest.doSomething(10); asyncTest.doSomething(10);
Future<String> future = asyncTest.returnSomething(20); Future<String> future = asyncTest.returnSomething(20);
@ -209,6 +219,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
context.refresh(); context.refresh();
AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class); AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class);
asyncTest.doSomething(10); asyncTest.doSomething(10);
Future<String> future = asyncTest.returnSomething(20); Future<String> future = asyncTest.returnSomething(20);
@ -222,6 +233,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncInterfaceBean.class)); context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncInterfaceBean.class));
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
context.refresh(); context.refresh();
AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class); AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class);
asyncTest.doSomething(10); asyncTest.doSomething(10);
Future<String> future = asyncTest.returnSomething(20); Future<String> future = asyncTest.returnSomething(20);
@ -236,6 +248,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
context.refresh(); context.refresh();
AsyncMethodsInterface asyncTest = context.getBean("asyncTest", AsyncMethodsInterface.class); AsyncMethodsInterface asyncTest = context.getBean("asyncTest", AsyncMethodsInterface.class);
asyncTest.doNothing(5); asyncTest.doNothing(5);
asyncTest.doSomething(10); asyncTest.doSomething(10);
@ -250,6 +263,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodsInterfaceBean.class)); context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodsInterfaceBean.class));
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
context.refresh(); context.refresh();
AsyncMethodsInterface asyncTest = context.getBean("asyncTest", AsyncMethodsInterface.class); AsyncMethodsInterface asyncTest = context.getBean("asyncTest", AsyncMethodsInterface.class);
asyncTest.doNothing(5); asyncTest.doNothing(5);
asyncTest.doSomething(10); asyncTest.doSomething(10);
@ -264,6 +278,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncMethodsInterfaceBean.class)); context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncMethodsInterfaceBean.class));
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
context.refresh(); context.refresh();
AsyncMethodsInterface asyncTest = context.getBean("asyncTest", AsyncMethodsInterface.class); AsyncMethodsInterface asyncTest = context.getBean("asyncTest", AsyncMethodsInterface.class);
asyncTest.doSomething(10); asyncTest.doSomething(10);
Future<String> future = asyncTest.returnSomething(20); Future<String> future = asyncTest.returnSomething(20);
@ -461,7 +476,7 @@ public class AsyncExecutionTests {
private final AsyncInterface proxy; private final AsyncInterface proxy;
public DynamicAsyncInterfaceBean() { public DynamicAsyncInterfaceBean() {
ProxyFactory pf = new ProxyFactory(new HashMap<>()); ProxyFactory pf = new ProxyFactory(new HashMap<String, String>());
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
@Override @Override
public Object invoke(MethodInvocation invocation) throws Throwable { public Object invoke(MethodInvocation invocation) throws Throwable {
@ -531,7 +546,7 @@ public class AsyncExecutionTests {
private final AsyncMethodsInterface proxy; private final AsyncMethodsInterface proxy;
public DynamicAsyncMethodsInterfaceBean() { public DynamicAsyncMethodsInterfaceBean() {
ProxyFactory pf = new ProxyFactory(new HashMap<>()); ProxyFactory pf = new ProxyFactory(new HashMap<String, String>());
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
@Override @Override
public Object invoke(MethodInvocation invocation) throws Throwable { public Object invoke(MethodInvocation invocation) throws Throwable {

10
spring-core/src/test/java/org/springframework/core/annotation/AnnotationAwareOrderComparatorTests.java

@ -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.
@ -37,7 +37,7 @@ public class AnnotationAwareOrderComparatorTests {
@Test @Test
public void sortInstances() { public void sortInstances() {
List<Object> list = new ArrayList<>(); List<Object> list = new ArrayList<Object>();
list.add(new B()); list.add(new B());
list.add(new A()); list.add(new A());
AnnotationAwareOrderComparator.sort(list); AnnotationAwareOrderComparator.sort(list);
@ -47,7 +47,7 @@ public class AnnotationAwareOrderComparatorTests {
@Test @Test
public void sortInstancesWithSubclass() { public void sortInstancesWithSubclass() {
List<Object> list = new ArrayList<>(); List<Object> list = new ArrayList<Object>();
list.add(new B()); list.add(new B());
list.add(new C()); list.add(new C());
AnnotationAwareOrderComparator.sort(list); AnnotationAwareOrderComparator.sort(list);
@ -57,7 +57,7 @@ public class AnnotationAwareOrderComparatorTests {
@Test @Test
public void sortClasses() { public void sortClasses() {
List<Object> list = new ArrayList<>(); List<Object> list = new ArrayList<Object>();
list.add(B.class); list.add(B.class);
list.add(A.class); list.add(A.class);
AnnotationAwareOrderComparator.sort(list); AnnotationAwareOrderComparator.sort(list);
@ -67,7 +67,7 @@ public class AnnotationAwareOrderComparatorTests {
@Test @Test
public void sortClassesWithSubclass() { public void sortClassesWithSubclass() {
List<Object> list = new ArrayList<>(); List<Object> list = new ArrayList<Object>();
list.add(B.class); list.add(B.class);
list.add(C.class); list.add(C.class);
AnnotationAwareOrderComparator.sort(list); AnnotationAwareOrderComparator.sort(list);

76
spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java

@ -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"); * 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.
@ -23,71 +23,83 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import junit.framework.TestCase; import org.junit.Before;
import org.junit.Test;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import static org.junit.Assert.*;
/** /**
* @author Keith Donald * @author Keith Donald
*/ */
public class ToStringCreatorTests extends TestCase { public class ToStringCreatorTests {
private SomeObject s1, s2, s3; private SomeObject s1, s2, s3;
@Override
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
s1 = new SomeObject() { s1 = new SomeObject() {
@Override
public String toString() { public String toString() {
return "A"; return "A";
} }
}; };
s2 = new SomeObject() { s2 = new SomeObject() {
@Override
public String toString() { public String toString() {
return "B"; return "B";
} }
}; };
s3 = new SomeObject() { s3 = new SomeObject() {
@Override
public String toString() { public String toString() {
return "C"; return "C";
} }
}; };
} }
public void testDefaultStyleMap() { @Test
final Map map = getMap(); public void defaultStyleMap() {
final Map<String, String> map = getMap();
Object stringy = new Object() { Object stringy = new Object() {
@Override
public String toString() { public String toString() {
return new ToStringCreator(this).append("familyFavoriteSport", map).toString(); return new ToStringCreator(this).append("familyFavoriteSport", map).toString();
} }
}; };
assertEquals("[ToStringCreatorTests.4@" + ObjectUtils.getIdentityHexString(stringy) assertEquals("[ToStringCreatorTests.4@" + ObjectUtils.getIdentityHexString(stringy) +
+ " familyFavoriteSport = map['Keri' -> 'Softball', 'Scot' -> 'Fishing', 'Keith' -> 'Flag Football']]", " familyFavoriteSport = map['Keri' -> 'Softball', 'Scot' -> 'Fishing', 'Keith' -> 'Flag Football']]",
stringy.toString()); stringy.toString());
} }
private Map getMap() { private Map<String, String> getMap() {
Map map = new LinkedHashMap(3); Map<String, String> map = new LinkedHashMap<String, String>();
map.put("Keri", "Softball"); map.put("Keri", "Softball");
map.put("Scot", "Fishing"); map.put("Scot", "Fishing");
map.put("Keith", "Flag Football"); map.put("Keith", "Flag Football");
return map; return map;
} }
public void testDefaultStyleArray() { @Test
SomeObject[] array = new SomeObject[] { s1, s2, s3 }; public void defaultStyleArray() {
SomeObject[] array = new SomeObject[] {s1, s2, s3};
String str = new ToStringCreator(array).toString(); String str = new ToStringCreator(array).toString();
assertEquals("[@" + ObjectUtils.getIdentityHexString(array) assertEquals("[@" + ObjectUtils.getIdentityHexString(array) +
+ " array<ToStringCreatorTests.SomeObject>[A, B, C]]", str); " array<ToStringCreatorTests.SomeObject>[A, B, C]]", str);
} }
public void testPrimitiveArrays() { @Test
int[] integers = new int[] { 0, 1, 2, 3, 4 }; public void primitiveArrays() {
int[] integers = new int[] {0, 1, 2, 3, 4};
String str = new ToStringCreator(integers).toString(); String str = new ToStringCreator(integers).toString();
assertEquals("[@" + ObjectUtils.getIdentityHexString(integers) + " array<Integer>[0, 1, 2, 3, 4]]", str); assertEquals("[@" + ObjectUtils.getIdentityHexString(integers) + " array<Integer>[0, 1, 2, 3, 4]]", str);
} }
public void testList() { @Test
List list = new ArrayList(); public void appendList() {
List<SomeObject> list = new ArrayList<SomeObject>();
list.add(s1); list.add(s1);
list.add(s2); list.add(s2);
list.add(s3); list.add(s3);
@ -96,32 +108,32 @@ public class ToStringCreatorTests extends TestCase {
str); str);
} }
public void testSet() { @Test
Set set = new LinkedHashSet<>(3); public void appendSet() {
Set<SomeObject> set = new LinkedHashSet<SomeObject>();
set.add(s1); set.add(s1);
set.add(s2); set.add(s2);
set.add(s3); set.add(s3);
String str = new ToStringCreator(this).append("myLetters", set).toString(); String str = new ToStringCreator(this).append("myLetters", set).toString();
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) + " myLetters = set[A, B, C]]", assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) + " myLetters = set[A, B, C]]", str);
str);
} }
public void testClass() { @Test
public void appendClass() {
String str = new ToStringCreator(this).append("myClass", this.getClass()).toString(); String str = new ToStringCreator(this).append("myClass", this.getClass()).toString();
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) +
+ " myClass = ToStringCreatorTests]", str); " myClass = ToStringCreatorTests]", str);
} }
public void testMethod() throws Exception { @Test
String str = new ToStringCreator(this).append("myMethod", this.getClass().getMethod("testMethod")) public void appendMethod() throws Exception {
.toString(); String str = new ToStringCreator(this).append("myMethod", this.getClass().getMethod("appendMethod")).toString();
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) +
+ " myMethod = testMethod@ToStringCreatorTests]", str); " myMethod = appendMethod@ToStringCreatorTests]", str);
} }
public static class SomeObject { public static class SomeObject {
} }
} }

77
spring-core/src/test/java/org/springframework/util/MethodInvokerTests.java

@ -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"); * 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.
@ -20,16 +20,26 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; 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 Colin Sampaleanu
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen
* @since 21.11.2003 * @since 21.11.2003
*/ */
public class MethodInvokerTests extends TestCase { public class MethodInvokerTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
public void testPlainMethodInvoker() throws Exception {
@Test
public void plainMethodInvoker() throws Exception {
// sanity check: singleton, non-static should work // sanity check: singleton, non-static should work
TestClass1 tc1 = new TestClass1(); TestClass1 tc1 = new TestClass1();
MethodInvoker mi = new MethodInvoker(); MethodInvoker mi = new MethodInvoker();
@ -43,14 +53,14 @@ public class MethodInvokerTests extends TestCase {
mi = new MethodInvoker(); mi = new MethodInvoker();
mi.setTargetClass(TestClass1.class); mi.setTargetClass(TestClass1.class);
mi.setTargetMethod("supertypes"); 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(); mi.prepare();
assertEquals("hello", mi.invoke()); assertEquals("hello", mi.invoke());
mi = new MethodInvoker(); mi = new MethodInvoker();
mi.setTargetClass(TestClass1.class); mi.setTargetClass(TestClass1.class);
mi.setTargetMethod("supertypes2"); 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(); mi.prepare();
assertEquals("hello", mi.invoke()); assertEquals("hello", mi.invoke());
@ -58,31 +68,25 @@ public class MethodInvokerTests extends TestCase {
mi = new MethodInvoker(); mi = new MethodInvoker();
mi.setTargetClass(TestClass1.class); mi.setTargetClass(TestClass1.class);
mi.setTargetMethod("supertypes2"); mi.setTargetMethod("supertypes2");
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello", Boolean.TRUE}); mi.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello", Boolean.TRUE});
try {
mi.prepare(); exception.expect(NoSuchMethodException.class);
fail("Shouldn't have matched without argument conversion"); mi.prepare();
}
catch (NoSuchMethodException ex) {
// expected
}
} }
public void testStringWithMethodInvoker() throws Exception { @Test
try { public void stringWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker(); MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet"); methodInvoker.setTargetMethod("greet");
methodInvoker.setArguments(new Object[] {new String("no match")}); methodInvoker.setArguments(new Object[] {"no match"});
methodInvoker.prepare();
fail("Should have thrown a NoSuchMethodException"); exception.expect(NoSuchMethodException.class);
} methodInvoker.prepare();
catch (NoSuchMethodException e) {
// expected
}
} }
public void testPurchaserWithMethodInvoker() throws Exception { @Test
public void purchaserWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker(); MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet"); methodInvoker.setTargetMethod("greet");
@ -92,7 +96,8 @@ public class MethodInvokerTests extends TestCase {
assertEquals("purchaser: hello", greeting); assertEquals("purchaser: hello", greeting);
} }
public void testShopperWithMethodInvoker() throws Exception { @Test
public void shopperWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker(); MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet"); methodInvoker.setTargetMethod("greet");
@ -102,7 +107,8 @@ public class MethodInvokerTests extends TestCase {
assertEquals("purchaser: may I help you?", greeting); assertEquals("purchaser: may I help you?", greeting);
} }
public void testSalesmanWithMethodInvoker() throws Exception { @Test
public void salesmanWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker(); MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet"); methodInvoker.setTargetMethod("greet");
@ -112,7 +118,8 @@ public class MethodInvokerTests extends TestCase {
assertEquals("greetable: how are sales?", greeting); assertEquals("greetable: how are sales?", greeting);
} }
public void testCustomerWithMethodInvoker() throws Exception { @Test
public void customerWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker(); MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet"); methodInvoker.setTargetMethod("greet");
@ -122,7 +129,8 @@ public class MethodInvokerTests extends TestCase {
assertEquals("customer: good day", greeting); assertEquals("customer: good day", greeting);
} }
public void testRegularWithMethodInvoker() throws Exception { @Test
public void regularWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker(); MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet"); methodInvoker.setTargetMethod("greet");
@ -132,7 +140,8 @@ public class MethodInvokerTests extends TestCase {
assertEquals("regular: welcome back Kotter", greeting); assertEquals("regular: welcome back Kotter", greeting);
} }
public void testVIPWithMethodInvoker() throws Exception { @Test
public void vipWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker(); MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet"); methodInvoker.setTargetMethod("greet");
@ -216,13 +225,13 @@ public class MethodInvokerTests extends TestCase {
} }
private static interface Greetable { private interface Greetable {
String getGreeting(); String getGreeting();
} }
private static interface Person extends Greetable { private interface Person extends Greetable {
} }

49
spring-jdbc/src/main/java/org/springframework/jdbc/object/GenericSqlQuery.java

@ -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"); * 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.
@ -18,39 +18,44 @@ package org.springframework.jdbc.object;
import java.util.Map; import java.util.Map;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.util.Assert; 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; 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() { public void afterPropertiesSet() {
super.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 { @Override
return (RowMapper) rowMapperClass.newInstance(); @SuppressWarnings("unchecked")
} protected RowMapper<T> newRowMapper(Object[] parameters, Map context) {
catch (InstantiationException e) { return BeanUtils.instantiateClass(this.rowMapperClass);
throw new InvalidDataAccessResourceUsageException("Unable to instantiate RowMapper", e);
}
catch (IllegalAccessException e) {
throw new InvalidDataAccessResourceUsageException("Unable to instantiate RowMapper", e);
}
} }
} }

35
spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java

@ -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"); * 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,7 +16,6 @@
package org.springframework.jdbc.object; package org.springframework.jdbc.object;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -25,13 +24,11 @@ import java.sql.Types;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; 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.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -43,13 +40,14 @@ import static org.mockito.BDDMockito.*;
/** /**
* @author Thomas Risberg * @author Thomas Risberg
* @author Juergen Hoeller
*/ */
public class GenericSqlQueryTests { public class GenericSqlQueryTests {
private static final String SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED = 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; private Connection connection;
@ -57,10 +55,11 @@ public class GenericSqlQueryTests {
private ResultSet resultSet; private ResultSet resultSet;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.beanFactory = new DefaultListableBeanFactory(); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory).loadBeanDefinitions( new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml")); new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml"));
DataSource dataSource = mock(DataSource.class); DataSource dataSource = mock(DataSource.class);
this.connection = mock(Connection.class); this.connection = mock(Connection.class);
@ -72,18 +71,18 @@ public class GenericSqlQueryTests {
} }
@Test @Test
public void testPlaceHoldersCustomerQuery() throws SQLException { public void testCustomerQueryWithPlaceholders() throws SQLException {
SqlQuery query = (SqlQuery) beanFactory.getBean("queryWithPlaceHolders"); SqlQuery<?> query = (SqlQuery<?>) beanFactory.getBean("queryWithPlaceholders");
doTestCustomerQuery(query, false); doTestCustomerQuery(query, false);
} }
@Test @Test
public void testNamedParameterCustomerQuery() throws SQLException { public void testCustomerQueryWithNamedParameters() throws SQLException {
SqlQuery query = (SqlQuery) beanFactory.getBean("queryWithNamedParameters"); SqlQuery<?> query = (SqlQuery<?>) beanFactory.getBean("queryWithNamedParameters");
doTestCustomerQuery(query, true); 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.next()).willReturn(true);
given(resultSet.getInt("id")).willReturn(1); given(resultSet.getInt("id")).willReturn(1);
given(resultSet.getString("forename")).willReturn("rod"); given(resultSet.getString("forename")).willReturn("rod");
@ -91,15 +90,15 @@ public class GenericSqlQueryTests {
given(preparedStatement.executeQuery()).willReturn(resultSet); given(preparedStatement.executeQuery()).willReturn(resultSet);
given(connection.prepareStatement(SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED)).willReturn(preparedStatement); given(connection.prepareStatement(SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED)).willReturn(preparedStatement);
List queryResults; List<?> queryResults;
if (namedParameters) { if (namedParameters) {
Map<String, Object> params = new HashMap<String, Object>(2); Map<String, Object> params = new HashMap<String, Object>(2);
params.put("id", new Integer(1)); params.put("id", 1);
params.put("country", "UK"); params.put("country", "UK");
queryResults = query.executeByNamedParam(params); queryResults = query.executeByNamedParam(params);
} }
else { else {
Object[] params = new Object[] {new Integer(1), "UK"}; Object[] params = new Object[] {1, "UK"};
queryResults = query.execute(params); queryResults = query.execute(params);
} }
assertTrue("Customer was returned correctly", queryResults.size() == 1); 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")); assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
verify(resultSet).close(); 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).setString(2, "UK");
verify(preparedStatement).close(); verify(preparedStatement).close();
} }

8
spring-jdbc/src/test/resources/org/springframework/jdbc/object/GenericSqlQueryTests-context.xml

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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" 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"> 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="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="dataSource" ref="dataSource"/>
<property name="sql" value="select id, forename from custmr where id = ? and country = ?"/> <property name="sql" value="select id, forename from custmr where id = ? and country = ?"/>
<property name="parameters"> <property name="parameters">
@ -15,7 +15,7 @@
<constructor-arg index="0" value="amount"/> <constructor-arg index="0" value="amount"/>
<constructor-arg index="1"> <constructor-arg index="1">
<util:constant static-field="java.sql.Types.INTEGER"/> <util:constant static-field="java.sql.Types.INTEGER"/>
</constructor-arg> </constructor-arg>
</bean> </bean>
<bean class="org.springframework.jdbc.core.SqlParameter"> <bean class="org.springframework.jdbc.core.SqlParameter">
<constructor-arg index="0" value="custid"/> <constructor-arg index="0" value="custid"/>
@ -47,7 +47,7 @@
</bean> </bean>
</list> </list>
</property> </property>
<property name="rowMapperClass" value="org.springframework.jdbc.object.CustomerMapper"/> <property name="rowMapperClass" value="org.springframework.jdbc.object.CustomerMapper"/>
</bean> </bean>
</beans> </beans>

8
spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java

@ -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"); * 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.
@ -63,7 +63,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
@Before @Before
public void setUp() { public void setUp() {
converter = new Jaxb2CollectionHttpMessageConverter<>(); converter = new Jaxb2CollectionHttpMessageConverter<Collection<Object>>();
rootElementListType = new ParameterizedTypeReference<List<RootElement>>() {}.getType(); rootElementListType = new ParameterizedTypeReference<List<RootElement>>() {}.getType();
rootElementSetType = new ParameterizedTypeReference<Set<RootElement>>() {}.getType(); rootElementSetType = new ParameterizedTypeReference<Set<RootElement>>() {}.getType();
typeListType = new ParameterizedTypeReference<List<TestType>>() {}.getType(); typeListType = new ParameterizedTypeReference<List<TestType>>() {}.getType();
@ -157,7 +157,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
assertEquals("", result.iterator().next().external); assertEquals("", result.iterator().next().external);
} }
catch (HttpMessageNotReadableException ex) { catch (HttpMessageNotReadableException ex) {
// Some parsers raise exception by default // Some parsers raise an exception
} }
} }
@ -212,7 +212,6 @@ public class Jaxb2CollectionHttpMessageConverterTests {
} }
@SuppressWarnings("unused")
@XmlRootElement @XmlRootElement
public static class RootElement { public static class RootElement {
@ -247,6 +246,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
} }
} }
@XmlType @XmlType
public static class TestType { public static class TestType {

16
spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java

@ -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"); * 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.
@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.Arrays;
import java.util.Collections; import java.util.Collections;
@ -24,6 +23,7 @@ import java.util.Map;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockServletContext; 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.NativeWebRequest;
import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.context.request.ServletWebRequest;
import static org.junit.Assert.*;
/** /**
* Test fixture for {@link ContentNegotiationManagerFactoryBean} tests. * Test fixture for {@link ContentNegotiationManagerFactoryBean} tests.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class ContentNegotiationManagerFactoryBeanTests { public class ContentNegotiationManagerFactoryBeanTests {
@ -43,6 +46,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
private MockHttpServletRequest servletRequest; private MockHttpServletRequest servletRequest;
@Before @Before
public void setup() { public void setup() {
TestServletContext servletContext = new TestServletContext(); TestServletContext servletContext = new TestServletContext();
@ -55,6 +59,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
this.factoryBean.setServletContext(this.servletRequest.getServletContext()); this.factoryBean.setServletContext(this.servletRequest.getServletContext());
} }
@Test @Test
public void defaultSettings() throws Exception { public void defaultSettings() throws Exception {
this.factoryBean.afterPropertiesSet(); this.factoryBean.afterPropertiesSet();
@ -149,17 +154,14 @@ public class ContentNegotiationManagerFactoryBeanTests {
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest));
// SPR-10513 // SPR-10513
this.servletRequest.addHeader("Accept", MediaType.ALL_VALUE); this.servletRequest.addHeader("Accept", MediaType.ALL_VALUE);
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest));
} }
private static class TestServletContext extends MockServletContext { 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() { public Map<String, String> getMimeTypes() {
return this.mimeTypes; return this.mimeTypes;

Loading…
Cancel
Save