Consistent Class array vs vararg declarations (and related polishing)

This commit is contained in:
Juergen Hoeller 2018-02-14 14:44:00 +01:00
parent 46cbdff5c3
commit 3b810f3544
39 changed files with 388 additions and 413 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2018 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.
@ -47,7 +47,7 @@ public class ConcurrencyThrottleInterceptorTests {
public void testSerializable() throws Exception { public void testSerializable() throws Exception {
DerivedTestBean tb = new DerivedTestBean(); DerivedTestBean tb = new DerivedTestBean();
ProxyFactory proxyFactory = new ProxyFactory(); ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(new Class[] {ITestBean.class}); proxyFactory.setInterfaces(ITestBean.class);
ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor(); ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
proxyFactory.addAdvice(cti); proxyFactory.addAdvice(cti);
proxyFactory.setTarget(tb); proxyFactory.setTarget(tb);
@ -75,7 +75,7 @@ public class ConcurrencyThrottleInterceptorTests {
private void testMultipleThreads(int concurrencyLimit) { private void testMultipleThreads(int concurrencyLimit) {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
ProxyFactory proxyFactory = new ProxyFactory(); ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(new Class[] {ITestBean.class}); proxyFactory.setInterfaces(ITestBean.class);
ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor(); ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
cti.setConcurrencyLimit(concurrencyLimit); cti.setConcurrencyLimit(concurrencyLimit);
proxyFactory.addAdvice(cti); proxyFactory.addAdvice(cti);
@ -95,7 +95,7 @@ public class ConcurrencyThrottleInterceptorTests {
ex.printStackTrace(); ex.printStackTrace();
} }
threads[i] = new ConcurrencyThread(proxy, threads[i] = new ConcurrencyThread(proxy,
i % 2 == 0 ? (Throwable) new OutOfMemoryError() : (Throwable) new IllegalStateException()); i % 2 == 0 ? new OutOfMemoryError() : new IllegalStateException());
threads[i].start(); threads[i].start();
} }
for (int i = 0; i < NR_OF_THREADS; i++) { for (int i = 0; i < NR_OF_THREADS; i++) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2018 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.
@ -83,7 +83,7 @@ public class CustomizableTraceInterceptorTests {
public void testSunnyDayPathLogsCorrectly() throws Throwable { public void testSunnyDayPathLogsCorrectly() throws Throwable {
MethodInvocation methodInvocation = mock(MethodInvocation.class); MethodInvocation methodInvocation = mock(MethodInvocation.class);
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString", new Class[]{})); given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
given(methodInvocation.getThis()).willReturn(this); given(methodInvocation.getThis()).willReturn(this);
Log log = mock(Log.class); Log log = mock(Log.class);
@ -101,7 +101,7 @@ public class CustomizableTraceInterceptorTests {
MethodInvocation methodInvocation = mock(MethodInvocation.class); MethodInvocation methodInvocation = mock(MethodInvocation.class);
IllegalArgumentException exception = new IllegalArgumentException(); IllegalArgumentException exception = new IllegalArgumentException();
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString", new Class[]{})); given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
given(methodInvocation.getThis()).willReturn(this); given(methodInvocation.getThis()).willReturn(this);
given(methodInvocation.proceed()).willThrow(exception); given(methodInvocation.proceed()).willThrow(exception);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2018 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.
@ -34,7 +34,7 @@ public class SimpleTraceInterceptorTests {
@Test @Test
public void testSunnyDayPathLogsCorrectly() throws Throwable { public void testSunnyDayPathLogsCorrectly() throws Throwable {
MethodInvocation mi = mock(MethodInvocation.class); MethodInvocation mi = mock(MethodInvocation.class);
given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[]{})); given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
given(mi.getThis()).willReturn(this); given(mi.getThis()).willReturn(this);
Log log = mock(Log.class); Log log = mock(Log.class);
@ -48,7 +48,7 @@ public class SimpleTraceInterceptorTests {
@Test @Test
public void testExceptionPathStillLogsCorrectly() throws Throwable { public void testExceptionPathStillLogsCorrectly() throws Throwable {
MethodInvocation mi = mock(MethodInvocation.class); MethodInvocation mi = mock(MethodInvocation.class);
given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[]{})); given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
given(mi.getThis()).willReturn(this); given(mi.getThis()).willReturn(this);
IllegalArgumentException exception = new IllegalArgumentException(); IllegalArgumentException exception = new IllegalArgumentException();
given(mi.proceed()).willThrow(exception); given(mi.proceed()).willThrow(exception);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -226,14 +226,14 @@ public class BeanUtilsTests {
@Test @Test
public void testResolveWithAndWithoutArgList() throws Exception { public void testResolveWithAndWithoutArgList() throws Exception {
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingElse", new Class[]{String.class, int.class}); Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingElse", String.class, int.class);
assertSignatureEquals(desiredMethod, "doSomethingElse"); assertSignatureEquals(desiredMethod, "doSomethingElse");
assertNull(BeanUtils.resolveSignature("doSomethingElse()", MethodSignatureBean.class)); assertNull(BeanUtils.resolveSignature("doSomethingElse()", MethodSignatureBean.class));
} }
@Test @Test
public void testResolveTypedSignature() throws Exception { public void testResolveTypedSignature() throws Exception {
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingElse", new Class[]{String.class, int.class}); Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingElse", String.class, int.class);
assertSignatureEquals(desiredMethod, "doSomethingElse(java.lang.String, int)"); assertSignatureEquals(desiredMethod, "doSomethingElse(java.lang.String, int)");
} }
@ -244,20 +244,20 @@ public class BeanUtilsTests {
assertSignatureEquals(desiredMethod, "overloaded()"); assertSignatureEquals(desiredMethod, "overloaded()");
// resolve with single arg // resolve with single arg
desiredMethod = MethodSignatureBean.class.getMethod("overloaded", new Class[]{String.class}); desiredMethod = MethodSignatureBean.class.getMethod("overloaded", String.class);
assertSignatureEquals(desiredMethod, "overloaded(java.lang.String)"); assertSignatureEquals(desiredMethod, "overloaded(java.lang.String)");
// resolve with two args // resolve with two args
desiredMethod = MethodSignatureBean.class.getMethod("overloaded", new Class[]{String.class, BeanFactory.class}); desiredMethod = MethodSignatureBean.class.getMethod("overloaded", String.class, BeanFactory.class);
assertSignatureEquals(desiredMethod, "overloaded(java.lang.String, org.springframework.beans.factory.BeanFactory)"); assertSignatureEquals(desiredMethod, "overloaded(java.lang.String, org.springframework.beans.factory.BeanFactory)");
} }
@Test @Test
public void testResolveSignatureWithArray() throws Exception { public void testResolveSignatureWithArray() throws Exception {
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingWithAnArray", new Class[]{String[].class}); Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingWithAnArray", String[].class);
assertSignatureEquals(desiredMethod, "doSomethingWithAnArray(java.lang.String[])"); assertSignatureEquals(desiredMethod, "doSomethingWithAnArray(java.lang.String[])");
desiredMethod = MethodSignatureBean.class.getMethod("doSomethingWithAMultiDimensionalArray", new Class[]{String[][].class}); desiredMethod = MethodSignatureBean.class.getMethod("doSomethingWithAMultiDimensionalArray", String[][].class);
assertSignatureEquals(desiredMethod, "doSomethingWithAMultiDimensionalArray(java.lang.String[][])"); assertSignatureEquals(desiredMethod, "doSomethingWithAMultiDimensionalArray(java.lang.String[][])");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 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.
@ -34,60 +34,54 @@ public class AutowireUtilsTests {
@Test @Test
public void genericMethodReturnTypes() { public void genericMethodReturnTypes() {
Method notParameterized = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterized", new Class[]{}); Method notParameterized = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterized");
assertEquals(String.class, assertEquals(String.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterized, new Object[]{}, getClass().getClassLoader())); AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterized, new Object[]{}, getClass().getClassLoader()));
Method notParameterizedWithArguments = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterizedWithArguments", Method notParameterizedWithArguments = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterizedWithArguments", Integer.class, Boolean.class);
new Class[] { Integer.class, Boolean.class });
assertEquals(String.class, assertEquals(String.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterizedWithArguments, new Object[] { 99, true }, getClass().getClassLoader())); AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterizedWithArguments, new Object[] {99, true}, getClass().getClassLoader()));
Method createProxy = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createProxy", new Class[] { Object.class }); Method createProxy = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createProxy", Object.class);
assertEquals(String.class, assertEquals(String.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createProxy, new Object[] { "foo" }, getClass().getClassLoader())); AutowireUtils.resolveReturnTypeForFactoryMethod(createProxy, new Object[] {"foo"}, getClass().getClassLoader()));
Method createNamedProxyWithDifferentTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy", Method createNamedProxyWithDifferentTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy", String.class, Object.class);
new Class[] { String.class, Object.class });
assertEquals(Long.class, assertEquals(Long.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDifferentTypes, new Object[] { "enigma", 99L }, getClass().getClassLoader())); AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDifferentTypes, new Object[] {"enigma", 99L}, getClass().getClassLoader()));
Method createNamedProxyWithDuplicateTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy", Method createNamedProxyWithDuplicateTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy", String.class, Object.class);
new Class[] { String.class, Object.class });
assertEquals(String.class, assertEquals(String.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDuplicateTypes, new Object[] { "enigma", "foo" }, getClass().getClassLoader())); AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDuplicateTypes, new Object[] {"enigma", "foo"}, getClass().getClassLoader()));
Method createMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createMock", new Class[] { Class.class }); Method createMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createMock", Class.class);
assertEquals(Runnable.class, assertEquals(Runnable.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] { Runnable.class }, getClass().getClassLoader())); AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] {Runnable.class}, getClass().getClassLoader()));
assertEquals(Runnable.class, assertEquals(Runnable.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] { Runnable.class.getName() }, getClass().getClassLoader())); AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] {Runnable.class.getName()}, getClass().getClassLoader()));
Method createNamedMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedMock", new Class[] { String.class, Method createNamedMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedMock", String.class, Class.class);
Class.class });
assertEquals(Runnable.class, assertEquals(Runnable.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedMock, new Object[] { "foo", Runnable.class }, getClass().getClassLoader())); AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedMock, new Object[] {"foo", Runnable.class}, getClass().getClassLoader()));
Method createVMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createVMock", Method createVMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createVMock", Object.class, Class.class);
new Class[] { Object.class, Class.class });
assertEquals(Runnable.class, assertEquals(Runnable.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createVMock, new Object[] { "foo", Runnable.class }, getClass().getClassLoader())); AutowireUtils.resolveReturnTypeForFactoryMethod(createVMock, new Object[] {"foo", Runnable.class}, getClass().getClassLoader()));
// Ideally we would expect String.class instead of Object.class, but // Ideally we would expect String.class instead of Object.class, but
// resolveReturnTypeForFactoryMethod() does not currently support this form of // resolveReturnTypeForFactoryMethod() does not currently support this form of
// look-up. // look-up.
Method extractValueFrom = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractValueFrom", Method extractValueFrom = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractValueFrom", MyInterfaceType.class);
new Class[] { MyInterfaceType.class });
assertEquals(Object.class, assertEquals(Object.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(extractValueFrom, new Object[] { new MySimpleInterfaceType() }, getClass().getClassLoader())); AutowireUtils.resolveReturnTypeForFactoryMethod(extractValueFrom, new Object[] {new MySimpleInterfaceType()}, getClass().getClassLoader()));
// Ideally we would expect Boolean.class instead of Object.class, but this // Ideally we would expect Boolean.class instead of Object.class, but this
// information is not available at run-time due to type erasure. // information is not available at run-time due to type erasure.
Map<Integer, Boolean> map = new HashMap<>(); Map<Integer, Boolean> map = new HashMap<>();
map.put(0, false); map.put(0, false);
map.put(1, true); map.put(1, true);
Method extractMagicValue = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractMagicValue", new Class[] { Map.class }); Method extractMagicValue = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractMagicValue", Map.class);
assertEquals(Object.class, AutowireUtils.resolveReturnTypeForFactoryMethod(extractMagicValue, new Object[] { map }, getClass().getClassLoader())); assertEquals(Object.class, AutowireUtils.resolveReturnTypeForFactoryMethod(extractMagicValue, new Object[] {map}, getClass().getClassLoader()));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -139,7 +139,7 @@ public abstract class AbstractSlsbInvokerInterceptor extends JndiObjectLocator
protected Method getCreateMethod(Object home) throws EjbAccessException { protected Method getCreateMethod(Object home) throws EjbAccessException {
try { try {
// Cache the EJB create() method that must be declared on the home interface. // Cache the EJB create() method that must be declared on the home interface.
return home.getClass().getMethod("create", (Class[]) null); return home.getClass().getMethod("create");
} }
catch (NoSuchMethodException ex) { catch (NoSuchMethodException ex) {
throw new EjbAccessException("EJB home [" + home + "] has no no-arg create() method"); throw new EjbAccessException("EJB home [" + home + "] has no no-arg create() method");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -34,11 +34,11 @@ import reactor.core.publisher.Mono;
import org.springframework.tests.sample.objects.TestObject; import org.springframework.tests.sample.objects.TestObject;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
/** /**
* Unit tests for {@link Conventions}. * Unit tests for {@link Conventions}.
*
* @author Rob Harrop * @author Rob Harrop
* @author Sam Brannen * @author Sam Brannen
*/ */
@ -50,13 +50,10 @@ public class ConventionsTests {
@Test @Test
public void simpleObject() { public void simpleObject() {
assertEquals("Incorrect singular variable name", assertEquals("Incorrect singular variable name",
"testObject", Conventions.getVariableName(new TestObject())); "testObject", Conventions.getVariableName(new TestObject()));
assertEquals("Incorrect singular variable name", "testObject", assertEquals("Incorrect singular variable name", "testObject",
Conventions.getVariableNameForParameter(getMethodParameter(TestObject.class))); Conventions.getVariableNameForParameter(getMethodParameter(TestObject.class)));
assertEquals("Incorrect singular variable name", "testObject", assertEquals("Incorrect singular variable name", "testObject",
Conventions.getVariableNameForReturnType(getMethodForReturnType(TestObject.class))); Conventions.getVariableNameForReturnType(getMethodForReturnType(TestObject.class)));
} }
@ -69,13 +66,10 @@ public class ConventionsTests {
@Test @Test
public void list() { public void list() {
assertEquals("Incorrect plural List form", "testObjectList", assertEquals("Incorrect plural List form", "testObjectList",
Conventions.getVariableName(Collections.singletonList(new TestObject()))); Conventions.getVariableName(Collections.singletonList(new TestObject())));
assertEquals("Incorrect plural List form", "testObjectList", assertEquals("Incorrect plural List form", "testObjectList",
Conventions.getVariableNameForParameter(getMethodParameter(List.class))); Conventions.getVariableNameForParameter(getMethodParameter(List.class)));
assertEquals("Incorrect plural List form", "testObjectList", assertEquals("Incorrect plural List form", "testObjectList",
Conventions.getVariableNameForReturnType(getMethodForReturnType(List.class))); Conventions.getVariableNameForReturnType(getMethodForReturnType(List.class)));
} }
@ -88,58 +82,47 @@ public class ConventionsTests {
@Test @Test
public void set() { public void set() {
assertEquals("Incorrect plural Set form", "testObjectList", assertEquals("Incorrect plural Set form", "testObjectList",
Conventions.getVariableName(Collections.singleton(new TestObject()))); Conventions.getVariableName(Collections.singleton(new TestObject())));
assertEquals("Incorrect plural Set form", "testObjectList", assertEquals("Incorrect plural Set form", "testObjectList",
Conventions.getVariableNameForParameter(getMethodParameter(Set.class))); Conventions.getVariableNameForParameter(getMethodParameter(Set.class)));
assertEquals("Incorrect plural Set form", "testObjectList", assertEquals("Incorrect plural Set form", "testObjectList",
Conventions.getVariableNameForReturnType(getMethodForReturnType(Set.class))); Conventions.getVariableNameForReturnType(getMethodForReturnType(Set.class)));
} }
@Test @Test
public void reactiveParameters() throws Exception { public void reactiveParameters() {
assertEquals("testObjectMono", assertEquals("testObjectMono",
Conventions.getVariableNameForParameter(getMethodParameter(Mono.class))); Conventions.getVariableNameForParameter(getMethodParameter(Mono.class)));
assertEquals("testObjectFlux", assertEquals("testObjectFlux",
Conventions.getVariableNameForParameter(getMethodParameter(Flux.class))); Conventions.getVariableNameForParameter(getMethodParameter(Flux.class)));
assertEquals("testObjectSingle", assertEquals("testObjectSingle",
Conventions.getVariableNameForParameter(getMethodParameter(Single.class))); Conventions.getVariableNameForParameter(getMethodParameter(Single.class)));
assertEquals("testObjectObservable", assertEquals("testObjectObservable",
Conventions.getVariableNameForParameter(getMethodParameter(Observable.class))); Conventions.getVariableNameForParameter(getMethodParameter(Observable.class)));
} }
@Test @Test
public void reactiveReturnTypes() throws Exception { public void reactiveReturnTypes() {
assertEquals("testObjectMono", assertEquals("testObjectMono",
Conventions.getVariableNameForReturnType(getMethodForReturnType(Mono.class))); Conventions.getVariableNameForReturnType(getMethodForReturnType(Mono.class)));
assertEquals("testObjectFlux", assertEquals("testObjectFlux",
Conventions.getVariableNameForReturnType(getMethodForReturnType(Flux.class))); Conventions.getVariableNameForReturnType(getMethodForReturnType(Flux.class)));
assertEquals("testObjectSingle", assertEquals("testObjectSingle",
Conventions.getVariableNameForReturnType(getMethodForReturnType(Single.class))); Conventions.getVariableNameForReturnType(getMethodForReturnType(Single.class)));
assertEquals("testObjectObservable", assertEquals("testObjectObservable",
Conventions.getVariableNameForReturnType(getMethodForReturnType(Observable.class))); Conventions.getVariableNameForReturnType(getMethodForReturnType(Observable.class)));
} }
@Test @Test
public void attributeNameToPropertyName() throws Exception { public void attributeNameToPropertyName() {
assertEquals("transactionManager", Conventions.attributeNameToPropertyName("transaction-manager")); assertEquals("transactionManager", Conventions.attributeNameToPropertyName("transaction-manager"));
assertEquals("pointcutRef", Conventions.attributeNameToPropertyName("pointcut-ref")); assertEquals("pointcutRef", Conventions.attributeNameToPropertyName("pointcut-ref"));
assertEquals("lookupOnStartup", Conventions.attributeNameToPropertyName("lookup-on-startup")); assertEquals("lookupOnStartup", Conventions.attributeNameToPropertyName("lookup-on-startup"));
} }
@Test @Test
public void getQualifiedAttributeName() throws Exception { public void getQualifiedAttributeName() {
String baseName = "foo"; String baseName = "foo";
Class<String> cls = String.class; Class<String> cls = String.class;
String desiredResult = "java.lang.String.foo"; String desiredResult = "java.lang.String.foo";

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2018 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.
@ -39,7 +39,7 @@ public class LocalVariableTableParameterNameDiscovererTests {
@Test @Test
public void methodParameterNameDiscoveryNoArgs() throws NoSuchMethodException { public void methodParameterNameDiscoveryNoArgs() throws NoSuchMethodException {
Method getName = TestObject.class.getMethod("getName", new Class[0]); Method getName = TestObject.class.getMethod("getName");
String[] names = discoverer.getParameterNames(getName); String[] names = discoverer.getParameterNames(getName);
assertNotNull("should find method info", names); assertNotNull("should find method info", names);
assertEquals("no argument names", 0, names.length); assertEquals("no argument names", 0, names.length);
@ -47,7 +47,7 @@ public class LocalVariableTableParameterNameDiscovererTests {
@Test @Test
public void methodParameterNameDiscoveryWithArgs() throws NoSuchMethodException { public void methodParameterNameDiscoveryWithArgs() throws NoSuchMethodException {
Method setName = TestObject.class.getMethod("setName", new Class[] { String.class }); Method setName = TestObject.class.getMethod("setName", String.class);
String[] names = discoverer.getParameterNames(setName); String[] names = discoverer.getParameterNames(setName);
assertNotNull("should find method info", names); assertNotNull("should find method info", names);
assertEquals("one argument", 1, names.length); assertEquals("one argument", 1, names.length);
@ -56,7 +56,7 @@ public class LocalVariableTableParameterNameDiscovererTests {
@Test @Test
public void consParameterNameDiscoveryNoArgs() throws NoSuchMethodException { public void consParameterNameDiscoveryNoArgs() throws NoSuchMethodException {
Constructor<TestObject> noArgsCons = TestObject.class.getConstructor(new Class[0]); Constructor<TestObject> noArgsCons = TestObject.class.getConstructor();
String[] names = discoverer.getParameterNames(noArgsCons); String[] names = discoverer.getParameterNames(noArgsCons);
assertNotNull("should find cons info", names); assertNotNull("should find cons info", names);
assertEquals("no argument names", 0, names.length); assertEquals("no argument names", 0, names.length);
@ -64,7 +64,7 @@ public class LocalVariableTableParameterNameDiscovererTests {
@Test @Test
public void consParameterNameDiscoveryArgs() throws NoSuchMethodException { public void consParameterNameDiscoveryArgs() throws NoSuchMethodException {
Constructor<TestObject> twoArgCons = TestObject.class.getConstructor(new Class[] { String.class, int.class }); Constructor<TestObject> twoArgCons = TestObject.class.getConstructor(String.class, int.class);
String[] names = discoverer.getParameterNames(twoArgCons); String[] names = discoverer.getParameterNames(twoArgCons);
assertNotNull("should find cons info", names); assertNotNull("should find cons info", names);
assertEquals("one argument", 2, names.length); assertEquals("one argument", 2, names.length);
@ -74,7 +74,7 @@ public class LocalVariableTableParameterNameDiscovererTests {
@Test @Test
public void staticMethodParameterNameDiscoveryNoArgs() throws NoSuchMethodException { public void staticMethodParameterNameDiscoveryNoArgs() throws NoSuchMethodException {
Method m = getClass().getMethod("staticMethodNoLocalVars", new Class[0]); Method m = getClass().getMethod("staticMethodNoLocalVars");
String[] names = discoverer.getParameterNames(m); String[] names = discoverer.getParameterNames(m);
assertNotNull("should find method info", names); assertNotNull("should find method info", names);
assertEquals("no argument names", 0, names.length); assertEquals("no argument names", 0, names.length);
@ -84,14 +84,14 @@ public class LocalVariableTableParameterNameDiscovererTests {
public void overloadedStaticMethod() throws Exception { public void overloadedStaticMethod() throws Exception {
Class<? extends LocalVariableTableParameterNameDiscovererTests> clazz = this.getClass(); Class<? extends LocalVariableTableParameterNameDiscovererTests> clazz = this.getClass();
Method m1 = clazz.getMethod("staticMethod", new Class[] { Long.TYPE, Long.TYPE }); Method m1 = clazz.getMethod("staticMethod", Long.TYPE, Long.TYPE);
String[] names = discoverer.getParameterNames(m1); String[] names = discoverer.getParameterNames(m1);
assertNotNull("should find method info", names); assertNotNull("should find method info", names);
assertEquals("two arguments", 2, names.length); assertEquals("two arguments", 2, names.length);
assertEquals("x", names[0]); assertEquals("x", names[0]);
assertEquals("y", names[1]); assertEquals("y", names[1]);
Method m2 = clazz.getMethod("staticMethod", new Class[] { Long.TYPE, Long.TYPE, Long.TYPE }); Method m2 = clazz.getMethod("staticMethod", Long.TYPE, Long.TYPE, Long.TYPE);
names = discoverer.getParameterNames(m2); names = discoverer.getParameterNames(m2);
assertNotNull("should find method info", names); assertNotNull("should find method info", names);
assertEquals("three arguments", 3, names.length); assertEquals("three arguments", 3, names.length);
@ -104,13 +104,13 @@ public class LocalVariableTableParameterNameDiscovererTests {
public void overloadedStaticMethodInInnerClass() throws Exception { public void overloadedStaticMethodInInnerClass() throws Exception {
Class<InnerClass> clazz = InnerClass.class; Class<InnerClass> clazz = InnerClass.class;
Method m1 = clazz.getMethod("staticMethod", new Class[] { Long.TYPE }); Method m1 = clazz.getMethod("staticMethod", Long.TYPE);
String[] names = discoverer.getParameterNames(m1); String[] names = discoverer.getParameterNames(m1);
assertNotNull("should find method info", names); assertNotNull("should find method info", names);
assertEquals("one argument", 1, names.length); assertEquals("one argument", 1, names.length);
assertEquals("x", names[0]); assertEquals("x", names[0]);
Method m2 = clazz.getMethod("staticMethod", new Class[] { Long.TYPE, Long.TYPE }); Method m2 = clazz.getMethod("staticMethod", Long.TYPE, Long.TYPE);
names = discoverer.getParameterNames(m2); names = discoverer.getParameterNames(m2);
assertNotNull("should find method info", names); assertNotNull("should find method info", names);
assertEquals("two arguments", 2, names.length); assertEquals("two arguments", 2, names.length);
@ -122,14 +122,14 @@ public class LocalVariableTableParameterNameDiscovererTests {
public void overloadedMethod() throws Exception { public void overloadedMethod() throws Exception {
Class<? extends LocalVariableTableParameterNameDiscovererTests> clazz = this.getClass(); Class<? extends LocalVariableTableParameterNameDiscovererTests> clazz = this.getClass();
Method m1 = clazz.getMethod("instanceMethod", new Class[] { Double.TYPE, Double.TYPE }); Method m1 = clazz.getMethod("instanceMethod", Double.TYPE, Double.TYPE);
String[] names = discoverer.getParameterNames(m1); String[] names = discoverer.getParameterNames(m1);
assertNotNull("should find method info", names); assertNotNull("should find method info", names);
assertEquals("two arguments", 2, names.length); assertEquals("two arguments", 2, names.length);
assertEquals("x", names[0]); assertEquals("x", names[0]);
assertEquals("y", names[1]); assertEquals("y", names[1]);
Method m2 = clazz.getMethod("instanceMethod", new Class[] { Double.TYPE, Double.TYPE, Double.TYPE }); Method m2 = clazz.getMethod("instanceMethod", Double.TYPE, Double.TYPE, Double.TYPE);
names = discoverer.getParameterNames(m2); names = discoverer.getParameterNames(m2);
assertNotNull("should find method info", names); assertNotNull("should find method info", names);
assertEquals("three arguments", 3, names.length); assertEquals("three arguments", 3, names.length);
@ -142,13 +142,13 @@ public class LocalVariableTableParameterNameDiscovererTests {
public void overloadedMethodInInnerClass() throws Exception { public void overloadedMethodInInnerClass() throws Exception {
Class<InnerClass> clazz = InnerClass.class; Class<InnerClass> clazz = InnerClass.class;
Method m1 = clazz.getMethod("instanceMethod", new Class[] { String.class }); Method m1 = clazz.getMethod("instanceMethod", String.class);
String[] names = discoverer.getParameterNames(m1); String[] names = discoverer.getParameterNames(m1);
assertNotNull("should find method info", names); assertNotNull("should find method info", names);
assertEquals("one argument", 1, names.length); assertEquals("one argument", 1, names.length);
assertEquals("aa", names[0]); assertEquals("aa", names[0]);
Method m2 = clazz.getMethod("instanceMethod", new Class[] { String.class, String.class }); Method m2 = clazz.getMethod("instanceMethod", String.class, String.class);
names = discoverer.getParameterNames(m2); names = discoverer.getParameterNames(m2);
assertNotNull("should find method info", names); assertNotNull("should find method info", names);
assertEquals("two arguments", 2, names.length); assertEquals("two arguments", 2, names.length);
@ -223,6 +223,7 @@ public class LocalVariableTableParameterNameDiscovererTests {
assertNull(names); assertNull(names);
} }
public static void staticMethodNoLocalVars() { public static void staticMethodNoLocalVars() {
} }
@ -246,6 +247,7 @@ public class LocalVariableTableParameterNameDiscovererTests {
return u; return u;
} }
public static class InnerClass { public static class InnerClass {
public int waz = 0; public int waz = 0;
@ -278,7 +280,9 @@ public class LocalVariableTableParameterNameDiscovererTests {
} }
} }
public static class GenerifiedClass<K, V> { public static class GenerifiedClass<K, V> {
private static long date; private static long date;
static { static {
@ -317,4 +321,5 @@ public class LocalVariableTableParameterNameDiscovererTests {
return date; return date;
} }
} }
} }

View File

@ -56,7 +56,7 @@ public class PrioritizedParameterNameDiscovererTests {
private final Method anyMethod; private final Method anyMethod;
public PrioritizedParameterNameDiscovererTests() throws SecurityException, NoSuchMethodException { public PrioritizedParameterNameDiscovererTests() throws SecurityException, NoSuchMethodException {
anyMethod = TestObject.class.getMethod("getAge", (Class[]) null); anyMethod = TestObject.class.getMethod("getAge");
} }
@Test @Test

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 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.
@ -309,30 +309,30 @@ public class AnnotationMetadataTests {
AnnotationAttributes nestedAnno = specialAttrs.getAnnotation("nestedAnno"); AnnotationAttributes nestedAnno = specialAttrs.getAnnotation("nestedAnno");
assertThat("na", is(nestedAnno.getString("value"))); assertThat("na", is(nestedAnno.getString("value")));
assertTrue(nestedAnno.getEnum("anEnum").equals(SomeEnum.LABEL1)); assertTrue(nestedAnno.getEnum("anEnum").equals(SomeEnum.LABEL1));
assertArrayEquals(new Class[] { String.class }, (Class[]) nestedAnno.get("classArray")); assertArrayEquals(new Class<?>[] {String.class}, (Class<?>[]) nestedAnno.get("classArray"));
AnnotationAttributes[] nestedAnnoArray = specialAttrs.getAnnotationArray("nestedAnnoArray"); AnnotationAttributes[] nestedAnnoArray = specialAttrs.getAnnotationArray("nestedAnnoArray");
assertThat(nestedAnnoArray.length, is(2)); assertThat(nestedAnnoArray.length, is(2));
assertThat(nestedAnnoArray[0].getString("value"), is("default")); assertThat(nestedAnnoArray[0].getString("value"), is("default"));
assertTrue(nestedAnnoArray[0].getEnum("anEnum").equals(SomeEnum.DEFAULT)); assertTrue(nestedAnnoArray[0].getEnum("anEnum").equals(SomeEnum.DEFAULT));
assertArrayEquals(new Class[] { Void.class }, (Class[]) nestedAnnoArray[0].get("classArray")); assertArrayEquals(new Class<?>[] {Void.class}, (Class<?>[]) nestedAnnoArray[0].get("classArray"));
assertThat(nestedAnnoArray[1].getString("value"), is("na1")); assertThat(nestedAnnoArray[1].getString("value"), is("na1"));
assertTrue(nestedAnnoArray[1].getEnum("anEnum").equals(SomeEnum.LABEL2)); assertTrue(nestedAnnoArray[1].getEnum("anEnum").equals(SomeEnum.LABEL2));
assertArrayEquals(new Class[] { Number.class }, (Class[]) nestedAnnoArray[1].get("classArray")); assertArrayEquals(new Class<?>[] {Number.class}, (Class<?>[]) nestedAnnoArray[1].get("classArray"));
assertArrayEquals(new Class[] { Number.class }, nestedAnnoArray[1].getClassArray("classArray")); assertArrayEquals(new Class<?>[] {Number.class}, nestedAnnoArray[1].getClassArray("classArray"));
AnnotationAttributes optional = specialAttrs.getAnnotation("optional"); AnnotationAttributes optional = specialAttrs.getAnnotation("optional");
assertThat(optional.getString("value"), is("optional")); assertThat(optional.getString("value"), is("optional"));
assertTrue(optional.getEnum("anEnum").equals(SomeEnum.DEFAULT)); assertTrue(optional.getEnum("anEnum").equals(SomeEnum.DEFAULT));
assertArrayEquals(new Class[] { Void.class }, (Class[]) optional.get("classArray")); assertArrayEquals(new Class<?>[] {Void.class}, (Class<?>[]) optional.get("classArray"));
assertArrayEquals(new Class[] { Void.class }, optional.getClassArray("classArray")); assertArrayEquals(new Class<?>[] {Void.class}, optional.getClassArray("classArray"));
AnnotationAttributes[] optionalArray = specialAttrs.getAnnotationArray("optionalArray"); AnnotationAttributes[] optionalArray = specialAttrs.getAnnotationArray("optionalArray");
assertThat(optionalArray.length, is(1)); assertThat(optionalArray.length, is(1));
assertThat(optionalArray[0].getString("value"), is("optional")); assertThat(optionalArray[0].getString("value"), is("optional"));
assertTrue(optionalArray[0].getEnum("anEnum").equals(SomeEnum.DEFAULT)); assertTrue(optionalArray[0].getEnum("anEnum").equals(SomeEnum.DEFAULT));
assertArrayEquals(new Class[] { Void.class }, (Class[]) optionalArray[0].get("classArray")); assertArrayEquals(new Class<?>[] {Void.class}, (Class<?>[]) optionalArray[0].get("classArray"));
assertArrayEquals(new Class[] { Void.class }, optionalArray[0].getClassArray("classArray")); assertArrayEquals(new Class<?>[] {Void.class}, optionalArray[0].getClassArray("classArray"));
assertEquals("direct", metadata.getAnnotationAttributes(DirectAnnotation.class.getName()).get("value")); assertEquals("direct", metadata.getAnnotationAttributes(DirectAnnotation.class.getName()).get("value"));
allMeta = metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName()).get("value"); allMeta = metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName()).get("value");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2018 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,6 +13,7 @@
* 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.core.type; package org.springframework.core.type;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -30,9 +31,9 @@ abstract class ClassloadingAssertions {
private static boolean isClassLoaded(String className) { private static boolean isClassLoaded(String className) {
ClassLoader cl = ClassUtils.getDefaultClassLoader(); ClassLoader cl = ClassUtils.getDefaultClassLoader();
Method findLoadeClassMethod = ReflectionUtils.findMethod(cl.getClass(), "findLoadedClass", new Class[] { String.class }); Method findLoadedClassMethod = ReflectionUtils.findMethod(cl.getClass(), "findLoadedClass", String.class);
ReflectionUtils.makeAccessible(findLoadeClassMethod); ReflectionUtils.makeAccessible(findLoadedClassMethod);
Class<?> loadedClass = (Class<?>) ReflectionUtils.invokeMethod(findLoadeClassMethod, cl, new Object[] { className }); Class<?> loadedClass = (Class<?>) ReflectionUtils.invokeMethod(findLoadedClassMethod, cl, className);
return loadedClass != null; return loadedClass != null;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2018 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.
@ -212,7 +212,7 @@ public class ClassUtilsTests {
assertNotNull(method); assertNotNull(method);
assertEquals("size", method.getName()); assertEquals("size", method.getName());
method = ClassUtils.getMethodIfAvailable(Collection.class, "remove", new Class[] {Object.class}); method = ClassUtils.getMethodIfAvailable(Collection.class, "remove", Object.class);
assertNotNull(method); assertNotNull(method);
assertEquals("remove", method.getName()); assertEquals("remove", method.getName());
@ -239,7 +239,7 @@ public class ClassUtilsTests {
@Test @Test
public void testNoArgsStaticMethod() throws IllegalAccessException, InvocationTargetException { public void testNoArgsStaticMethod() throws IllegalAccessException, InvocationTargetException {
Method method = ClassUtils.getStaticMethod(InnerClass.class, "staticMethod", (Class[]) null); Method method = ClassUtils.getStaticMethod(InnerClass.class, "staticMethod");
method.invoke(null, (Object[]) null); method.invoke(null, (Object[]) null);
assertTrue("no argument method was not invoked.", assertTrue("no argument method was not invoked.",
InnerClass.noArgCalled); InnerClass.noArgCalled);
@ -247,19 +247,16 @@ public class ClassUtilsTests {
@Test @Test
public void testArgsStaticMethod() throws IllegalAccessException, InvocationTargetException { public void testArgsStaticMethod() throws IllegalAccessException, InvocationTargetException {
Method method = ClassUtils.getStaticMethod(InnerClass.class, "argStaticMethod", Method method = ClassUtils.getStaticMethod(InnerClass.class, "argStaticMethod", String.class);
new Class[] {String.class}); method.invoke(null, "test");
method.invoke(null, new Object[] {"test"});
assertTrue("argument method was not invoked.", InnerClass.argCalled); assertTrue("argument method was not invoked.", InnerClass.argCalled);
} }
@Test @Test
public void testOverloadedStaticMethod() throws IllegalAccessException, InvocationTargetException { public void testOverloadedStaticMethod() throws IllegalAccessException, InvocationTargetException {
Method method = ClassUtils.getStaticMethod(InnerClass.class, "staticMethod", Method method = ClassUtils.getStaticMethod(InnerClass.class, "staticMethod", String.class);
new Class[] {String.class}); method.invoke(null, "test");
method.invoke(null, new Object[] {"test"}); assertTrue("argument method was not invoked.", InnerClass.overloadedCalled);
assertTrue("argument method was not invoked.",
InnerClass.overloadedCalled);
} }
@Test @Test

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -60,10 +60,10 @@ public class ObjectUtilsTests {
@Test @Test
public void isCompatibleWithThrowsClause() { public void isCompatibleWithThrowsClause() {
Class<?>[] empty = new Class[0]; Class<?>[] empty = new Class<?>[0];
Class<?>[] exception = new Class[] {Exception.class}; Class<?>[] exception = new Class<?>[] {Exception.class};
Class<?>[] sqlAndIO = new Class[] {SQLException.class, IOException.class}; Class<?>[] sqlAndIO = new Class<?>[] {SQLException.class, IOException.class};
Class<?>[] throwable = new Class[] {Throwable.class}; Class<?>[] throwable = new Class<?>[] {Throwable.class};
assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException())); assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException()));
assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException(), empty)); assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException(), empty));

View File

@ -86,7 +86,7 @@ public class ReflectionUtilsTests {
TestObject bean = new TestObject(); TestObject bean = new TestObject();
bean.setName(rob); bean.setName(rob);
Method getName = TestObject.class.getMethod("getName", (Class[]) null); Method getName = TestObject.class.getMethod("getName");
Method setName = TestObject.class.getMethod("setName", String.class); Method setName = TestObject.class.getMethod("setName", String.class);
Object name = ReflectionUtils.invokeMethod(getName, bean); Object name = ReflectionUtils.invokeMethod(getName, bean);

View File

@ -103,7 +103,7 @@ public class IndexingTests {
@Override @Override
public Class<?>[] getSpecificTargetClasses() { public Class<?>[] getSpecificTargetClasses() {
return new Class[] { Map.class }; return new Class<?>[] {Map.class};
} }
} }

View File

@ -190,7 +190,7 @@ public class PropertyAccessTests extends AbstractExpressionTests {
@Override @Override
public Class<?>[] getSpecificTargetClasses() { public Class<?>[] getSpecificTargetClasses() {
return new Class[] {String.class}; return new Class<?>[] {String.class};
} }
@Override @Override

View File

@ -4957,7 +4957,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
private Method method; private Method method;
public Class<?>[] getSpecificTargetClasses() { public Class<?>[] getSpecificTargetClasses() {
return new Class[] {Payload2.class}; return new Class<?>[] {Payload2.class};
} }
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException { public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
@ -5043,7 +5043,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@Override @Override
public Class<?>[] getSpecificTargetClasses() { public Class<?>[] getSpecificTargetClasses() {
return new Class[] {Map.class}; return new Class<?>[] {Map.class};
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 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.
@ -438,9 +438,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
public void testFunctions() throws Exception { public void testFunctions() throws Exception {
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
context.registerFunction("reverseString", StringUtils.class.getDeclaredMethod("reverseString", String.class));
context.registerFunction("reverseString", StringUtils.class.getDeclaredMethod(
"reverseString", new Class[] { String.class }));
String helloWorldReversed = parser.parseExpression("#reverseString('hello world')").getValue(context, String.class); String helloWorldReversed = parser.parseExpression("#reverseString('hello world')").getValue(context, String.class);
assertEquals("dlrow olleh",helloWorldReversed); assertEquals("dlrow olleh",helloWorldReversed);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -117,10 +117,10 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
StandardTypeConverter tc = new StandardTypeConverter(); StandardTypeConverter tc = new StandardTypeConverter();
// Calling foo(String) with (String) is exact match // Calling foo(String) with (String) is exact match
checkMatch(new Class[] {String.class}, new Class[] {String.class}, tc, ReflectionHelper.ArgumentsMatchKind.EXACT); checkMatch(new Class<?>[] {String.class}, new Class<?>[] {String.class}, tc, ReflectionHelper.ArgumentsMatchKind.EXACT);
// Calling foo(String,Integer) with (String,Integer) is exact match // Calling foo(String,Integer) with (String,Integer) is exact match
checkMatch(new Class[] {String.class, Integer.class}, new Class[] {String.class, Integer.class}, tc, ArgumentsMatchKind.EXACT); checkMatch(new Class<?>[] {String.class, Integer.class}, new Class<?>[] {String.class, Integer.class}, tc, ArgumentsMatchKind.EXACT);
} }
@Test @Test
@ -128,13 +128,13 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
StandardTypeConverter tc = new StandardTypeConverter(); StandardTypeConverter tc = new StandardTypeConverter();
// Calling foo(List) with (ArrayList) is close match (no conversion required) // Calling foo(List) with (ArrayList) is close match (no conversion required)
checkMatch(new Class[] {ArrayList.class}, new Class[] {List.class}, tc, ArgumentsMatchKind.CLOSE); checkMatch(new Class<?>[] {ArrayList.class}, new Class<?>[] {List.class}, tc, ArgumentsMatchKind.CLOSE);
// Passing (Sub,String) on call to foo(Super,String) is close match // Passing (Sub,String) on call to foo(Super,String) is close match
checkMatch(new Class[] {Sub.class, String.class}, new Class[] {Super.class, String.class}, tc, ArgumentsMatchKind.CLOSE); checkMatch(new Class<?>[] {Sub.class, String.class}, new Class<?>[] {Super.class, String.class}, tc, ArgumentsMatchKind.CLOSE);
// Passing (String,Sub) on call to foo(String,Super) is close match // Passing (String,Sub) on call to foo(String,Super) is close match
checkMatch(new Class[] {String.class, Sub.class}, new Class[] {String.class, Super.class}, tc, ArgumentsMatchKind.CLOSE); checkMatch(new Class<?>[] {String.class, Sub.class}, new Class<?>[] {String.class, Super.class}, tc, ArgumentsMatchKind.CLOSE);
} }
@Test @Test
@ -142,16 +142,16 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
StandardTypeConverter tc = new StandardTypeConverter(); StandardTypeConverter tc = new StandardTypeConverter();
// Calling foo(String,int) with (String,Integer) requires boxing conversion of argument one // Calling foo(String,int) with (String,Integer) requires boxing conversion of argument one
checkMatch(new Class[] {String.class, Integer.TYPE}, new Class[] {String.class,Integer.class},tc, ArgumentsMatchKind.CLOSE); checkMatch(new Class<?>[] {String.class, Integer.TYPE}, new Class<?>[] {String.class,Integer.class},tc, ArgumentsMatchKind.CLOSE);
// Passing (int,String) on call to foo(Integer,String) requires boxing conversion of argument zero // Passing (int,String) on call to foo(Integer,String) requires boxing conversion of argument zero
checkMatch(new Class[] {Integer.TYPE, String.class}, new Class[] {Integer.class, String.class},tc, ArgumentsMatchKind.CLOSE); checkMatch(new Class<?>[] {Integer.TYPE, String.class}, new Class<?>[] {Integer.class, String.class},tc, ArgumentsMatchKind.CLOSE);
// Passing (int,Sub) on call to foo(Integer,Super) requires boxing conversion of argument zero // Passing (int,Sub) on call to foo(Integer,Super) requires boxing conversion of argument zero
checkMatch(new Class[] {Integer.TYPE, Sub.class}, new Class[] {Integer.class, Super.class}, tc, ArgumentsMatchKind.CLOSE); checkMatch(new Class<?>[] {Integer.TYPE, Sub.class}, new Class<?>[] {Integer.class, Super.class}, tc, ArgumentsMatchKind.CLOSE);
// Passing (int,Sub,boolean) on call to foo(Integer,Super,Boolean) requires boxing conversion of arguments zero and two // Passing (int,Sub,boolean) on call to foo(Integer,Super,Boolean) requires boxing conversion of arguments zero and two
// TODO checkMatch(new Class[] {Integer.TYPE, Sub.class, Boolean.TYPE}, new Class[] {Integer.class, Super.class, Boolean.class}, tc, ArgsMatchKind.REQUIRES_CONVERSION); // TODO checkMatch(new Class<?>[] {Integer.TYPE, Sub.class, Boolean.TYPE}, new Class<?>[] {Integer.class, Super.class, Boolean.class}, tc, ArgsMatchKind.REQUIRES_CONVERSION);
} }
@Test @Test
@ -159,7 +159,7 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
StandardTypeConverter typeConverter = new StandardTypeConverter(); StandardTypeConverter typeConverter = new StandardTypeConverter();
// Passing (Super,String) on call to foo(Sub,String) is not a match // Passing (Super,String) on call to foo(Sub,String) is not a match
checkMatch(new Class[] {Super.class,String.class}, new Class[] {Sub.class,String.class},typeConverter,null); checkMatch(new Class<?>[] {Super.class,String.class}, new Class<?>[] {Sub.class,String.class},typeConverter,null);
} }
@Test @Test
@ -169,49 +169,49 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
Class<?> integerArrayClass = new Integer[0].getClass(); Class<?> integerArrayClass = new Integer[0].getClass();
// Passing (String[]) on call to (String[]) is exact match // Passing (String[]) on call to (String[]) is exact match
checkMatch2(new Class[] {stringArrayClass}, new Class[] {stringArrayClass}, tc, ArgumentsMatchKind.EXACT); checkMatch2(new Class<?>[] {stringArrayClass}, new Class<?>[] {stringArrayClass}, tc, ArgumentsMatchKind.EXACT);
// Passing (Integer, String[]) on call to (Integer, String[]) is exact match // Passing (Integer, String[]) on call to (Integer, String[]) is exact match
checkMatch2(new Class[] {Integer.class, stringArrayClass}, new Class[] {Integer.class, stringArrayClass}, tc, ArgumentsMatchKind.EXACT); checkMatch2(new Class<?>[] {Integer.class, stringArrayClass}, new Class<?>[] {Integer.class, stringArrayClass}, tc, ArgumentsMatchKind.EXACT);
// Passing (String, Integer, String[]) on call to (String, String, String[]) is exact match // Passing (String, Integer, String[]) on call to (String, String, String[]) is exact match
checkMatch2(new Class[] {String.class, Integer.class, stringArrayClass}, new Class[] {String.class,Integer.class, stringArrayClass}, tc, ArgumentsMatchKind.EXACT); checkMatch2(new Class<?>[] {String.class, Integer.class, stringArrayClass}, new Class<?>[] {String.class,Integer.class, stringArrayClass}, tc, ArgumentsMatchKind.EXACT);
// Passing (Sub, String[]) on call to (Super, String[]) is exact match // Passing (Sub, String[]) on call to (Super, String[]) is exact match
checkMatch2(new Class[] {Sub.class, stringArrayClass}, new Class[] {Super.class,stringArrayClass}, tc, ArgumentsMatchKind.CLOSE); checkMatch2(new Class<?>[] {Sub.class, stringArrayClass}, new Class<?>[] {Super.class,stringArrayClass}, tc, ArgumentsMatchKind.CLOSE);
// Passing (Integer, String[]) on call to (String, String[]) is exact match // Passing (Integer, String[]) on call to (String, String[]) is exact match
checkMatch2(new Class[] {Integer.class, stringArrayClass}, new Class[] {String.class, stringArrayClass}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION); checkMatch2(new Class<?>[] {Integer.class, stringArrayClass}, new Class<?>[] {String.class, stringArrayClass}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);
// Passing (Integer, Sub, String[]) on call to (String, Super, String[]) is exact match // Passing (Integer, Sub, String[]) on call to (String, Super, String[]) is exact match
checkMatch2(new Class[] {Integer.class, Sub.class, String[].class}, new Class[] {String.class,Super .class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION); checkMatch2(new Class<?>[] {Integer.class, Sub.class, String[].class}, new Class<?>[] {String.class,Super .class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);
// Passing (String) on call to (String[]) is exact match // Passing (String) on call to (String[]) is exact match
checkMatch2(new Class[] {String.class}, new Class[] {stringArrayClass}, tc, ArgumentsMatchKind.EXACT); checkMatch2(new Class<?>[] {String.class}, new Class<?>[] {stringArrayClass}, tc, ArgumentsMatchKind.EXACT);
// Passing (Integer,String) on call to (Integer,String[]) is exact match // Passing (Integer,String) on call to (Integer,String[]) is exact match
checkMatch2(new Class[] {Integer.class, String.class}, new Class[] {Integer.class, stringArrayClass}, tc, ArgumentsMatchKind.EXACT); checkMatch2(new Class<?>[] {Integer.class, String.class}, new Class<?>[] {Integer.class, stringArrayClass}, tc, ArgumentsMatchKind.EXACT);
// Passing (String) on call to (Integer[]) is conversion match (String to Integer) // Passing (String) on call to (Integer[]) is conversion match (String to Integer)
checkMatch2(new Class[] {String.class}, new Class[] {integerArrayClass}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION); checkMatch2(new Class<?>[] {String.class}, new Class<?>[] {integerArrayClass}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);
// Passing (Sub) on call to (Super[]) is close match // Passing (Sub) on call to (Super[]) is close match
checkMatch2(new Class[] {Sub.class}, new Class[] {new Super[0].getClass()}, tc, ArgumentsMatchKind.CLOSE); checkMatch2(new Class<?>[] {Sub.class}, new Class<?>[] {new Super[0].getClass()}, tc, ArgumentsMatchKind.CLOSE);
// Passing (Super) on call to (Sub[]) is not a match // Passing (Super) on call to (Sub[]) is not a match
checkMatch2(new Class[] {Super.class}, new Class[] {new Sub[0].getClass()}, tc, null); checkMatch2(new Class<?>[] {Super.class}, new Class<?>[] {new Sub[0].getClass()}, tc, null);
checkMatch2(new Class[] {Unconvertable.class, String.class}, new Class[] {Sub.class, Super[].class}, tc, null); checkMatch2(new Class<?>[] {Unconvertable.class, String.class}, new Class<?>[] {Sub.class, Super[].class}, tc, null);
checkMatch2(new Class[] {Integer.class, Integer.class, String.class}, new Class[] {String.class, String.class, Super[].class}, tc, null); checkMatch2(new Class<?>[] {Integer.class, Integer.class, String.class}, new Class<?>[] {String.class, String.class, Super[].class}, tc, null);
checkMatch2(new Class[] {Unconvertable.class, String.class}, new Class[] {Sub.class, Super[].class}, tc, null); checkMatch2(new Class<?>[] {Unconvertable.class, String.class}, new Class<?>[] {Sub.class, Super[].class}, tc, null);
checkMatch2(new Class[] {Integer.class, Integer.class, String.class}, new Class[] {String.class, String.class, Super[].class}, tc, null); checkMatch2(new Class<?>[] {Integer.class, Integer.class, String.class}, new Class<?>[] {String.class, String.class, Super[].class}, tc, null);
checkMatch2(new Class[] {Integer.class, Integer.class, Sub.class}, new Class[] {String.class, String.class, Super[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION); checkMatch2(new Class<?>[] {Integer.class, Integer.class, Sub.class}, new Class<?>[] {String.class, String.class, Super[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);
checkMatch2(new Class[] {Integer.class, Integer.class, Integer.class}, new Class[] {Integer.class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION); checkMatch2(new Class<?>[] {Integer.class, Integer.class, Integer.class}, new Class<?>[] {Integer.class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);
// what happens on (Integer,String) passed to (Integer[]) ? // what happens on (Integer,String) passed to (Integer[]) ?
} }
@ -271,7 +271,8 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
@Test @Test
public void testSetupArguments() { public void testSetupArguments() {
Object[] newArray = ReflectionHelper.setupArgumentsForVarargsInvocation(new Class[] {new String[0].getClass()},"a","b","c"); Object[] newArray = ReflectionHelper.setupArgumentsForVarargsInvocation(
new Class<?>[] {new String[0].getClass()},"a","b","c");
assertEquals(1, newArray.length); assertEquals(1, newArray.length);
Object firstParam = newArray[0]; Object firstParam = newArray[0];

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -45,7 +45,7 @@ public class TableMetaDataProviderFactory {
*/ */
public static TableMetaDataProvider createMetaDataProvider(DataSource dataSource, TableMetaDataContext context) { public static TableMetaDataProvider createMetaDataProvider(DataSource dataSource, TableMetaDataContext context) {
try { try {
TableMetaDataProvider result = (TableMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, databaseMetaData -> { return (TableMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, databaseMetaData -> {
String databaseProductName = String databaseProductName =
JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName()); JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName());
boolean accessTableColumnMetaData = context.isAccessTableColumnMetaData(); boolean accessTableColumnMetaData = context.isAccessTableColumnMetaData();
@ -71,12 +71,11 @@ public class TableMetaDataProviderFactory {
} }
provider.initializeWithMetaData(databaseMetaData); provider.initializeWithMetaData(databaseMetaData);
if (accessTableColumnMetaData) { if (accessTableColumnMetaData) {
provider.initializeWithTableColumnMetaData(databaseMetaData, context.getCatalogName(), provider.initializeWithTableColumnMetaData(databaseMetaData,
context.getSchemaName(), context.getTableName()); context.getCatalogName(), context.getSchemaName(), context.getTableName());
} }
return provider; return provider;
}); });
return result;
} }
catch (MetaDataAccessException ex) { catch (MetaDataAccessException ex) {
throw new DataAccessResourceFailureException("Error retrieving database metadata", ex); throw new DataAccessResourceFailureException("Error retrieving database metadata", ex);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -95,7 +95,7 @@ public class WebSphereDataSourceAdapter extends IsolationLevelDataSourceAdapter
this.wsDataSourceClass = getClass().getClassLoader().loadClass("com.ibm.websphere.rsadapter.WSDataSource"); this.wsDataSourceClass = getClass().getClassLoader().loadClass("com.ibm.websphere.rsadapter.WSDataSource");
Class<?> jdbcConnSpecClass = getClass().getClassLoader().loadClass("com.ibm.websphere.rsadapter.JDBCConnectionSpec"); Class<?> jdbcConnSpecClass = getClass().getClassLoader().loadClass("com.ibm.websphere.rsadapter.JDBCConnectionSpec");
Class<?> wsrraFactoryClass = getClass().getClassLoader().loadClass("com.ibm.websphere.rsadapter.WSRRAFactory"); Class<?> wsrraFactoryClass = getClass().getClassLoader().loadClass("com.ibm.websphere.rsadapter.WSRRAFactory");
this.newJdbcConnSpecMethod = wsrraFactoryClass.getMethod("createJDBCConnectionSpec", (Class<?>[]) null); this.newJdbcConnSpecMethod = wsrraFactoryClass.getMethod("createJDBCConnectionSpec");
this.wsDataSourceGetConnectionMethod = this.wsDataSourceGetConnectionMethod =
this.wsDataSourceClass.getMethod("getConnection", jdbcConnSpecClass); this.wsDataSourceClass.getMethod("getConnection", jdbcConnSpecClass);
this.setTransactionIsolationMethod = this.setTransactionIsolationMethod =

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -17,7 +17,6 @@
package org.springframework.jdbc.support; package org.springframework.jdbc.support;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Blob; import java.sql.Blob;
import java.sql.Clob; import java.sql.Clob;
@ -356,8 +355,7 @@ public abstract class JdbcUtils {
return (T) extractDatabaseMetaData(dataSource, return (T) extractDatabaseMetaData(dataSource,
dbmd -> { dbmd -> {
try { try {
Method method = DatabaseMetaData.class.getMethod(metaDataMethodName, (Class[]) null); return DatabaseMetaData.class.getMethod(metaDataMethodName).invoke(dbmd);
return method.invoke(dbmd, (Object[]) null);
} }
catch (NoSuchMethodException ex) { catch (NoSuchMethodException ex) {
throw new MetaDataAccessException("No method named '" + metaDataMethodName + throw new MetaDataAccessException("No method named '" + metaDataMethodName +

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2018 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.
@ -38,180 +38,183 @@ import static org.mockito.BDDMockito.*;
*/ */
public class ResultSetWrappingRowSetTests { public class ResultSetWrappingRowSetTests {
private ResultSet rset; private ResultSet resultSet;
private ResultSetWrappingSqlRowSet rowset;
private ResultSetWrappingSqlRowSet rowSet;
@Before @Before
public void setUp() throws Exception { public void setup() throws Exception {
rset = mock(ResultSet.class); resultSet = mock(ResultSet.class);
rowset = new ResultSetWrappingSqlRowSet(rset); rowSet = new ResultSetWrappingSqlRowSet(resultSet);
} }
@Test @Test
public void testGetBigDecimalInt() throws Exception { public void testGetBigDecimalInt() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", new Class[] {int.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", int.class);
doTest(rset, rowset, 1, BigDecimal.ONE); doTest(rset, rowset, 1, BigDecimal.ONE);
} }
@Test @Test
public void testGetBigDecimalString() throws Exception { public void testGetBigDecimalString() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", new Class[] {String.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", String.class);
doTest(rset, rowset, "test", BigDecimal.ONE); doTest(rset, rowset, "test", BigDecimal.ONE);
} }
@Test @Test
public void testGetStringInt() throws Exception { public void testGetStringInt() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getString", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getString", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", new Class[] {int.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", int.class);
doTest(rset, rowset, 1, "test"); doTest(rset, rowset, 1, "test");
} }
@Test @Test
public void testGetStringString() throws Exception { public void testGetStringString() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getString", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getString", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", new Class[] {String.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", String.class);
doTest(rset, rowset, "test", "test"); doTest(rset, rowset, "test", "test");
} }
@Test @Test
public void testGetTimestampInt() throws Exception { public void testGetTimestampInt() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", new Class[] {int.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", int.class);
doTest(rset, rowset, 1, new Timestamp(1234l)); doTest(rset, rowset, 1, new Timestamp(1234l));
} }
@Test @Test
public void testGetTimestampString() throws Exception { public void testGetTimestampString() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", new Class[] {String.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", String.class);
doTest(rset, rowset, "test", new Timestamp(1234l)); doTest(rset, rowset, "test", new Timestamp(1234l));
} }
@Test @Test
public void testGetDateInt() throws Exception { public void testGetDateInt() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getDate", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getDate", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", new Class[] {int.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", int.class);
doTest(rset, rowset, 1, new Date(1234l)); doTest(rset, rowset, 1, new Date(1234l));
} }
@Test @Test
public void testGetDateString() throws Exception { public void testGetDateString() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getDate", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getDate", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", new Class[] {String.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", String.class);
doTest(rset, rowset, "test", new Date(1234l)); doTest(rset, rowset, "test", new Date(1234l));
} }
@Test @Test
public void testGetTimeInt() throws Exception { public void testGetTimeInt() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getTime", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getTime", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", new Class[] {int.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", int.class);
doTest(rset, rowset, 1, new Time(1234l)); doTest(rset, rowset, 1, new Time(1234l));
} }
@Test @Test
public void testGetTimeString() throws Exception { public void testGetTimeString() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getTime", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getTime", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", new Class[] {String.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", String.class);
doTest(rset, rowset, "test", new Time(1234l)); doTest(rset, rowset, "test", new Time(1234l));
} }
@Test @Test
public void testGetObjectInt() throws Exception { public void testGetObjectInt() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getObject", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getObject", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", new Class[] {int.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", int.class);
doTest(rset, rowset, 1, new Object()); doTest(rset, rowset, 1, new Object());
} }
@Test @Test
public void testGetObjectString() throws Exception { public void testGetObjectString() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getObject", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getObject", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", new Class[] {String.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", String.class);
doTest(rset, rowset, "test", new Object()); doTest(rset, rowset, "test", new Object());
} }
@Test @Test
public void testGetIntInt() throws Exception { public void testGetIntInt() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getInt", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getInt", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", new Class[] {int.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", int.class);
doTest(rset, rowset, 1, 1); doTest(rset, rowset, 1, 1);
} }
@Test @Test
public void testGetIntString() throws Exception { public void testGetIntString() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getInt", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getInt", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", new Class[] {String.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", String.class);
doTest(rset, rowset, "test", 1); doTest(rset, rowset, "test", 1);
} }
@Test @Test
public void testGetFloatInt() throws Exception { public void testGetFloatInt() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getFloat", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getFloat", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", new Class[] {int.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", int.class);
doTest(rset, rowset, 1, 1.0f); doTest(rset, rowset, 1, 1.0f);
} }
@Test @Test
public void testGetFloatString() throws Exception { public void testGetFloatString() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getFloat", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getFloat", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", new Class[] {String.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", String.class);
doTest(rset, rowset, "test", 1.0f); doTest(rset, rowset, "test", 1.0f);
} }
@Test @Test
public void testGetDoubleInt() throws Exception { public void testGetDoubleInt() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getDouble", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getDouble", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", new Class[] {int.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", int.class);
doTest(rset, rowset, 1, 1.0d); doTest(rset, rowset, 1, 1.0d);
} }
@Test @Test
public void testGetDoubleString() throws Exception { public void testGetDoubleString() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getDouble", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getDouble", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", new Class[] {String.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", String.class);
doTest(rset, rowset, "test", 1.0d); doTest(rset, rowset, "test", 1.0d);
} }
@Test @Test
public void testGetLongInt() throws Exception { public void testGetLongInt() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getLong", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getLong", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", new Class[] {int.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", int.class);
doTest(rset, rowset, 1, 1L); doTest(rset, rowset, 1, 1L);
} }
@Test @Test
public void testGetLongString() throws Exception { public void testGetLongString() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getLong", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getLong", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", new Class[] {String.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", String.class);
doTest(rset, rowset, "test", 1L); doTest(rset, rowset, "test", 1L);
} }
@Test @Test
public void testGetBooleanInt() throws Exception { public void testGetBooleanInt() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getBoolean", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getBoolean", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", new Class[] {int.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", int.class);
doTest(rset, rowset, 1, true); doTest(rset, rowset, 1, true);
} }
@Test @Test
public void testGetBooleanString() throws Exception { public void testGetBooleanString() throws Exception {
Method rset = ResultSet.class.getDeclaredMethod("getBoolean", new Class[] {int.class}); Method rset = ResultSet.class.getDeclaredMethod("getBoolean", int.class);
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", new Class[] {String.class}); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", String.class);
doTest(rset, rowset, "test", true); doTest(rset, rowset, "test", true);
} }
private void doTest(Method rsetMethod, Method rowsetMethod, Object arg, Object ret) throws Exception { private void doTest(Method rsetMethod, Method rowsetMethod, Object arg, Object ret) throws Exception {
if (arg instanceof String) { if (arg instanceof String) {
given(rset.findColumn((String) arg)).willReturn(1); given(resultSet.findColumn((String) arg)).willReturn(1);
given(rsetMethod.invoke(rset, 1)).willReturn(ret).willThrow(new SQLException("test")); given(rsetMethod.invoke(resultSet, 1)).willReturn(ret).willThrow(new SQLException("test"));
} }
else { else {
given(rsetMethod.invoke(rset, arg)).willReturn(ret).willThrow(new SQLException("test")); given(rsetMethod.invoke(resultSet, arg)).willReturn(ret).willThrow(new SQLException("test"));
} }
rowsetMethod.invoke(rowset, arg); rowsetMethod.invoke(rowSet, arg);
try { try {
rowsetMethod.invoke(rowset, arg); rowsetMethod.invoke(rowSet, arg);
fail("InvalidResultSetAccessException should have been thrown"); fail("InvalidResultSetAccessException should have been thrown");
} }
catch (InvocationTargetException ex) { catch (InvocationTargetException ex) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -60,7 +60,7 @@ public class HeaderMethodArgumentResolverTests {
@Before @Before
public void setup() throws Exception { public void setup() {
@SuppressWarnings("resource") @SuppressWarnings("resource")
GenericApplicationContext cxt = new GenericApplicationContext(); GenericApplicationContext cxt = new GenericApplicationContext();
cxt.refresh(); cxt.refresh();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 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.
@ -164,7 +164,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
@Test @Test
public void testPublicExtendedPersistenceContextSetterWithSerialization() throws Exception { public void testPublicExtendedPersistenceContextSetterWithSerialization() throws Exception {
DummyInvocationHandler ih = new DummyInvocationHandler(); DummyInvocationHandler ih = new DummyInvocationHandler();
Object mockEm = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {EntityManager.class}, ih); Object mockEm = Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] {EntityManager.class}, ih);
given(mockEmf.createEntityManager()).willReturn((EntityManager) mockEm); given(mockEmf.createEntityManager()).willReturn((EntityManager) mockEm);
GenericApplicationContext gac = new GenericApplicationContext(); GenericApplicationContext gac = new GenericApplicationContext();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -87,7 +87,7 @@ public class CastorUnmarshallerTests extends AbstractUnmarshallerTests<CastorMar
@Test @Test
public void unmarshalTargetClass() throws Exception { public void unmarshalTargetClass() throws Exception {
CastorMarshaller unmarshaller = new CastorMarshaller(); CastorMarshaller unmarshaller = new CastorMarshaller();
unmarshaller.setTargetClasses(new Class[] {Flights.class}); unmarshaller.setTargetClasses(Flights.class);
unmarshaller.afterPropertiesSet(); unmarshaller.afterPropertiesSet();
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8"))); StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
Object flights = unmarshaller.unmarshal(source); Object flights = unmarshaller.unmarshal(source);
@ -98,7 +98,7 @@ public class CastorUnmarshallerTests extends AbstractUnmarshallerTests<CastorMar
public void setBothTargetClassesAndMapping() throws IOException { public void setBothTargetClassesAndMapping() throws IOException {
CastorMarshaller unmarshaller = new CastorMarshaller(); CastorMarshaller unmarshaller = new CastorMarshaller();
unmarshaller.setMappingLocation(new ClassPathResource("order-mapping.xml", CastorMarshaller.class)); unmarshaller.setMappingLocation(new ClassPathResource("order-mapping.xml", CastorMarshaller.class));
unmarshaller.setTargetClasses(new Class[] {Order.class}); unmarshaller.setTargetClasses(Order.class);
unmarshaller.afterPropertiesSet(); unmarshaller.afterPropertiesSet();
String xml = "<order>" + String xml = "<order>" +

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -202,7 +202,7 @@ public class XStreamMarshallerTests {
@Test @Test
public void useAttributesFor() throws Exception { public void useAttributesFor() throws Exception {
marshaller.setUseAttributeForTypes(new Class[]{Long.TYPE}); marshaller.setUseAttributeForTypes(Long.TYPE);
Writer writer = new StringWriter(); Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer)); marshaller.marshal(flight, new StreamResult(writer));
String expected = "<flight flightNumber=\"42\" />"; String expected = "<flight flightNumber=\"42\" />";

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -74,8 +74,7 @@ import static org.springframework.test.context.junit4.JUnitTestingUtils.*;
*/ */
public class SpringJUnit4ConcurrencyTests { public class SpringJUnit4ConcurrencyTests {
// @formatter:off private final Class<?>[] testClasses = new Class<?>[] {
private final Class<?>[] testClasses = new Class[] {
// Basics // Basics
SpringJUnit4ClassRunnerAppCtxTests.class, SpringJUnit4ClassRunnerAppCtxTests.class,
InheritedConfigSpringJUnit4ClassRunnerAppCtxTests.class, InheritedConfigSpringJUnit4ClassRunnerAppCtxTests.class,
@ -94,7 +93,7 @@ public class SpringJUnit4ConcurrencyTests {
WebAppResourceTests.class, WebAppResourceTests.class,
SampleTests.class SampleTests.class
}; };
// @formatter:on
@BeforeClass @BeforeClass
public static void abortIfLongRunningTestGroupIsNotEnabled() { public static void abortIfLongRunningTestGroupIsNotEnabled() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 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.
@ -57,8 +57,8 @@ public class DelegatingSmartContextLoaderTests {
@Test @Test
public void processContextConfigurationWithDefaultXmlConfigGeneration() { public void processContextConfigurationWithDefaultXmlConfigGeneration() {
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(XmlTestCase.class, ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); XmlTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
loader.processContextConfiguration(configAttributes); loader.processContextConfiguration(configAttributes);
assertEquals(1, configAttributes.getLocations().length); assertEquals(1, configAttributes.getLocations().length);
assertEmpty(configAttributes.getClasses()); assertEmpty(configAttributes.getClasses());
@ -66,8 +66,8 @@ public class DelegatingSmartContextLoaderTests {
@Test @Test
public void processContextConfigurationWithDefaultConfigurationClassGeneration() { public void processContextConfigurationWithDefaultConfigurationClassGeneration() {
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(ConfigClassTestCase.class, ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); ConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
loader.processContextConfiguration(configAttributes); loader.processContextConfiguration(configAttributes);
assertEquals(1, configAttributes.getClasses().length); assertEquals(1, configAttributes.getClasses().length);
assertEmpty(configAttributes.getLocations()); assertEmpty(configAttributes.getLocations());
@ -79,16 +79,16 @@ public class DelegatingSmartContextLoaderTests {
expectedException.expectMessage(containsString("both default locations AND default configuration classes were detected")); expectedException.expectMessage(containsString("both default locations AND default configuration classes were detected"));
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
ImproperDuplicateDefaultXmlAndConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, ImproperDuplicateDefaultXmlAndConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY,
true, ContextLoader.class); true, null, true, ContextLoader.class);
loader.processContextConfiguration(configAttributes); loader.processContextConfiguration(configAttributes);
} }
@Test @Test
public void processContextConfigurationWithLocation() { public void processContextConfigurationWithLocation() {
String[] locations = new String[] { "classpath:/foo.xml" }; String[] locations = new String[] {"classpath:/foo.xml"};
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(getClass(), locations, ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); getClass(), locations, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
loader.processContextConfiguration(configAttributes); loader.processContextConfiguration(configAttributes);
assertArrayEquals(locations, configAttributes.getLocations()); assertArrayEquals(locations, configAttributes.getLocations());
assertEmpty(configAttributes.getClasses()); assertEmpty(configAttributes.getClasses());
@ -96,9 +96,9 @@ public class DelegatingSmartContextLoaderTests {
@Test @Test
public void processContextConfigurationWithConfigurationClass() { public void processContextConfigurationWithConfigurationClass() {
Class<?>[] classes = new Class<?>[] { getClass() }; Class<?>[] classes = new Class<?>[] {getClass()};
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(getClass(), ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
EMPTY_STRING_ARRAY, classes, true, null, true, ContextLoader.class); getClass(), EMPTY_STRING_ARRAY, classes, true, null, true, ContextLoader.class);
loader.processContextConfiguration(configAttributes); loader.processContextConfiguration(configAttributes);
assertArrayEquals(classes, configAttributes.getClasses()); assertArrayEquals(classes, configAttributes.getClasses());
assertEmpty(configAttributes.getLocations()); assertEmpty(configAttributes.getLocations());
@ -118,8 +118,8 @@ public class DelegatingSmartContextLoaderTests {
expectedException.expectMessage(startsWith("Neither")); expectedException.expectMessage(startsWith("Neither"));
expectedException.expectMessage(containsString("was able to load an ApplicationContext from")); expectedException.expectMessage(containsString("was able to load an ApplicationContext from"));
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, MergedContextConfiguration mergedConfig = new MergedContextConfiguration(
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
loader.loadContext(mergedConfig); loader.loadContext(mergedConfig);
} }
@ -133,12 +133,13 @@ public class DelegatingSmartContextLoaderTests {
expectedException.expectMessage(endsWith("declare either 'locations' or 'classes' but not both.")); expectedException.expectMessage(endsWith("declare either 'locations' or 'classes' but not both."));
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(),
new String[] { "test.xml" }, new Class[] { getClass() }, EMPTY_STRING_ARRAY, loader); new String[] {"test.xml"}, new Class<?>[] {getClass()}, EMPTY_STRING_ARRAY, loader);
loader.loadContext(mergedConfig); loader.loadContext(mergedConfig);
} }
private void assertApplicationContextLoadsAndContainsFooString(MergedContextConfiguration mergedConfig) private void assertApplicationContextLoadsAndContainsFooString(MergedContextConfiguration mergedConfig)
throws Exception { throws Exception {
ApplicationContext applicationContext = loader.loadContext(mergedConfig); ApplicationContext applicationContext = loader.loadContext(mergedConfig);
assertNotNull(applicationContext); assertNotNull(applicationContext);
assertEquals("foo", applicationContext.getBean(String.class)); assertEquals("foo", applicationContext.getBean(String.class));
@ -150,7 +151,7 @@ public class DelegatingSmartContextLoaderTests {
public void loadContextWithXmlConfig() throws Exception { public void loadContextWithXmlConfig() throws Exception {
MergedContextConfiguration mergedConfig = new MergedContextConfiguration( MergedContextConfiguration mergedConfig = new MergedContextConfiguration(
XmlTestCase.class, XmlTestCase.class,
new String[] { "classpath:/org/springframework/test/context/support/DelegatingSmartContextLoaderTests$XmlTestCase-context.xml" }, new String[] {"classpath:/org/springframework/test/context/support/DelegatingSmartContextLoaderTests$XmlTestCase-context.xml"},
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
assertApplicationContextLoadsAndContainsFooString(mergedConfig); assertApplicationContextLoadsAndContainsFooString(mergedConfig);
} }
@ -158,7 +159,7 @@ public class DelegatingSmartContextLoaderTests {
@Test @Test
public void loadContextWithConfigurationClass() throws Exception { public void loadContextWithConfigurationClass() throws Exception {
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(ConfigClassTestCase.class, MergedContextConfiguration mergedConfig = new MergedContextConfiguration(ConfigClassTestCase.class,
EMPTY_STRING_ARRAY, new Class<?>[] { ConfigClassTestCase.Config.class }, EMPTY_STRING_ARRAY, loader); EMPTY_STRING_ARRAY, new Class<?>[] {ConfigClassTestCase.Config.class}, EMPTY_STRING_ARRAY, loader);
assertApplicationContextLoadsAndContainsFooString(mergedConfig); assertApplicationContextLoadsAndContainsFooString(mergedConfig);
} }
@ -192,7 +193,6 @@ public class DelegatingSmartContextLoaderTests {
} }
static class NotAConfigClass { static class NotAConfigClass {
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -44,19 +44,21 @@ import static org.springframework.test.util.MetaAnnotationUtils.*;
*/ */
public class MetaAnnotationUtilsTests { public class MetaAnnotationUtilsTests {
private void assertAtComponentOnComposedAnnotation(Class<?> rootDeclaringClass, String name, private void assertAtComponentOnComposedAnnotation(
Class<? extends Annotation> composedAnnotationType) { Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, name, composedAnnotationType); assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, name, composedAnnotationType);
} }
private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass, String name, private void assertAtComponentOnComposedAnnotation(
Class<? extends Annotation> composedAnnotationType) { Class<?> startClass, Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, composedAnnotationType, name,
composedAnnotationType); assertAtComponentOnComposedAnnotation(startClass, rootDeclaringClass, composedAnnotationType, name, composedAnnotationType);
} }
private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass, private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass,
Class<?> declaringClass, String name, Class<? extends Annotation> composedAnnotationType) { Class<?> declaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(startClass, Component.class); AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(startClass, Component.class);
assertNotNull("AnnotationDescriptor should not be null", descriptor); assertNotNull("AnnotationDescriptor should not be null", descriptor);
assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass()); assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass());
@ -67,25 +69,29 @@ public class MetaAnnotationUtilsTests {
assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType()); assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType());
} }
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass, String name, private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
Class<? extends Annotation> composedAnnotationType) { Class<?> startClass, String name, Class<? extends Annotation> composedAnnotationType) {
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, name,
composedAnnotationType); assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
startClass, startClass, name, composedAnnotationType);
} }
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass, private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass,
Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) { Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, rootDeclaringClass,
composedAnnotationType, name, composedAnnotationType); assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
startClass, rootDeclaringClass, composedAnnotationType, name, composedAnnotationType);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass, private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass,
Class<?> rootDeclaringClass, Class<?> declaringClass, String name, Class<?> rootDeclaringClass, Class<?> declaringClass, String name,
Class<? extends Annotation> composedAnnotationType) { Class<? extends Annotation> composedAnnotationType) {
Class<Component> annotationType = Component.class; Class<Component> annotationType = Component.class;
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class, UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
annotationType, Order.class, Transactional.class); startClass, Service.class, annotationType, Order.class, Transactional.class);
assertNotNull("UntypedAnnotationDescriptor should not be null", descriptor); assertNotNull("UntypedAnnotationDescriptor should not be null", descriptor);
assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass()); assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass());
assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass()); assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass());
@ -96,13 +102,13 @@ public class MetaAnnotationUtilsTests {
} }
@Test @Test
public void findAnnotationDescriptorWithNoAnnotationPresent() throws Exception { public void findAnnotationDescriptorWithNoAnnotationPresent() {
assertNull(findAnnotationDescriptor(NonAnnotatedInterface.class, Transactional.class)); assertNull(findAnnotationDescriptor(NonAnnotatedInterface.class, Transactional.class));
assertNull(findAnnotationDescriptor(NonAnnotatedClass.class, Transactional.class)); assertNull(findAnnotationDescriptor(NonAnnotatedClass.class, Transactional.class));
} }
@Test @Test
public void findAnnotationDescriptorWithInheritedAnnotationOnClass() throws Exception { public void findAnnotationDescriptorWithInheritedAnnotationOnClass() {
// Note: @Transactional is inherited // Note: @Transactional is inherited
assertEquals(InheritedAnnotationClass.class, assertEquals(InheritedAnnotationClass.class,
findAnnotationDescriptor(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); findAnnotationDescriptor(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass());
@ -111,13 +117,12 @@ public class MetaAnnotationUtilsTests {
} }
@Test @Test
public void findAnnotationDescriptorWithInheritedAnnotationOnInterface() throws Exception { public void findAnnotationDescriptorWithInheritedAnnotationOnInterface() {
// Note: @Transactional is inherited // Note: @Transactional is inherited
Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class); Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class);
AnnotationDescriptor<Transactional> descriptor; AnnotationDescriptor<Transactional> descriptor =
findAnnotationDescriptor(InheritedAnnotationInterface.class, Transactional.class);
descriptor = findAnnotationDescriptor(InheritedAnnotationInterface.class, Transactional.class);
assertNotNull(descriptor); assertNotNull(descriptor);
assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass()); assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass());
@ -137,7 +142,7 @@ public class MetaAnnotationUtilsTests {
} }
@Test @Test
public void findAnnotationDescriptorForNonInheritedAnnotationOnClass() throws Exception { public void findAnnotationDescriptorForNonInheritedAnnotationOnClass() {
// Note: @Order is not inherited. // Note: @Order is not inherited.
assertEquals(NonInheritedAnnotationClass.class, assertEquals(NonInheritedAnnotationClass.class,
findAnnotationDescriptor(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); findAnnotationDescriptor(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass());
@ -146,13 +151,12 @@ public class MetaAnnotationUtilsTests {
} }
@Test @Test
public void findAnnotationDescriptorForNonInheritedAnnotationOnInterface() throws Exception { public void findAnnotationDescriptorForNonInheritedAnnotationOnInterface() {
// Note: @Order is not inherited. // Note: @Order is not inherited.
Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class); Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class);
AnnotationDescriptor<Order> descriptor; AnnotationDescriptor<Order> descriptor =
findAnnotationDescriptor(NonInheritedAnnotationInterface.class, Order.class);
descriptor = findAnnotationDescriptor(NonInheritedAnnotationInterface.class, Order.class);
assertNotNull(descriptor); assertNotNull(descriptor);
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass()); assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass());
@ -166,15 +170,16 @@ public class MetaAnnotationUtilsTests {
} }
@Test @Test
public void findAnnotationDescriptorWithMetaComponentAnnotation() throws Exception { public void findAnnotationDescriptorWithMetaComponentAnnotation() {
assertAtComponentOnComposedAnnotation(HasMetaComponentAnnotation.class, "meta1", Meta1.class); assertAtComponentOnComposedAnnotation(HasMetaComponentAnnotation.class, "meta1", Meta1.class);
} }
@Test @Test
public void findAnnotationDescriptorWithLocalAndMetaComponentAnnotation() throws Exception { public void findAnnotationDescriptorWithLocalAndMetaComponentAnnotation() {
Class<Component> annotationType = Component.class; Class<Component> annotationType = Component.class;
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(HasLocalAndMetaComponentAnnotation.class, AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(
annotationType); HasLocalAndMetaComponentAnnotation.class, annotationType);
assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass()); assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass());
assertEquals(annotationType, descriptor.getAnnotationType()); assertEquals(annotationType, descriptor.getAnnotationType());
assertNull(descriptor.getComposedAnnotation()); assertNull(descriptor.getComposedAnnotation());
@ -188,12 +193,10 @@ public class MetaAnnotationUtilsTests {
@Test @Test
public void findAnnotationDescriptorForClassWithMetaAnnotatedInterface() { public void findAnnotationDescriptorForClassWithMetaAnnotatedInterface() {
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class);
Component.class); AnnotationDescriptor<Component> descriptor =
findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class);
AnnotationDescriptor<Component> descriptor;
descriptor = findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class);
assertNotNull(descriptor); assertNotNull(descriptor);
assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass()); assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass());
assertEquals(Meta1.class, descriptor.getDeclaringClass()); assertEquals(Meta1.class, descriptor.getDeclaringClass());
@ -213,14 +216,13 @@ public class MetaAnnotationUtilsTests {
assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation()); assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation());
assertEquals("composedAnnotationType", MetaConfig.class, descriptor.getComposedAnnotationType()); assertEquals("composedAnnotationType", MetaConfig.class, descriptor.getComposedAnnotationType());
assertArrayEquals("configured classes", new Class[] { String.class }, assertArrayEquals("configured classes", new Class<?>[] {String.class},
descriptor.getAnnotationAttributes().getClassArray("classes")); descriptor.getAnnotationAttributes().getClassArray("classes"));
} }
@Test @Test
public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() {
assertAtComponentOnComposedAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", assertAtComponentOnComposedAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class);
Meta2.class);
} }
@Test @Test
@ -253,8 +255,8 @@ public class MetaAnnotationUtilsTests {
@Test @Test
public void findAnnotationDescriptorOnAnnotatedClassWithMissingTargetMetaAnnotation() { public void findAnnotationDescriptorOnAnnotatedClassWithMissingTargetMetaAnnotation() {
// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component // InheritedAnnotationClass is NOT annotated or meta-annotated with @Component
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(InheritedAnnotationClass.class, AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(
Component.class); InheritedAnnotationClass.class, Component.class);
assertNull("Should not find @Component on InheritedAnnotationClass", descriptor); assertNull("Should not find @Component on InheritedAnnotationClass", descriptor);
} }
@ -263,8 +265,8 @@ public class MetaAnnotationUtilsTests {
*/ */
@Test @Test
public void findAnnotationDescriptorOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { public void findAnnotationDescriptorOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(MetaCycleAnnotatedClass.class, AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(
Component.class); MetaCycleAnnotatedClass.class, Component.class);
assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor); assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor);
} }
@ -272,17 +274,16 @@ public class MetaAnnotationUtilsTests {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithNoAnnotationPresent() throws Exception { public void findAnnotationDescriptorForTypesWithNoAnnotationPresent() {
assertNull(findAnnotationDescriptorForTypes(NonAnnotatedInterface.class, Transactional.class, Component.class)); assertNull(findAnnotationDescriptorForTypes(NonAnnotatedInterface.class, Transactional.class, Component.class));
assertNull(findAnnotationDescriptorForTypes(NonAnnotatedClass.class, Transactional.class, Order.class)); assertNull(findAnnotationDescriptorForTypes(NonAnnotatedClass.class, Transactional.class, Order.class));
} }
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnClass() throws Exception { public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnClass() {
// Note: @Transactional is inherited // Note: @Transactional is inherited
assertEquals( assertEquals(InheritedAnnotationClass.class,
InheritedAnnotationClass.class,
findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass());
assertEquals( assertEquals(
InheritedAnnotationClass.class, InheritedAnnotationClass.class,
@ -291,13 +292,12 @@ public class MetaAnnotationUtilsTests {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface() throws Exception { public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface() {
// Note: @Transactional is inherited // Note: @Transactional is inherited
Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class); Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class);
UntypedAnnotationDescriptor descriptor; UntypedAnnotationDescriptor descriptor =
findAnnotationDescriptorForTypes(InheritedAnnotationInterface.class, Transactional.class);
descriptor = findAnnotationDescriptorForTypes(InheritedAnnotationInterface.class, Transactional.class);
assertNotNull(descriptor); assertNotNull(descriptor);
assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass()); assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass());
@ -318,7 +318,7 @@ public class MetaAnnotationUtilsTests {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnClass() throws Exception { public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnClass() {
// Note: @Order is not inherited. // Note: @Order is not inherited.
assertEquals(NonInheritedAnnotationClass.class, assertEquals(NonInheritedAnnotationClass.class,
findAnnotationDescriptorForTypes(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); findAnnotationDescriptorForTypes(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass());
@ -328,13 +328,12 @@ public class MetaAnnotationUtilsTests {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface() throws Exception { public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface() {
// Note: @Order is not inherited. // Note: @Order is not inherited.
Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class); Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class);
UntypedAnnotationDescriptor descriptor; UntypedAnnotationDescriptor descriptor =
findAnnotationDescriptorForTypes(NonInheritedAnnotationInterface.class, Order.class);
descriptor = findAnnotationDescriptorForTypes(NonInheritedAnnotationInterface.class, Order.class);
assertNotNull(descriptor); assertNotNull(descriptor);
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass()); assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass());
@ -349,7 +348,7 @@ public class MetaAnnotationUtilsTests {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() throws Exception { public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() {
Class<Component> annotationType = Component.class; Class<Component> annotationType = Component.class;
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
HasLocalAndMetaComponentAnnotation.class, Transactional.class, annotationType, Order.class); HasLocalAndMetaComponentAnnotation.class, Transactional.class, annotationType, Order.class);
@ -360,25 +359,25 @@ public class MetaAnnotationUtilsTests {
} }
@Test @Test
public void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() throws Exception { public void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() {
Class<HasMetaComponentAnnotation> startClass = HasMetaComponentAnnotation.class; Class<HasMetaComponentAnnotation> startClass = HasMetaComponentAnnotation.class;
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, "meta1", Meta1.class); assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, "meta1", Meta1.class);
} }
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() throws Exception { public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() {
Class<?> startClass = MetaConfigWithDefaultAttributesTestCase.class; Class<?> startClass = MetaConfigWithDefaultAttributesTestCase.class;
Class<ContextConfiguration> annotationType = ContextConfiguration.class; Class<ContextConfiguration> annotationType = ContextConfiguration.class;
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class, UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass,
ContextConfiguration.class, Order.class, Transactional.class); Service.class, ContextConfiguration.class, Order.class, Transactional.class);
assertNotNull(descriptor); assertNotNull(descriptor);
assertEquals(startClass, descriptor.getRootDeclaringClass()); assertEquals(startClass, descriptor.getRootDeclaringClass());
assertEquals(annotationType, descriptor.getAnnotationType()); assertEquals(annotationType, descriptor.getAnnotationType());
assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value()); assertArrayEquals(new Class<?>[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value());
assertArrayEquals(new Class[] { MetaConfig.DevConfig.class, MetaConfig.ProductionConfig.class }, assertArrayEquals(new Class<?>[] {MetaConfig.DevConfig.class, MetaConfig.ProductionConfig.class},
descriptor.getAnnotationAttributes().getClassArray("classes")); descriptor.getAnnotationAttributes().getClassArray("classes"));
assertNotNull(descriptor.getComposedAnnotation()); assertNotNull(descriptor.getComposedAnnotation());
assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType()); assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType());
@ -386,18 +385,18 @@ public class MetaAnnotationUtilsTests {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() throws Exception { public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() {
Class<?> startClass = MetaConfigWithOverriddenAttributesTestCase.class; Class<?> startClass = MetaConfigWithOverriddenAttributesTestCase.class;
Class<ContextConfiguration> annotationType = ContextConfiguration.class; Class<ContextConfiguration> annotationType = ContextConfiguration.class;
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class, UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
ContextConfiguration.class, Order.class, Transactional.class); startClass, Service.class, ContextConfiguration.class, Order.class, Transactional.class);
assertNotNull(descriptor); assertNotNull(descriptor);
assertEquals(startClass, descriptor.getRootDeclaringClass()); assertEquals(startClass, descriptor.getRootDeclaringClass());
assertEquals(annotationType, descriptor.getAnnotationType()); assertEquals(annotationType, descriptor.getAnnotationType());
assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value()); assertArrayEquals(new Class<?>[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value());
assertArrayEquals(new Class[] { MetaAnnotationUtilsTests.class }, assertArrayEquals(new Class<?>[] {MetaAnnotationUtilsTests.class},
descriptor.getAnnotationAttributes().getClassArray("classes")); descriptor.getAnnotationAttributes().getClassArray("classes"));
assertNotNull(descriptor.getComposedAnnotation()); assertNotNull(descriptor.getComposedAnnotation());
assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType()); assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType());
@ -412,13 +411,11 @@ public class MetaAnnotationUtilsTests {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() { public void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() {
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class);
Component.class);
UntypedAnnotationDescriptor descriptor; UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
ClassWithMetaAnnotatedInterface.class, Service.class, Component.class, Order.class, Transactional.class);
descriptor = findAnnotationDescriptorForTypes(ClassWithMetaAnnotatedInterface.class, Service.class,
Component.class, Order.class, Transactional.class);
assertNotNull(descriptor); assertNotNull(descriptor);
assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass()); assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass());
assertEquals(Meta1.class, descriptor.getDeclaringClass()); assertEquals(Meta1.class, descriptor.getDeclaringClass());
@ -445,8 +442,8 @@ public class MetaAnnotationUtilsTests {
@Test @Test
public void findAnnotationDescriptorForTypesOnMetaMetaAnnotatedClass() { public void findAnnotationDescriptorForTypesOnMetaMetaAnnotatedClass() {
Class<MetaMetaAnnotatedClass> startClass = MetaMetaAnnotatedClass.class; Class<MetaMetaAnnotatedClass> startClass = MetaMetaAnnotatedClass.class;
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, Meta2.class, "meta2", assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
MetaMeta.class); startClass, startClass, Meta2.class, "meta2", MetaMeta.class);
} }
/** /**
@ -455,8 +452,8 @@ public class MetaAnnotationUtilsTests {
@Test @Test
public void findAnnotationDescriptorForTypesOnMetaMetaMetaAnnotatedClass() { public void findAnnotationDescriptorForTypesOnMetaMetaMetaAnnotatedClass() {
Class<MetaMetaMetaAnnotatedClass> startClass = MetaMetaMetaAnnotatedClass.class; Class<MetaMetaMetaAnnotatedClass> startClass = MetaMetaMetaAnnotatedClass.class;
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, Meta2.class, "meta2", assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
MetaMetaMeta.class); startClass, startClass, Meta2.class, "meta2", MetaMetaMeta.class);
} }
/** /**
@ -467,8 +464,8 @@ public class MetaAnnotationUtilsTests {
public void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() { public void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() {
// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component, // InheritedAnnotationClass is NOT annotated or meta-annotated with @Component,
// @Service, or @Order, but it is annotated with @Transactional. // @Service, or @Order, but it is annotated with @Transactional.
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
Service.class, Component.class, Order.class); InheritedAnnotationClass.class, Service.class, Component.class, Order.class);
assertNull("Should not find @Component on InheritedAnnotationClass", descriptor); assertNull("Should not find @Component on InheritedAnnotationClass", descriptor);
} }
@ -478,8 +475,8 @@ public class MetaAnnotationUtilsTests {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { public void findAnnotationDescriptorForTypesOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(MetaCycleAnnotatedClass.class, UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
Service.class, Component.class, Order.class); MetaCycleAnnotatedClass.class, Service.class, Component.class, Order.class);
assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor); assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2018 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.
@ -46,20 +46,21 @@ public class TxNamespaceHandlerTests {
@Before @Before
public void setUp() throws Exception { public void setup() throws Exception {
this.context = new ClassPathXmlApplicationContext("txNamespaceHandlerTests.xml", getClass()); this.context = new ClassPathXmlApplicationContext("txNamespaceHandlerTests.xml", getClass());
this.getAgeMethod = ITestBean.class.getMethod("getAge", new Class[0]); this.getAgeMethod = ITestBean.class.getMethod("getAge");
this.setAgeMethod = ITestBean.class.getMethod("setAge", new Class[] {int.class}); this.setAgeMethod = ITestBean.class.getMethod("setAge", int.class);
} }
@Test @Test
public void isProxy() throws Exception { public void isProxy() {
ITestBean bean = getTestBean(); ITestBean bean = getTestBean();
assertTrue("testBean is not a proxy", AopUtils.isAopProxy(bean)); assertTrue("testBean is not a proxy", AopUtils.isAopProxy(bean));
} }
@Test @Test
public void invokeTransactional() throws Exception { public void invokeTransactional() {
ITestBean testBean = getTestBean(); ITestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager"); CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
@ -97,7 +98,7 @@ public class TxNamespaceHandlerTests {
} }
private ITestBean getTestBean() { private ITestBean getTestBean() {
return (ITestBean)context.getBean("testBean"); return (ITestBean) context.getBean("testBean");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2018 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,6 +18,7 @@ package org.springframework.transaction.interceptor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.dao.OptimisticLockingFailureException; import org.springframework.dao.OptimisticLockingFailureException;
@ -57,16 +58,11 @@ public abstract class AbstractTransactionAspectTests {
protected Method setNameMethod; protected Method setNameMethod;
public AbstractTransactionAspectTests() { @Before
try { public void setup() throws Exception {
// Cache the methods we'll be testing exceptionalMethod = ITestBean.class.getMethod("exceptional", Throwable.class);
exceptionalMethod = ITestBean.class.getMethod("exceptional", new Class[] { Throwable.class }); getNameMethod = ITestBean.class.getMethod("getName");
getNameMethod = ITestBean.class.getMethod("getName", (Class[]) null); setNameMethod = ITestBean.class.getMethod("setName", String.class);
setNameMethod = ITestBean.class.getMethod("setName", new Class[] { String.class} );
}
catch (NoSuchMethodException ex) {
throw new RuntimeException("Shouldn't happen", ex);
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2018 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.
@ -43,7 +43,7 @@ public class TransactionAttributeSourceEditorTests {
editor.setAsText(null); editor.setAsText(null);
TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue(); TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue();
Method m = Object.class.getMethod("hashCode", (Class[]) null); Method m = Object.class.getMethod("hashCode");
assertNull(tas.getTransactionAttribute(m, null)); assertNull(tas.getTransactionAttribute(m, null));
} }
@ -62,21 +62,21 @@ public class TransactionAttributeSourceEditorTests {
"java.lang.Object.not*=PROPAGATION_REQUIRED"); "java.lang.Object.not*=PROPAGATION_REQUIRED");
TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue(); TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue();
checkTransactionProperties(tas, Object.class.getMethod("hashCode", (Class[]) null), checkTransactionProperties(tas, Object.class.getMethod("hashCode"),
TransactionDefinition.PROPAGATION_REQUIRED); TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("equals", new Class[] { Object.class }), checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class),
TransactionDefinition.PROPAGATION_MANDATORY); TransactionDefinition.PROPAGATION_MANDATORY);
checkTransactionProperties(tas, Object.class.getMethod("wait", (Class[]) null), checkTransactionProperties(tas, Object.class.getMethod("wait"),
TransactionDefinition.PROPAGATION_SUPPORTS); TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("wait", new Class[] { long.class }), checkTransactionProperties(tas, Object.class.getMethod("wait", long.class),
TransactionDefinition.PROPAGATION_SUPPORTS); TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("wait", new Class[] { long.class, int.class }), checkTransactionProperties(tas, Object.class.getMethod("wait", long.class, int.class),
TransactionDefinition.PROPAGATION_SUPPORTS); TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("notify", (Class[]) null), checkTransactionProperties(tas, Object.class.getMethod("notify"),
TransactionDefinition.PROPAGATION_SUPPORTS); TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("notifyAll", (Class[]) null), checkTransactionProperties(tas, Object.class.getMethod("notifyAll"),
TransactionDefinition.PROPAGATION_REQUIRED); TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("toString", (Class[]) null), -1); checkTransactionProperties(tas, Object.class.getMethod("toString"), -1);
} }
@Test @Test
@ -84,21 +84,21 @@ public class TransactionAttributeSourceEditorTests {
editor.setAsText("java.lang.Object.*=PROPAGATION_REQUIRED"); editor.setAsText("java.lang.Object.*=PROPAGATION_REQUIRED");
TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue(); TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue();
checkTransactionProperties(tas, Object.class.getMethod("hashCode", (Class[]) null), checkTransactionProperties(tas, Object.class.getMethod("hashCode"),
TransactionDefinition.PROPAGATION_REQUIRED); TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("equals", new Class[] { Object.class }), checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class),
TransactionDefinition.PROPAGATION_REQUIRED); TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("wait", (Class[]) null), checkTransactionProperties(tas, Object.class.getMethod("wait"),
TransactionDefinition.PROPAGATION_REQUIRED); TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("wait", new Class[] { long.class }), checkTransactionProperties(tas, Object.class.getMethod("wait", long.class),
TransactionDefinition.PROPAGATION_REQUIRED); TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("wait", new Class[] { long.class, int.class }), checkTransactionProperties(tas, Object.class.getMethod("wait", long.class, int.class),
TransactionDefinition.PROPAGATION_REQUIRED); TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("notify", (Class[]) null), checkTransactionProperties(tas, Object.class.getMethod("notify"),
TransactionDefinition.PROPAGATION_REQUIRED); TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("notifyAll", (Class[]) null), checkTransactionProperties(tas, Object.class.getMethod("notifyAll"),
TransactionDefinition.PROPAGATION_REQUIRED); TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("toString", (Class[]) null), checkTransactionProperties(tas, Object.class.getMethod("toString"),
TransactionDefinition.PROPAGATION_REQUIRED); TransactionDefinition.PROPAGATION_REQUIRED);
} }

View File

@ -41,13 +41,13 @@ public class TransactionAttributeSourceTests {
public void matchAlwaysTransactionAttributeSource() throws Exception { public void matchAlwaysTransactionAttributeSource() throws Exception {
MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource(); MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource();
TransactionAttribute ta = tas.getTransactionAttribute( TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null); Object.class.getMethod("hashCode"), null);
assertNotNull(ta); assertNotNull(ta);
assertTrue(TransactionDefinition.PROPAGATION_REQUIRED == ta.getPropagationBehavior()); assertTrue(TransactionDefinition.PROPAGATION_REQUIRED == ta.getPropagationBehavior());
tas.setTransactionAttribute(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS)); tas.setTransactionAttribute(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS));
ta = tas.getTransactionAttribute( ta = tas.getTransactionAttribute(
IOException.class.getMethod("getMessage", (Class[]) null), IOException.class); IOException.class.getMethod("getMessage"), IOException.class);
assertNotNull(ta); assertNotNull(ta);
assertTrue(TransactionDefinition.PROPAGATION_SUPPORTS == ta.getPropagationBehavior()); assertTrue(TransactionDefinition.PROPAGATION_SUPPORTS == ta.getPropagationBehavior());
} }
@ -60,7 +60,7 @@ public class TransactionAttributeSourceTests {
attributes.put("*ashCode", "PROPAGATION_REQUIRED"); attributes.put("*ashCode", "PROPAGATION_REQUIRED");
tas.setProperties(attributes); tas.setProperties(attributes);
TransactionAttribute ta = tas.getTransactionAttribute( TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null); Object.class.getMethod("hashCode"), null);
assertNotNull(ta); assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior()); assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior());
} }
@ -73,7 +73,7 @@ public class TransactionAttributeSourceTests {
attributes.put("hashCod*", "PROPAGATION_REQUIRED"); attributes.put("hashCod*", "PROPAGATION_REQUIRED");
tas.setProperties(attributes); tas.setProperties(attributes);
TransactionAttribute ta = tas.getTransactionAttribute( TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null); Object.class.getMethod("hashCode"), null);
assertNotNull(ta); assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior()); assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior());
} }
@ -87,7 +87,7 @@ public class TransactionAttributeSourceTests {
attributes.put("hashCode", "PROPAGATION_MANDATORY"); attributes.put("hashCode", "PROPAGATION_MANDATORY");
tas.setProperties(attributes); tas.setProperties(attributes);
TransactionAttribute ta = tas.getTransactionAttribute( TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null); Object.class.getMethod("hashCode"), null);
assertNotNull(ta); assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_MANDATORY, ta.getPropagationBehavior()); assertEquals(TransactionDefinition.PROPAGATION_MANDATORY, ta.getPropagationBehavior());
} }
@ -100,7 +100,7 @@ public class TransactionAttributeSourceTests {
attributes.put("", "PROPAGATION_MANDATORY"); attributes.put("", "PROPAGATION_MANDATORY");
tas.setProperties(attributes); tas.setProperties(attributes);
TransactionAttribute ta = tas.getTransactionAttribute( TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null); Object.class.getMethod("hashCode"), null);
assertNull(ta); assertNull(ta);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2018 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.
@ -47,6 +47,7 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests
@Rule @Rule
public final ExpectedException thrown = ExpectedException.none(); public final ExpectedException thrown = ExpectedException.none();
@Override @Override
protected Object advised(Object target, PlatformTransactionManager ptm, TransactionAttributeSource[] tas) throws Exception { protected Object advised(Object target, PlatformTransactionManager ptm, TransactionAttributeSource[] tas) throws Exception {
TransactionInterceptor ti = new TransactionInterceptor(); TransactionInterceptor ti = new TransactionInterceptor();
@ -76,6 +77,7 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests
return pf.getProxy(); return pf.getProxy();
} }
/** /**
* A TransactionInterceptor should be serializable if its * A TransactionInterceptor should be serializable if its
* PlatformTransactionManager is. * PlatformTransactionManager is.
@ -109,7 +111,7 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests
tas2.setProperties(props); tas2.setProperties(props);
TransactionInterceptor ti = new TransactionInterceptor(); TransactionInterceptor ti = new TransactionInterceptor();
ti.setTransactionAttributeSources(new TransactionAttributeSource[] {tas1, tas2}); ti.setTransactionAttributeSources(tas1, tas2);
PlatformTransactionManager ptm = new SerializableTransactionManager(); PlatformTransactionManager ptm = new SerializableTransactionManager();
ti.setTransactionManager(ptm); ti.setTransactionManager(ptm);
ti = (TransactionInterceptor) SerializationTestUtils.serializeAndDeserialize(ti); ti = (TransactionInterceptor) SerializationTestUtils.serializeAndDeserialize(ti);
@ -255,8 +257,10 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests
verify(beanFactory, times(1)).getBean(PlatformTransactionManager.class); verify(beanFactory, times(1)).getBean(PlatformTransactionManager.class);
} }
private TransactionInterceptor createTransactionInterceptor(BeanFactory beanFactory, private TransactionInterceptor createTransactionInterceptor(BeanFactory beanFactory,
String transactionManagerName, PlatformTransactionManager transactionManager) { String transactionManagerName, PlatformTransactionManager transactionManager) {
TransactionInterceptor ti = new TransactionInterceptor(); TransactionInterceptor ti = new TransactionInterceptor();
if (beanFactory != null) { if (beanFactory != null) {
ti.setBeanFactory(beanFactory); ti.setBeanFactory(beanFactory);
@ -317,6 +321,6 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests
public void rollback(TransactionStatus status) throws TransactionException { public void rollback(TransactionStatus status) throws TransactionException {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2018 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.
@ -80,7 +80,7 @@ public class SimpleMappingExceptionResolverTests {
@Test @Test
public void defaultErrorViewDifferentHandlerClass() { public void defaultErrorViewDifferentHandlerClass() {
exceptionResolver.setDefaultErrorView("default-view"); exceptionResolver.setDefaultErrorView("default-view");
exceptionResolver.setMappedHandlerClasses(new Class[] {String.class}); exceptionResolver.setMappedHandlerClasses(String.class);
ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException); ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException);
assertNull(mav); assertNull(mav);
} }
@ -161,7 +161,7 @@ public class SimpleMappingExceptionResolverTests {
public void exactExceptionMappingWithHandlerClassSpecified() { public void exactExceptionMappingWithHandlerClassSpecified() {
Properties props = new Properties(); Properties props = new Properties();
props.setProperty("java.lang.Exception", "error"); props.setProperty("java.lang.Exception", "error");
exceptionResolver.setMappedHandlerClasses(new Class[] {String.class}); exceptionResolver.setMappedHandlerClasses(String.class);
exceptionResolver.setExceptionMappings(props); exceptionResolver.setExceptionMappings(props);
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException); ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
assertEquals("error", mav.getViewName()); assertEquals("error", mav.getViewName());
@ -171,7 +171,7 @@ public class SimpleMappingExceptionResolverTests {
public void exactExceptionMappingWithHandlerInterfaceSpecified() { public void exactExceptionMappingWithHandlerInterfaceSpecified() {
Properties props = new Properties(); Properties props = new Properties();
props.setProperty("java.lang.Exception", "error"); props.setProperty("java.lang.Exception", "error");
exceptionResolver.setMappedHandlerClasses(new Class[] {Comparable.class}); exceptionResolver.setMappedHandlerClasses(Comparable.class);
exceptionResolver.setExceptionMappings(props); exceptionResolver.setExceptionMappings(props);
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException); ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
assertEquals("error", mav.getViewName()); assertEquals("error", mav.getViewName());
@ -191,7 +191,7 @@ public class SimpleMappingExceptionResolverTests {
public void simpleExceptionMappingWithHandlerClassSpecifiedButWrongHandler() { public void simpleExceptionMappingWithHandlerClassSpecifiedButWrongHandler() {
Properties props = new Properties(); Properties props = new Properties();
props.setProperty("Exception", "error"); props.setProperty("Exception", "error");
exceptionResolver.setMappedHandlerClasses(new Class[] {String.class}); exceptionResolver.setMappedHandlerClasses(String.class);
exceptionResolver.setExceptionMappings(props); exceptionResolver.setExceptionMappings(props);
ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException); ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException);
assertNull(mav); assertNull(mav);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2018 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,11 +16,9 @@
package org.springframework.web.servlet.mvc.method.annotation; package org.springframework.web.servlet.mvc.method.annotation;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.junit.Before; import org.junit.Before;
@ -44,6 +42,9 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.ControllerAdviceBean; import org.springframework.web.method.ControllerAdviceBean;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/** /**
* Unit tests for {@link RequestResponseBodyAdviceChain}. * Unit tests for {@link RequestResponseBodyAdviceChain}.
* *
@ -80,7 +81,6 @@ public class RequestResponseBodyAdviceChainTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void requestBodyAdvice() throws IOException { public void requestBodyAdvice() throws IOException {
RequestBodyAdvice requestAdvice = Mockito.mock(RequestBodyAdvice.class); RequestBodyAdvice requestAdvice = Mockito.mock(RequestBodyAdvice.class);
ResponseBodyAdvice<String> responseAdvice = Mockito.mock(ResponseBodyAdvice.class); ResponseBodyAdvice<String> responseAdvice = Mockito.mock(ResponseBodyAdvice.class);
List<Object> advice = Arrays.asList(requestAdvice, responseAdvice); List<Object> advice = Arrays.asList(requestAdvice, responseAdvice);
@ -104,7 +104,6 @@ public class RequestResponseBodyAdviceChainTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void responseBodyAdvice() { public void responseBodyAdvice() {
RequestBodyAdvice requestAdvice = Mockito.mock(RequestBodyAdvice.class); RequestBodyAdvice requestAdvice = Mockito.mock(RequestBodyAdvice.class);
ResponseBodyAdvice<String> responseAdvice = Mockito.mock(ResponseBodyAdvice.class); ResponseBodyAdvice<String> responseAdvice = Mockito.mock(ResponseBodyAdvice.class);
List<Object> advice = Arrays.asList(requestAdvice, responseAdvice); List<Object> advice = Arrays.asList(requestAdvice, responseAdvice);
@ -123,9 +122,8 @@ public class RequestResponseBodyAdviceChainTests {
@Test @Test
public void controllerAdvice() { public void controllerAdvice() {
Object adviceBean = new ControllerAdviceBean(new MyControllerAdvice()); Object adviceBean = new ControllerAdviceBean(new MyControllerAdvice());
RequestResponseBodyAdviceChain chain = new RequestResponseBodyAdviceChain(Arrays.asList(adviceBean)); RequestResponseBodyAdviceChain chain = new RequestResponseBodyAdviceChain(Collections.singletonList(adviceBean));
String actual = (String) chain.beforeBodyWrite(this.body, this.returnType, this.contentType, String actual = (String) chain.beforeBodyWrite(this.body, this.returnType, this.contentType,
this.converterType, this.request, this.response); this.converterType, this.request, this.response);
@ -135,9 +133,8 @@ public class RequestResponseBodyAdviceChainTests {
@Test @Test
public void controllerAdviceNotApplicable() { public void controllerAdviceNotApplicable() {
Object adviceBean = new ControllerAdviceBean(new TargetedControllerAdvice()); Object adviceBean = new ControllerAdviceBean(new TargetedControllerAdvice());
RequestResponseBodyAdviceChain chain = new RequestResponseBodyAdviceChain(Arrays.asList(adviceBean)); RequestResponseBodyAdviceChain chain = new RequestResponseBodyAdviceChain(Collections.singletonList(adviceBean));
String actual = (String) chain.beforeBodyWrite(this.body, this.returnType, this.contentType, String actual = (String) chain.beforeBodyWrite(this.body, this.returnType, this.contentType,
this.converterType, this.request, this.response); this.converterType, this.request, this.response);
@ -164,6 +161,7 @@ public class RequestResponseBodyAdviceChainTests {
} }
} }
@ControllerAdvice(annotations = Controller.class) @ControllerAdvice(annotations = Controller.class)
private static class TargetedControllerAdvice implements ResponseBodyAdvice<String> { private static class TargetedControllerAdvice implements ResponseBodyAdvice<String> {
@ -182,6 +180,7 @@ public class RequestResponseBodyAdviceChainTests {
} }
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ResponseBody @ResponseBody
public String handle(String body) { public String handle(String body) {

View File

@ -1089,7 +1089,7 @@ expression string.
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
context.registerFunction("reverseString", context.registerFunction("reverseString",
StringUtils.class.getDeclaredMethod("reverseString", new Class[] { String.class })); StringUtils.class.getDeclaredMethod("reverseString", String.class));
String helloWorldReversed = parser.parseExpression( String helloWorldReversed = parser.parseExpression(
"#reverseString('hello')").getValue(context, String.class); "#reverseString('hello')").getValue(context, String.class);

View File

@ -342,7 +342,7 @@ This is recommended for applications that use Java-based Spring configuration:
@Override @Override
protected Class<?>[] getServletConfigClasses() { protected Class<?>[] getServletConfigClasses() {
return new Class[] { MyWebConfig.class }; return new Class<?>[] { MyWebConfig.class };
} }
@Override @Override