diff --git a/spring-aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java b/spring-aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java index c4011acd6a9..0aa8ae54e59 100644 --- a/spring-aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ public class ConcurrencyThrottleInterceptorTests { public void testSerializable() throws Exception { DerivedTestBean tb = new DerivedTestBean(); ProxyFactory proxyFactory = new ProxyFactory(); - proxyFactory.setInterfaces(new Class[] {ITestBean.class}); + proxyFactory.setInterfaces(ITestBean.class); ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor(); proxyFactory.addAdvice(cti); proxyFactory.setTarget(tb); @@ -75,7 +75,7 @@ public class ConcurrencyThrottleInterceptorTests { private void testMultipleThreads(int concurrencyLimit) { TestBean tb = new TestBean(); ProxyFactory proxyFactory = new ProxyFactory(); - proxyFactory.setInterfaces(new Class[] {ITestBean.class}); + proxyFactory.setInterfaces(ITestBean.class); ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor(); cti.setConcurrencyLimit(concurrencyLimit); proxyFactory.addAdvice(cti); @@ -95,7 +95,7 @@ public class ConcurrencyThrottleInterceptorTests { ex.printStackTrace(); } threads[i] = new ConcurrencyThread(proxy, - i % 2 == 0 ? (Throwable) new OutOfMemoryError() : (Throwable) new IllegalStateException()); + i % 2 == 0 ? new OutOfMemoryError() : new IllegalStateException()); threads[i].start(); } for (int i = 0; i < NR_OF_THREADS; i++) { diff --git a/spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java b/spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java index c78a02c487d..56574025faf 100644 --- a/spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -83,7 +83,7 @@ public class CustomizableTraceInterceptorTests { public void testSunnyDayPathLogsCorrectly() throws Throwable { 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); Log log = mock(Log.class); @@ -101,7 +101,7 @@ public class CustomizableTraceInterceptorTests { MethodInvocation methodInvocation = mock(MethodInvocation.class); 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.proceed()).willThrow(exception); diff --git a/spring-aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java b/spring-aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java index 7504bee5ebe..3f01638a323 100644 --- a/spring-aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ public class SimpleTraceInterceptorTests { @Test public void testSunnyDayPathLogsCorrectly() throws Throwable { 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); Log log = mock(Log.class); @@ -48,7 +48,7 @@ public class SimpleTraceInterceptorTests { @Test public void testExceptionPathStillLogsCorrectly() throws Throwable { 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); IllegalArgumentException exception = new IllegalArgumentException(); given(mi.proceed()).willThrow(exception); diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java index bea3883b3fd..ce421c5a746 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -226,14 +226,14 @@ public class BeanUtilsTests { @Test 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"); assertNull(BeanUtils.resolveSignature("doSomethingElse()", MethodSignatureBean.class)); } @Test 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)"); } @@ -244,20 +244,20 @@ public class BeanUtilsTests { assertSignatureEquals(desiredMethod, "overloaded()"); // 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)"); // 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)"); } @Test 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[])"); - desiredMethod = MethodSignatureBean.class.getMethod("doSomethingWithAMultiDimensionalArray", new Class[]{String[][].class}); + desiredMethod = MethodSignatureBean.class.getMethod("doSomethingWithAMultiDimensionalArray", String[][].class); assertSignatureEquals(desiredMethod, "doSomethingWithAMultiDimensionalArray(java.lang.String[][])"); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java index de645447199..c1de073dc27 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -34,60 +34,54 @@ public class AutowireUtilsTests { @Test public void genericMethodReturnTypes() { - Method notParameterized = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterized", new Class[]{}); + Method notParameterized = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterized"); assertEquals(String.class, AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterized, new Object[]{}, getClass().getClassLoader())); - Method notParameterizedWithArguments = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterizedWithArguments", - new Class[] { Integer.class, Boolean.class }); + Method notParameterizedWithArguments = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterizedWithArguments", Integer.class, Boolean.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, - AutowireUtils.resolveReturnTypeForFactoryMethod(createProxy, new Object[] { "foo" }, getClass().getClassLoader())); + AutowireUtils.resolveReturnTypeForFactoryMethod(createProxy, new Object[] {"foo"}, getClass().getClassLoader())); - Method createNamedProxyWithDifferentTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy", - new Class[] { String.class, Object.class }); + Method createNamedProxyWithDifferentTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy", String.class, Object.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", - new Class[] { String.class, Object.class }); + Method createNamedProxyWithDuplicateTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy", String.class, Object.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, - AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] { Runnable.class }, getClass().getClassLoader())); + AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] {Runnable.class}, getClass().getClassLoader())); 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, - Class.class }); + Method createNamedMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedMock", String.class, Class.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", - new Class[] { Object.class, Class.class }); + Method createVMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createVMock", Object.class, Class.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 // resolveReturnTypeForFactoryMethod() does not currently support this form of // look-up. - Method extractValueFrom = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractValueFrom", - new Class[] { MyInterfaceType.class }); + Method extractValueFrom = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractValueFrom", MyInterfaceType.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 // information is not available at run-time due to type erasure. Map map = new HashMap<>(); map.put(0, false); map.put(1, true); - Method extractMagicValue = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractMagicValue", new Class[] { Map.class }); - assertEquals(Object.class, AutowireUtils.resolveReturnTypeForFactoryMethod(extractMagicValue, new Object[] { map }, getClass().getClassLoader())); + Method extractMagicValue = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractMagicValue", Map.class); + assertEquals(Object.class, AutowireUtils.resolveReturnTypeForFactoryMethod(extractMagicValue, new Object[] {map}, getClass().getClassLoader())); } diff --git a/spring-context/src/main/java/org/springframework/ejb/access/AbstractSlsbInvokerInterceptor.java b/spring-context/src/main/java/org/springframework/ejb/access/AbstractSlsbInvokerInterceptor.java index 9cee7dd3ad0..e62e74b0171 100644 --- a/spring-context/src/main/java/org/springframework/ejb/access/AbstractSlsbInvokerInterceptor.java +++ b/spring-context/src/main/java/org/springframework/ejb/access/AbstractSlsbInvokerInterceptor.java @@ -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"); * 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 { try { // 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) { throw new EjbAccessException("EJB home [" + home + "] has no no-arg create() method"); diff --git a/spring-core/src/test/java/org/springframework/core/ConventionsTests.java b/spring-core/src/test/java/org/springframework/core/ConventionsTests.java index 1496b7ba5cf..28263a8d0ab 100644 --- a/spring-core/src/test/java/org/springframework/core/ConventionsTests.java +++ b/spring-core/src/test/java/org/springframework/core/ConventionsTests.java @@ -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"); * 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.util.ClassUtils; -import static org.junit.Assert.assertEquals; - +import static org.junit.Assert.*; /** * Unit tests for {@link Conventions}. + * * @author Rob Harrop * @author Sam Brannen */ @@ -50,13 +50,10 @@ public class ConventionsTests { @Test public void simpleObject() { - assertEquals("Incorrect singular variable name", "testObject", Conventions.getVariableName(new TestObject())); - assertEquals("Incorrect singular variable name", "testObject", Conventions.getVariableNameForParameter(getMethodParameter(TestObject.class))); - assertEquals("Incorrect singular variable name", "testObject", Conventions.getVariableNameForReturnType(getMethodForReturnType(TestObject.class))); } @@ -69,13 +66,10 @@ public class ConventionsTests { @Test public void list() { - assertEquals("Incorrect plural List form", "testObjectList", Conventions.getVariableName(Collections.singletonList(new TestObject()))); - assertEquals("Incorrect plural List form", "testObjectList", Conventions.getVariableNameForParameter(getMethodParameter(List.class))); - assertEquals("Incorrect plural List form", "testObjectList", Conventions.getVariableNameForReturnType(getMethodForReturnType(List.class))); } @@ -88,58 +82,47 @@ public class ConventionsTests { @Test public void set() { - assertEquals("Incorrect plural Set form", "testObjectList", Conventions.getVariableName(Collections.singleton(new TestObject()))); - assertEquals("Incorrect plural Set form", "testObjectList", Conventions.getVariableNameForParameter(getMethodParameter(Set.class))); - assertEquals("Incorrect plural Set form", "testObjectList", Conventions.getVariableNameForReturnType(getMethodForReturnType(Set.class))); } @Test - public void reactiveParameters() throws Exception { - + public void reactiveParameters() { assertEquals("testObjectMono", Conventions.getVariableNameForParameter(getMethodParameter(Mono.class))); - assertEquals("testObjectFlux", Conventions.getVariableNameForParameter(getMethodParameter(Flux.class))); - assertEquals("testObjectSingle", Conventions.getVariableNameForParameter(getMethodParameter(Single.class))); - assertEquals("testObjectObservable", Conventions.getVariableNameForParameter(getMethodParameter(Observable.class))); } @Test - public void reactiveReturnTypes() throws Exception { - + public void reactiveReturnTypes() { assertEquals("testObjectMono", Conventions.getVariableNameForReturnType(getMethodForReturnType(Mono.class))); - assertEquals("testObjectFlux", Conventions.getVariableNameForReturnType(getMethodForReturnType(Flux.class))); - assertEquals("testObjectSingle", Conventions.getVariableNameForReturnType(getMethodForReturnType(Single.class))); - assertEquals("testObjectObservable", Conventions.getVariableNameForReturnType(getMethodForReturnType(Observable.class))); } @Test - public void attributeNameToPropertyName() throws Exception { + public void attributeNameToPropertyName() { assertEquals("transactionManager", Conventions.attributeNameToPropertyName("transaction-manager")); assertEquals("pointcutRef", Conventions.attributeNameToPropertyName("pointcut-ref")); assertEquals("lookupOnStartup", Conventions.attributeNameToPropertyName("lookup-on-startup")); } @Test - public void getQualifiedAttributeName() throws Exception { + public void getQualifiedAttributeName() { String baseName = "foo"; Class cls = String.class; String desiredResult = "java.lang.String.foo"; diff --git a/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java b/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java index 31090c94cec..9c17e3d9a8c 100644 --- a/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java +++ b/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ public class LocalVariableTableParameterNameDiscovererTests { @Test 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); assertNotNull("should find method info", names); assertEquals("no argument names", 0, names.length); @@ -47,7 +47,7 @@ public class LocalVariableTableParameterNameDiscovererTests { @Test 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); assertNotNull("should find method info", names); assertEquals("one argument", 1, names.length); @@ -56,7 +56,7 @@ public class LocalVariableTableParameterNameDiscovererTests { @Test public void consParameterNameDiscoveryNoArgs() throws NoSuchMethodException { - Constructor noArgsCons = TestObject.class.getConstructor(new Class[0]); + Constructor noArgsCons = TestObject.class.getConstructor(); String[] names = discoverer.getParameterNames(noArgsCons); assertNotNull("should find cons info", names); assertEquals("no argument names", 0, names.length); @@ -64,7 +64,7 @@ public class LocalVariableTableParameterNameDiscovererTests { @Test public void consParameterNameDiscoveryArgs() throws NoSuchMethodException { - Constructor twoArgCons = TestObject.class.getConstructor(new Class[] { String.class, int.class }); + Constructor twoArgCons = TestObject.class.getConstructor(String.class, int.class); String[] names = discoverer.getParameterNames(twoArgCons); assertNotNull("should find cons info", names); assertEquals("one argument", 2, names.length); @@ -74,7 +74,7 @@ public class LocalVariableTableParameterNameDiscovererTests { @Test public void staticMethodParameterNameDiscoveryNoArgs() throws NoSuchMethodException { - Method m = getClass().getMethod("staticMethodNoLocalVars", new Class[0]); + Method m = getClass().getMethod("staticMethodNoLocalVars"); String[] names = discoverer.getParameterNames(m); assertNotNull("should find method info", names); assertEquals("no argument names", 0, names.length); @@ -84,14 +84,14 @@ public class LocalVariableTableParameterNameDiscovererTests { public void overloadedStaticMethod() throws Exception { Class 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); assertNotNull("should find method info", names); assertEquals("two arguments", 2, names.length); assertEquals("x", names[0]); 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); assertNotNull("should find method info", names); assertEquals("three arguments", 3, names.length); @@ -104,13 +104,13 @@ public class LocalVariableTableParameterNameDiscovererTests { public void overloadedStaticMethodInInnerClass() throws Exception { Class clazz = InnerClass.class; - Method m1 = clazz.getMethod("staticMethod", new Class[] { Long.TYPE }); + Method m1 = clazz.getMethod("staticMethod", Long.TYPE); String[] names = discoverer.getParameterNames(m1); assertNotNull("should find method info", names); assertEquals("one argument", 1, names.length); 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); assertNotNull("should find method info", names); assertEquals("two arguments", 2, names.length); @@ -122,14 +122,14 @@ public class LocalVariableTableParameterNameDiscovererTests { public void overloadedMethod() throws Exception { Class 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); assertNotNull("should find method info", names); assertEquals("two arguments", 2, names.length); assertEquals("x", names[0]); 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); assertNotNull("should find method info", names); assertEquals("three arguments", 3, names.length); @@ -142,13 +142,13 @@ public class LocalVariableTableParameterNameDiscovererTests { public void overloadedMethodInInnerClass() throws Exception { Class clazz = InnerClass.class; - Method m1 = clazz.getMethod("instanceMethod", new Class[] { String.class }); + Method m1 = clazz.getMethod("instanceMethod", String.class); String[] names = discoverer.getParameterNames(m1); assertNotNull("should find method info", names); assertEquals("one argument", 1, names.length); 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); assertNotNull("should find method info", names); assertEquals("two arguments", 2, names.length); @@ -223,6 +223,7 @@ public class LocalVariableTableParameterNameDiscovererTests { assertNull(names); } + public static void staticMethodNoLocalVars() { } @@ -246,6 +247,7 @@ public class LocalVariableTableParameterNameDiscovererTests { return u; } + public static class InnerClass { public int waz = 0; @@ -278,7 +280,9 @@ public class LocalVariableTableParameterNameDiscovererTests { } } + public static class GenerifiedClass { + private static long date; static { @@ -317,4 +321,5 @@ public class LocalVariableTableParameterNameDiscovererTests { return date; } } + } diff --git a/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java b/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java index 52209456778..d2a1aa757dc 100644 --- a/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java +++ b/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java @@ -56,7 +56,7 @@ public class PrioritizedParameterNameDiscovererTests { private final Method anyMethod; public PrioritizedParameterNameDiscovererTests() throws SecurityException, NoSuchMethodException { - anyMethod = TestObject.class.getMethod("getAge", (Class[]) null); + anyMethod = TestObject.class.getMethod("getAge"); } @Test diff --git a/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java b/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java index 31f80520b75..b20ce3f8e76 100644 --- a/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java +++ b/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -309,30 +309,30 @@ public class AnnotationMetadataTests { AnnotationAttributes nestedAnno = specialAttrs.getAnnotation("nestedAnno"); assertThat("na", is(nestedAnno.getString("value"))); 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"); assertThat(nestedAnnoArray.length, is(2)); assertThat(nestedAnnoArray[0].getString("value"), is("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")); assertTrue(nestedAnnoArray[1].getEnum("anEnum").equals(SomeEnum.LABEL2)); - assertArrayEquals(new Class[] { Number.class }, (Class[]) nestedAnnoArray[1].get("classArray")); - assertArrayEquals(new Class[] { Number.class }, nestedAnnoArray[1].getClassArray("classArray")); + assertArrayEquals(new Class[] {Number.class}, (Class[]) nestedAnnoArray[1].get("classArray")); + assertArrayEquals(new Class[] {Number.class}, nestedAnnoArray[1].getClassArray("classArray")); AnnotationAttributes optional = specialAttrs.getAnnotation("optional"); assertThat(optional.getString("value"), is("optional")); assertTrue(optional.getEnum("anEnum").equals(SomeEnum.DEFAULT)); - assertArrayEquals(new Class[] { Void.class }, (Class[]) optional.get("classArray")); - assertArrayEquals(new Class[] { Void.class }, optional.getClassArray("classArray")); + assertArrayEquals(new Class[] {Void.class}, (Class[]) optional.get("classArray")); + assertArrayEquals(new Class[] {Void.class}, optional.getClassArray("classArray")); AnnotationAttributes[] optionalArray = specialAttrs.getAnnotationArray("optionalArray"); assertThat(optionalArray.length, is(1)); assertThat(optionalArray[0].getString("value"), is("optional")); assertTrue(optionalArray[0].getEnum("anEnum").equals(SomeEnum.DEFAULT)); - assertArrayEquals(new Class[] { Void.class }, (Class[]) optionalArray[0].get("classArray")); - assertArrayEquals(new Class[] { Void.class }, optionalArray[0].getClassArray("classArray")); + assertArrayEquals(new Class[] {Void.class}, (Class[]) optionalArray[0].get("classArray")); + assertArrayEquals(new Class[] {Void.class}, optionalArray[0].getClassArray("classArray")); assertEquals("direct", metadata.getAnnotationAttributes(DirectAnnotation.class.getName()).get("value")); allMeta = metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName()).get("value"); diff --git a/spring-core/src/test/java/org/springframework/core/type/ClassloadingAssertions.java b/spring-core/src/test/java/org/springframework/core/type/ClassloadingAssertions.java index 16a0e89662a..53dc87823dc 100644 --- a/spring-core/src/test/java/org/springframework/core/type/ClassloadingAssertions.java +++ b/spring-core/src/test/java/org/springframework/core/type/ClassloadingAssertions.java @@ -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"); * 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 * limitations under the License. */ + package org.springframework.core.type; import java.lang.reflect.Method; @@ -30,9 +31,9 @@ abstract class ClassloadingAssertions { private static boolean isClassLoaded(String className) { ClassLoader cl = ClassUtils.getDefaultClassLoader(); - Method findLoadeClassMethod = ReflectionUtils.findMethod(cl.getClass(), "findLoadedClass", new Class[] { String.class }); - ReflectionUtils.makeAccessible(findLoadeClassMethod); - Class loadedClass = (Class) ReflectionUtils.invokeMethod(findLoadeClassMethod, cl, new Object[] { className }); + Method findLoadedClassMethod = ReflectionUtils.findMethod(cl.getClass(), "findLoadedClass", String.class); + ReflectionUtils.makeAccessible(findLoadedClassMethod); + Class loadedClass = (Class) ReflectionUtils.invokeMethod(findLoadedClassMethod, cl, className); return loadedClass != null; } @@ -40,4 +41,4 @@ abstract class ClassloadingAssertions { assertFalse("Class [" + className + "] should not have been loaded", isClassLoaded(className)); } -} \ No newline at end of file +} diff --git a/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java b/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java index 32978f575a6..8786363c681 100644 --- a/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -212,7 +212,7 @@ public class ClassUtilsTests { assertNotNull(method); assertEquals("size", method.getName()); - method = ClassUtils.getMethodIfAvailable(Collection.class, "remove", new Class[] {Object.class}); + method = ClassUtils.getMethodIfAvailable(Collection.class, "remove", Object.class); assertNotNull(method); assertEquals("remove", method.getName()); @@ -239,7 +239,7 @@ public class ClassUtilsTests { @Test 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); assertTrue("no argument method was not invoked.", InnerClass.noArgCalled); @@ -247,19 +247,16 @@ public class ClassUtilsTests { @Test public void testArgsStaticMethod() throws IllegalAccessException, InvocationTargetException { - Method method = ClassUtils.getStaticMethod(InnerClass.class, "argStaticMethod", - new Class[] {String.class}); - method.invoke(null, new Object[] {"test"}); + Method method = ClassUtils.getStaticMethod(InnerClass.class, "argStaticMethod", String.class); + method.invoke(null, "test"); assertTrue("argument method was not invoked.", InnerClass.argCalled); } @Test public void testOverloadedStaticMethod() throws IllegalAccessException, InvocationTargetException { - Method method = ClassUtils.getStaticMethod(InnerClass.class, "staticMethod", - new Class[] {String.class}); - method.invoke(null, new Object[] {"test"}); - assertTrue("argument method was not invoked.", - InnerClass.overloadedCalled); + Method method = ClassUtils.getStaticMethod(InnerClass.class, "staticMethod", String.class); + method.invoke(null, "test"); + assertTrue("argument method was not invoked.", InnerClass.overloadedCalled); } @Test diff --git a/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java b/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java index 57af7b38b71..d11ea1f7880 100644 --- a/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -60,10 +60,10 @@ public class ObjectUtilsTests { @Test public void isCompatibleWithThrowsClause() { - Class[] empty = new Class[0]; - Class[] exception = new Class[] {Exception.class}; - Class[] sqlAndIO = new Class[] {SQLException.class, IOException.class}; - Class[] throwable = new Class[] {Throwable.class}; + Class[] empty = new Class[0]; + Class[] exception = new Class[] {Exception.class}; + Class[] sqlAndIO = new Class[] {SQLException.class, IOException.class}; + Class[] throwable = new Class[] {Throwable.class}; assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException())); assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException(), empty)); diff --git a/spring-core/src/test/java/org/springframework/util/ReflectionUtilsTests.java b/spring-core/src/test/java/org/springframework/util/ReflectionUtilsTests.java index af5efcbe10d..bc934b25460 100644 --- a/spring-core/src/test/java/org/springframework/util/ReflectionUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/ReflectionUtilsTests.java @@ -86,7 +86,7 @@ public class ReflectionUtilsTests { TestObject bean = new TestObject(); 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); Object name = ReflectionUtils.invokeMethod(getName, bean); diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/IndexingTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/IndexingTests.java index 961ca5aabca..15ed0091c24 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/IndexingTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/IndexingTests.java @@ -103,7 +103,7 @@ public class IndexingTests { @Override public Class[] getSpecificTargetClasses() { - return new Class[] { Map.class }; + return new Class[] {Map.class}; } } diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/PropertyAccessTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/PropertyAccessTests.java index f25bf974e03..8ded3b8db46 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/PropertyAccessTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/PropertyAccessTests.java @@ -190,7 +190,7 @@ public class PropertyAccessTests extends AbstractExpressionTests { @Override public Class[] getSpecificTargetClasses() { - return new Class[] {String.class}; + return new Class[] {String.class}; } @Override diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java index 6e0addf8397..f654dbedfb4 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java @@ -4957,7 +4957,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { private Method method; public Class[] getSpecificTargetClasses() { - return new Class[] {Payload2.class}; + return new Class[] {Payload2.class}; } public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException { @@ -5043,7 +5043,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { @Override public Class[] getSpecificTargetClasses() { - return new Class[] {Map.class}; + return new Class[] {Map.class}; } @Override diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SpelDocumentationTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SpelDocumentationTests.java index 2a4f7bcdfa1..ae62f21c919 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SpelDocumentationTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SpelDocumentationTests.java @@ -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"); * 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 { ExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext context = new StandardEvaluationContext(); - - context.registerFunction("reverseString", StringUtils.class.getDeclaredMethod( - "reverseString", new Class[] { String.class })); + context.registerFunction("reverseString", StringUtils.class.getDeclaredMethod("reverseString", String.class)); String helloWorldReversed = parser.parseExpression("#reverseString('hello world')").getValue(context, String.class); assertEquals("dlrow olleh",helloWorldReversed); diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/support/ReflectionHelperTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/support/ReflectionHelperTests.java index 14f741052d6..91bae22b4ca 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/support/ReflectionHelperTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/support/ReflectionHelperTests.java @@ -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"); * 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(); // 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 - 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 @@ -128,13 +128,13 @@ public class ReflectionHelperTests extends AbstractExpressionTests { StandardTypeConverter tc = new StandardTypeConverter(); // 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 - 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 - 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 @@ -142,16 +142,16 @@ public class ReflectionHelperTests extends AbstractExpressionTests { StandardTypeConverter tc = new StandardTypeConverter(); // 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 - 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 - 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 - // 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 @@ -159,7 +159,7 @@ public class ReflectionHelperTests extends AbstractExpressionTests { StandardTypeConverter typeConverter = new StandardTypeConverter(); // 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 @@ -169,49 +169,49 @@ public class ReflectionHelperTests extends AbstractExpressionTests { Class integerArrayClass = new Integer[0].getClass(); // 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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) - 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 - 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 - 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[]) ? } @@ -271,7 +271,8 @@ public class ReflectionHelperTests extends AbstractExpressionTests { @Test 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); Object firstParam = newArray[0]; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProviderFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProviderFactory.java index 539cf223f1d..51b3b094288 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProviderFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProviderFactory.java @@ -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"); * 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) { try { - TableMetaDataProvider result = (TableMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, databaseMetaData -> { + return (TableMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, databaseMetaData -> { String databaseProductName = JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessTableColumnMetaData = context.isAccessTableColumnMetaData(); @@ -71,12 +71,11 @@ public class TableMetaDataProviderFactory { } provider.initializeWithMetaData(databaseMetaData); if (accessTableColumnMetaData) { - provider.initializeWithTableColumnMetaData(databaseMetaData, context.getCatalogName(), - context.getSchemaName(), context.getTableName()); + provider.initializeWithTableColumnMetaData(databaseMetaData, + context.getCatalogName(), context.getSchemaName(), context.getTableName()); } return provider; }); - return result; } catch (MetaDataAccessException ex) { throw new DataAccessResourceFailureException("Error retrieving database metadata", ex); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/WebSphereDataSourceAdapter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/WebSphereDataSourceAdapter.java index 363af595d97..12ca3e856b0 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/WebSphereDataSourceAdapter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/WebSphereDataSourceAdapter.java @@ -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"); * 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"); Class jdbcConnSpecClass = getClass().getClassLoader().loadClass("com.ibm.websphere.rsadapter.JDBCConnectionSpec"); 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.wsDataSourceClass.getMethod("getConnection", jdbcConnSpecClass); this.setTransactionIsolationMethod = diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java index e26ef2979d5..1540ffd8e5b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java @@ -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"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.jdbc.support; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.math.BigDecimal; import java.sql.Blob; import java.sql.Clob; @@ -356,8 +355,7 @@ public abstract class JdbcUtils { return (T) extractDatabaseMetaData(dataSource, dbmd -> { try { - Method method = DatabaseMetaData.class.getMethod(metaDataMethodName, (Class[]) null); - return method.invoke(dbmd, (Object[]) null); + return DatabaseMetaData.class.getMethod(metaDataMethodName).invoke(dbmd); } catch (NoSuchMethodException ex) { throw new MetaDataAccessException("No method named '" + metaDataMethodName + diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java index 0b048d0812c..99385727fef 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -38,180 +38,183 @@ import static org.mockito.BDDMockito.*; */ public class ResultSetWrappingRowSetTests { - private ResultSet rset; - private ResultSetWrappingSqlRowSet rowset; + private ResultSet resultSet; + + private ResultSetWrappingSqlRowSet rowSet; + @Before - public void setUp() throws Exception { - rset = mock(ResultSet.class); - rowset = new ResultSetWrappingSqlRowSet(rset); + public void setup() throws Exception { + resultSet = mock(ResultSet.class); + rowSet = new ResultSetWrappingSqlRowSet(resultSet); } + @Test public void testGetBigDecimalInt() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", new Class[] {int.class}); + Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", int.class); doTest(rset, rowset, 1, BigDecimal.ONE); } @Test public void testGetBigDecimalString() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", new Class[] {String.class}); + Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", String.class); doTest(rset, rowset, "test", BigDecimal.ONE); } @Test public void testGetStringInt() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getString", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", new Class[] {int.class}); + Method rset = ResultSet.class.getDeclaredMethod("getString", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", int.class); doTest(rset, rowset, 1, "test"); } @Test public void testGetStringString() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getString", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", new Class[] {String.class}); + Method rset = ResultSet.class.getDeclaredMethod("getString", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", String.class); doTest(rset, rowset, "test", "test"); } @Test public void testGetTimestampInt() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", new Class[] {int.class}); + Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", int.class); doTest(rset, rowset, 1, new Timestamp(1234l)); } @Test public void testGetTimestampString() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", new Class[] {String.class}); + Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", String.class); doTest(rset, rowset, "test", new Timestamp(1234l)); } @Test public void testGetDateInt() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getDate", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", new Class[] {int.class}); + Method rset = ResultSet.class.getDeclaredMethod("getDate", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", int.class); doTest(rset, rowset, 1, new Date(1234l)); } @Test public void testGetDateString() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getDate", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", new Class[] {String.class}); + Method rset = ResultSet.class.getDeclaredMethod("getDate", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", String.class); doTest(rset, rowset, "test", new Date(1234l)); } @Test public void testGetTimeInt() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getTime", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", new Class[] {int.class}); + Method rset = ResultSet.class.getDeclaredMethod("getTime", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", int.class); doTest(rset, rowset, 1, new Time(1234l)); } @Test public void testGetTimeString() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getTime", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", new Class[] {String.class}); + Method rset = ResultSet.class.getDeclaredMethod("getTime", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", String.class); doTest(rset, rowset, "test", new Time(1234l)); } @Test public void testGetObjectInt() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getObject", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", new Class[] {int.class}); + Method rset = ResultSet.class.getDeclaredMethod("getObject", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", int.class); doTest(rset, rowset, 1, new Object()); } @Test public void testGetObjectString() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getObject", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", new Class[] {String.class}); + Method rset = ResultSet.class.getDeclaredMethod("getObject", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", String.class); doTest(rset, rowset, "test", new Object()); } @Test public void testGetIntInt() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getInt", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", new Class[] {int.class}); + Method rset = ResultSet.class.getDeclaredMethod("getInt", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", int.class); doTest(rset, rowset, 1, 1); } @Test public void testGetIntString() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getInt", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", new Class[] {String.class}); + Method rset = ResultSet.class.getDeclaredMethod("getInt", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", String.class); doTest(rset, rowset, "test", 1); } @Test public void testGetFloatInt() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getFloat", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", new Class[] {int.class}); + Method rset = ResultSet.class.getDeclaredMethod("getFloat", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", int.class); doTest(rset, rowset, 1, 1.0f); } @Test public void testGetFloatString() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getFloat", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", new Class[] {String.class}); + Method rset = ResultSet.class.getDeclaredMethod("getFloat", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", String.class); doTest(rset, rowset, "test", 1.0f); } @Test public void testGetDoubleInt() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getDouble", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", new Class[] {int.class}); + Method rset = ResultSet.class.getDeclaredMethod("getDouble", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", int.class); doTest(rset, rowset, 1, 1.0d); } @Test public void testGetDoubleString() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getDouble", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", new Class[] {String.class}); + Method rset = ResultSet.class.getDeclaredMethod("getDouble", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", String.class); doTest(rset, rowset, "test", 1.0d); } @Test public void testGetLongInt() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getLong", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", new Class[] {int.class}); + Method rset = ResultSet.class.getDeclaredMethod("getLong", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", int.class); doTest(rset, rowset, 1, 1L); } @Test public void testGetLongString() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getLong", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", new Class[] {String.class}); + Method rset = ResultSet.class.getDeclaredMethod("getLong", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", String.class); doTest(rset, rowset, "test", 1L); } @Test public void testGetBooleanInt() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getBoolean", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", new Class[] {int.class}); + Method rset = ResultSet.class.getDeclaredMethod("getBoolean", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", int.class); doTest(rset, rowset, 1, true); } @Test public void testGetBooleanString() throws Exception { - Method rset = ResultSet.class.getDeclaredMethod("getBoolean", new Class[] {int.class}); - Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", new Class[] {String.class}); + Method rset = ResultSet.class.getDeclaredMethod("getBoolean", int.class); + Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", String.class); doTest(rset, rowset, "test", true); } private void doTest(Method rsetMethod, Method rowsetMethod, Object arg, Object ret) throws Exception { if (arg instanceof String) { - given(rset.findColumn((String) arg)).willReturn(1); - given(rsetMethod.invoke(rset, 1)).willReturn(ret).willThrow(new SQLException("test")); + given(resultSet.findColumn((String) arg)).willReturn(1); + given(rsetMethod.invoke(resultSet, 1)).willReturn(ret).willThrow(new SQLException("test")); } 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 { - rowsetMethod.invoke(rowset, arg); + rowsetMethod.invoke(rowSet, arg); fail("InvalidResultSetAccessException should have been thrown"); } catch (InvocationTargetException ex) { diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolverTests.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolverTests.java index 863d1f10158..61bf8854f6b 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolverTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolverTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -60,7 +60,7 @@ public class HeaderMethodArgumentResolverTests { @Before - public void setup() throws Exception { + public void setup() { @SuppressWarnings("resource") GenericApplicationContext cxt = new GenericApplicationContext(); cxt.refresh(); diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java index 5bc01918fc8..31936b3b793 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -164,7 +164,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT @Test public void testPublicExtendedPersistenceContextSetterWithSerialization() throws Exception { 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); GenericApplicationContext gac = new GenericApplicationContext(); diff --git a/spring-oxm/src/test/java/org/springframework/oxm/castor/CastorUnmarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/castor/CastorUnmarshallerTests.java index e5405cc6616..db20e7c9d7f 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/castor/CastorUnmarshallerTests.java +++ b/spring-oxm/src/test/java/org/springframework/oxm/castor/CastorUnmarshallerTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -87,7 +87,7 @@ public class CastorUnmarshallerTests extends AbstractUnmarshallerTests"; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java index 25463a4486f..784254b5c14 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java @@ -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"); * 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 { - // @formatter:off - private final Class[] testClasses = new Class[] { + private final Class[] testClasses = new Class[] { // Basics SpringJUnit4ClassRunnerAppCtxTests.class, InheritedConfigSpringJUnit4ClassRunnerAppCtxTests.class, @@ -94,7 +93,7 @@ public class SpringJUnit4ConcurrencyTests { WebAppResourceTests.class, SampleTests.class }; - // @formatter:on + @BeforeClass public static void abortIfLongRunningTestGroupIsNotEnabled() { @@ -109,7 +108,7 @@ public class SpringJUnit4ConcurrencyTests { final int TESTS = countAnnotatedMethods(Test.class) - IGNORED; runTestsAndAssertCounters(new ParallelComputer(true, true), TESTS, FAILED, TESTS, IGNORED, ABORTED, - this.testClasses); + this.testClasses); } private int countAnnotatedMethods(Class annotationType) { diff --git a/spring-test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java index 8f416cfaa45..e71c33d17bd 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -57,8 +57,8 @@ public class DelegatingSmartContextLoaderTests { @Test public void processContextConfigurationWithDefaultXmlConfigGeneration() { - ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(XmlTestCase.class, - EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); + ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( + XmlTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertEquals(1, configAttributes.getLocations().length); assertEmpty(configAttributes.getClasses()); @@ -66,8 +66,8 @@ public class DelegatingSmartContextLoaderTests { @Test public void processContextConfigurationWithDefaultConfigurationClassGeneration() { - ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(ConfigClassTestCase.class, - EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); + ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( + ConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertEquals(1, configAttributes.getClasses().length); assertEmpty(configAttributes.getLocations()); @@ -79,16 +79,16 @@ public class DelegatingSmartContextLoaderTests { expectedException.expectMessage(containsString("both default locations AND default configuration classes were detected")); ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( - ImproperDuplicateDefaultXmlAndConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, - true, ContextLoader.class); + ImproperDuplicateDefaultXmlAndConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, + true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); } @Test public void processContextConfigurationWithLocation() { - String[] locations = new String[] { "classpath:/foo.xml" }; - ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(getClass(), locations, - EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); + String[] locations = new String[] {"classpath:/foo.xml"}; + ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( + getClass(), locations, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertArrayEquals(locations, configAttributes.getLocations()); assertEmpty(configAttributes.getClasses()); @@ -96,9 +96,9 @@ public class DelegatingSmartContextLoaderTests { @Test public void processContextConfigurationWithConfigurationClass() { - Class[] classes = new Class[] { getClass() }; - ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(getClass(), - EMPTY_STRING_ARRAY, classes, true, null, true, ContextLoader.class); + Class[] classes = new Class[] {getClass()}; + ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( + getClass(), EMPTY_STRING_ARRAY, classes, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertArrayEquals(classes, configAttributes.getClasses()); assertEmpty(configAttributes.getLocations()); @@ -118,8 +118,8 @@ public class DelegatingSmartContextLoaderTests { expectedException.expectMessage(startsWith("Neither")); expectedException.expectMessage(containsString("was able to load an ApplicationContext from")); - MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, - EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); + MergedContextConfiguration mergedConfig = new MergedContextConfiguration( + getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); loader.loadContext(mergedConfig); } @@ -133,12 +133,13 @@ public class DelegatingSmartContextLoaderTests { expectedException.expectMessage(endsWith("declare either 'locations' or 'classes' but not both.")); 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); } private void assertApplicationContextLoadsAndContainsFooString(MergedContextConfiguration mergedConfig) throws Exception { + ApplicationContext applicationContext = loader.loadContext(mergedConfig); assertNotNull(applicationContext); assertEquals("foo", applicationContext.getBean(String.class)); @@ -149,16 +150,16 @@ public class DelegatingSmartContextLoaderTests { @Test public void loadContextWithXmlConfig() throws Exception { MergedContextConfiguration mergedConfig = new MergedContextConfiguration( - XmlTestCase.class, - new String[] { "classpath:/org/springframework/test/context/support/DelegatingSmartContextLoaderTests$XmlTestCase-context.xml" }, - EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); + XmlTestCase.class, + new String[] {"classpath:/org/springframework/test/context/support/DelegatingSmartContextLoaderTests$XmlTestCase-context.xml"}, + EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); assertApplicationContextLoadsAndContainsFooString(mergedConfig); } @Test public void loadContextWithConfigurationClass() throws Exception { 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); } @@ -192,7 +193,6 @@ public class DelegatingSmartContextLoaderTests { } static class NotAConfigClass { - } } diff --git a/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java b/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java index daf25306396..ba5e330ee80 100644 --- a/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java @@ -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"); * 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 { - private void assertAtComponentOnComposedAnnotation(Class rootDeclaringClass, String name, - Class composedAnnotationType) { + private void assertAtComponentOnComposedAnnotation( + Class rootDeclaringClass, String name, Class composedAnnotationType) { + assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, name, composedAnnotationType); } - private void assertAtComponentOnComposedAnnotation(Class startClass, Class rootDeclaringClass, String name, - Class composedAnnotationType) { - assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, composedAnnotationType, name, - composedAnnotationType); + private void assertAtComponentOnComposedAnnotation( + Class startClass, Class rootDeclaringClass, String name, Class composedAnnotationType) { + + assertAtComponentOnComposedAnnotation(startClass, rootDeclaringClass, composedAnnotationType, name, composedAnnotationType); } private void assertAtComponentOnComposedAnnotation(Class startClass, Class rootDeclaringClass, Class declaringClass, String name, Class composedAnnotationType) { + AnnotationDescriptor descriptor = findAnnotationDescriptor(startClass, Component.class); assertNotNull("AnnotationDescriptor should not be null", descriptor); assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass()); @@ -67,25 +69,29 @@ public class MetaAnnotationUtilsTests { assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType()); } - private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class startClass, String name, - Class composedAnnotationType) { - assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, name, - composedAnnotationType); + private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( + Class startClass, String name, Class composedAnnotationType) { + + assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( + startClass, startClass, name, composedAnnotationType); } private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class startClass, Class rootDeclaringClass, String name, Class composedAnnotationType) { - assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, rootDeclaringClass, - composedAnnotationType, name, composedAnnotationType); + + assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( + startClass, rootDeclaringClass, composedAnnotationType, name, composedAnnotationType); } @SuppressWarnings("unchecked") private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class startClass, Class rootDeclaringClass, Class declaringClass, String name, Class composedAnnotationType) { + Class annotationType = Component.class; - UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class, - annotationType, Order.class, Transactional.class); + UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( + startClass, Service.class, annotationType, Order.class, Transactional.class); + assertNotNull("UntypedAnnotationDescriptor should not be null", descriptor); assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass()); assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass()); @@ -96,28 +102,27 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorWithNoAnnotationPresent() throws Exception { + public void findAnnotationDescriptorWithNoAnnotationPresent() { assertNull(findAnnotationDescriptor(NonAnnotatedInterface.class, Transactional.class)); assertNull(findAnnotationDescriptor(NonAnnotatedClass.class, Transactional.class)); } @Test - public void findAnnotationDescriptorWithInheritedAnnotationOnClass() throws Exception { + public void findAnnotationDescriptorWithInheritedAnnotationOnClass() { // Note: @Transactional is inherited assertEquals(InheritedAnnotationClass.class, - findAnnotationDescriptor(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); + findAnnotationDescriptor(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); assertEquals(InheritedAnnotationClass.class, - findAnnotationDescriptor(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); + findAnnotationDescriptor(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); } @Test - public void findAnnotationDescriptorWithInheritedAnnotationOnInterface() throws Exception { + public void findAnnotationDescriptorWithInheritedAnnotationOnInterface() { // Note: @Transactional is inherited Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class); - AnnotationDescriptor descriptor; - - descriptor = findAnnotationDescriptor(InheritedAnnotationInterface.class, Transactional.class); + AnnotationDescriptor descriptor = + findAnnotationDescriptor(InheritedAnnotationInterface.class, Transactional.class); assertNotNull(descriptor); assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass()); @@ -137,22 +142,21 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorForNonInheritedAnnotationOnClass() throws Exception { + public void findAnnotationDescriptorForNonInheritedAnnotationOnClass() { // Note: @Order is not inherited. assertEquals(NonInheritedAnnotationClass.class, - findAnnotationDescriptor(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); + findAnnotationDescriptor(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); assertEquals(NonInheritedAnnotationClass.class, - findAnnotationDescriptor(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); + findAnnotationDescriptor(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); } @Test - public void findAnnotationDescriptorForNonInheritedAnnotationOnInterface() throws Exception { + public void findAnnotationDescriptorForNonInheritedAnnotationOnInterface() { // Note: @Order is not inherited. Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class); - AnnotationDescriptor descriptor; - - descriptor = findAnnotationDescriptor(NonInheritedAnnotationInterface.class, Order.class); + AnnotationDescriptor descriptor = + findAnnotationDescriptor(NonInheritedAnnotationInterface.class, Order.class); assertNotNull(descriptor); assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass()); @@ -166,15 +170,16 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorWithMetaComponentAnnotation() throws Exception { + public void findAnnotationDescriptorWithMetaComponentAnnotation() { assertAtComponentOnComposedAnnotation(HasMetaComponentAnnotation.class, "meta1", Meta1.class); } @Test - public void findAnnotationDescriptorWithLocalAndMetaComponentAnnotation() throws Exception { + public void findAnnotationDescriptorWithLocalAndMetaComponentAnnotation() { Class annotationType = Component.class; - AnnotationDescriptor descriptor = findAnnotationDescriptor(HasLocalAndMetaComponentAnnotation.class, - annotationType); + AnnotationDescriptor descriptor = findAnnotationDescriptor( + HasLocalAndMetaComponentAnnotation.class, annotationType); + assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass()); assertEquals(annotationType, descriptor.getAnnotationType()); assertNull(descriptor.getComposedAnnotation()); @@ -188,12 +193,10 @@ public class MetaAnnotationUtilsTests { @Test public void findAnnotationDescriptorForClassWithMetaAnnotatedInterface() { - Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, - Component.class); + Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class); + AnnotationDescriptor descriptor = + findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class); - AnnotationDescriptor descriptor; - - descriptor = findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class); assertNotNull(descriptor); assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass()); assertEquals(Meta1.class, descriptor.getDeclaringClass()); @@ -204,7 +207,7 @@ public class MetaAnnotationUtilsTests { @Test public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndAnnotatedSuperclass() { AnnotationDescriptor descriptor = findAnnotationDescriptor( - MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, ContextConfiguration.class); + MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, ContextConfiguration.class); assertNotNull("AnnotationDescriptor should not be null", descriptor); assertEquals("rootDeclaringClass", MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, descriptor.getRootDeclaringClass()); @@ -213,20 +216,19 @@ public class MetaAnnotationUtilsTests { assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation()); assertEquals("composedAnnotationType", MetaConfig.class, descriptor.getComposedAnnotationType()); - assertArrayEquals("configured classes", new Class[] { String.class }, - descriptor.getAnnotationAttributes().getClassArray("classes")); + assertArrayEquals("configured classes", new Class[] {String.class}, + descriptor.getAnnotationAttributes().getClassArray("classes")); } @Test public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { - assertAtComponentOnComposedAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", - Meta2.class); + assertAtComponentOnComposedAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); } @Test public void findAnnotationDescriptorForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { assertAtComponentOnComposedAnnotation(SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, - ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); + ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); } /** @@ -253,8 +255,8 @@ public class MetaAnnotationUtilsTests { @Test public void findAnnotationDescriptorOnAnnotatedClassWithMissingTargetMetaAnnotation() { // InheritedAnnotationClass is NOT annotated or meta-annotated with @Component - AnnotationDescriptor descriptor = findAnnotationDescriptor(InheritedAnnotationClass.class, - Component.class); + AnnotationDescriptor descriptor = findAnnotationDescriptor( + InheritedAnnotationClass.class, Component.class); assertNull("Should not find @Component on InheritedAnnotationClass", descriptor); } @@ -263,8 +265,8 @@ public class MetaAnnotationUtilsTests { */ @Test public void findAnnotationDescriptorOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { - AnnotationDescriptor descriptor = findAnnotationDescriptor(MetaCycleAnnotatedClass.class, - Component.class); + AnnotationDescriptor descriptor = findAnnotationDescriptor( + MetaCycleAnnotatedClass.class, Component.class); assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor); } @@ -272,32 +274,30 @@ public class MetaAnnotationUtilsTests { @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithNoAnnotationPresent() throws Exception { + public void findAnnotationDescriptorForTypesWithNoAnnotationPresent() { assertNull(findAnnotationDescriptorForTypes(NonAnnotatedInterface.class, Transactional.class, Component.class)); assertNull(findAnnotationDescriptorForTypes(NonAnnotatedClass.class, Transactional.class, Order.class)); } @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnClass() throws Exception { + public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnClass() { // Note: @Transactional is inherited + assertEquals(InheritedAnnotationClass.class, + findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); assertEquals( - InheritedAnnotationClass.class, - findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); - assertEquals( - InheritedAnnotationClass.class, - findAnnotationDescriptorForTypes(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); + InheritedAnnotationClass.class, + findAnnotationDescriptorForTypes(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); } @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface() throws Exception { + public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface() { // Note: @Transactional is inherited Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class); - UntypedAnnotationDescriptor descriptor; - - descriptor = findAnnotationDescriptorForTypes(InheritedAnnotationInterface.class, Transactional.class); + UntypedAnnotationDescriptor descriptor = + findAnnotationDescriptorForTypes(InheritedAnnotationInterface.class, Transactional.class); assertNotNull(descriptor); assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass()); @@ -318,23 +318,22 @@ public class MetaAnnotationUtilsTests { @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnClass() throws Exception { + public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnClass() { // Note: @Order is not inherited. assertEquals(NonInheritedAnnotationClass.class, - findAnnotationDescriptorForTypes(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); + findAnnotationDescriptorForTypes(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); assertEquals(NonInheritedAnnotationClass.class, - findAnnotationDescriptorForTypes(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); + findAnnotationDescriptorForTypes(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); } @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface() throws Exception { + public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface() { // Note: @Order is not inherited. Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class); - UntypedAnnotationDescriptor descriptor; - - descriptor = findAnnotationDescriptorForTypes(NonInheritedAnnotationInterface.class, Order.class); + UntypedAnnotationDescriptor descriptor = + findAnnotationDescriptorForTypes(NonInheritedAnnotationInterface.class, Order.class); assertNotNull(descriptor); assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass()); @@ -349,10 +348,10 @@ public class MetaAnnotationUtilsTests { @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() throws Exception { + public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() { Class annotationType = Component.class; UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( - HasLocalAndMetaComponentAnnotation.class, Transactional.class, annotationType, Order.class); + HasLocalAndMetaComponentAnnotation.class, Transactional.class, annotationType, Order.class); assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass()); assertEquals(annotationType, descriptor.getAnnotationType()); assertNull(descriptor.getComposedAnnotation()); @@ -360,45 +359,45 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() throws Exception { + public void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() { Class startClass = HasMetaComponentAnnotation.class; assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, "meta1", Meta1.class); } @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() throws Exception { + public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() { Class startClass = MetaConfigWithDefaultAttributesTestCase.class; Class annotationType = ContextConfiguration.class; - UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class, - ContextConfiguration.class, Order.class, Transactional.class); + UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, + Service.class, ContextConfiguration.class, Order.class, Transactional.class); assertNotNull(descriptor); assertEquals(startClass, descriptor.getRootDeclaringClass()); assertEquals(annotationType, descriptor.getAnnotationType()); - assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value()); - assertArrayEquals(new Class[] { MetaConfig.DevConfig.class, MetaConfig.ProductionConfig.class }, - descriptor.getAnnotationAttributes().getClassArray("classes")); + assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value()); + assertArrayEquals(new Class[] {MetaConfig.DevConfig.class, MetaConfig.ProductionConfig.class}, + descriptor.getAnnotationAttributes().getClassArray("classes")); assertNotNull(descriptor.getComposedAnnotation()); assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType()); } @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() throws Exception { + public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() { Class startClass = MetaConfigWithOverriddenAttributesTestCase.class; Class annotationType = ContextConfiguration.class; - UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class, - ContextConfiguration.class, Order.class, Transactional.class); + UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( + startClass, Service.class, ContextConfiguration.class, Order.class, Transactional.class); assertNotNull(descriptor); assertEquals(startClass, descriptor.getRootDeclaringClass()); assertEquals(annotationType, descriptor.getAnnotationType()); - assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value()); - assertArrayEquals(new Class[] { MetaAnnotationUtilsTests.class }, - descriptor.getAnnotationAttributes().getClassArray("classes")); + assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value()); + assertArrayEquals(new Class[] {MetaAnnotationUtilsTests.class}, + descriptor.getAnnotationAttributes().getClassArray("classes")); assertNotNull(descriptor.getComposedAnnotation()); assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType()); } @@ -412,13 +411,11 @@ public class MetaAnnotationUtilsTests { @Test @SuppressWarnings("unchecked") public void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() { - Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, - Component.class); + Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.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); assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass()); assertEquals(Meta1.class, descriptor.getDeclaringClass()); @@ -435,8 +432,8 @@ public class MetaAnnotationUtilsTests { @Test public void findAnnotationDescriptorForTypesForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( - SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, - ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); + SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, + ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); } /** @@ -445,8 +442,8 @@ public class MetaAnnotationUtilsTests { @Test public void findAnnotationDescriptorForTypesOnMetaMetaAnnotatedClass() { Class startClass = MetaMetaAnnotatedClass.class; - assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, Meta2.class, "meta2", - MetaMeta.class); + assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( + startClass, startClass, Meta2.class, "meta2", MetaMeta.class); } /** @@ -455,8 +452,8 @@ public class MetaAnnotationUtilsTests { @Test public void findAnnotationDescriptorForTypesOnMetaMetaMetaAnnotatedClass() { Class startClass = MetaMetaMetaAnnotatedClass.class; - assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, Meta2.class, "meta2", - MetaMetaMeta.class); + assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( + startClass, startClass, Meta2.class, "meta2", MetaMetaMeta.class); } /** @@ -467,8 +464,8 @@ public class MetaAnnotationUtilsTests { public void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() { // InheritedAnnotationClass is NOT annotated or meta-annotated with @Component, // @Service, or @Order, but it is annotated with @Transactional. - UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, - Service.class, Component.class, Order.class); + UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( + InheritedAnnotationClass.class, Service.class, Component.class, Order.class); assertNull("Should not find @Component on InheritedAnnotationClass", descriptor); } @@ -478,8 +475,8 @@ public class MetaAnnotationUtilsTests { @Test @SuppressWarnings("unchecked") public void findAnnotationDescriptorForTypesOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { - UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(MetaCycleAnnotatedClass.class, - Service.class, Component.class, Order.class); + UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( + MetaCycleAnnotatedClass.class, Service.class, Component.class, Order.class); assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor); } diff --git a/spring-tx/src/test/java/org/springframework/transaction/TxNamespaceHandlerTests.java b/spring-tx/src/test/java/org/springframework/transaction/TxNamespaceHandlerTests.java index 52c41cd9248..ce62d2948b8 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/TxNamespaceHandlerTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/TxNamespaceHandlerTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -46,20 +46,21 @@ public class TxNamespaceHandlerTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.context = new ClassPathXmlApplicationContext("txNamespaceHandlerTests.xml", getClass()); - this.getAgeMethod = ITestBean.class.getMethod("getAge", new Class[0]); - this.setAgeMethod = ITestBean.class.getMethod("setAge", new Class[] {int.class}); + this.getAgeMethod = ITestBean.class.getMethod("getAge"); + this.setAgeMethod = ITestBean.class.getMethod("setAge", int.class); } + @Test - public void isProxy() throws Exception { + public void isProxy() { ITestBean bean = getTestBean(); assertTrue("testBean is not a proxy", AopUtils.isAopProxy(bean)); } @Test - public void invokeTransactional() throws Exception { + public void invokeTransactional() { ITestBean testBean = getTestBean(); CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager"); @@ -97,7 +98,7 @@ public class TxNamespaceHandlerTests { } private ITestBean getTestBean() { - return (ITestBean)context.getBean("testBean"); + return (ITestBean) context.getBean("testBean"); } } diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/AbstractTransactionAspectTests.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/AbstractTransactionAspectTests.java index ef5a832d878..2d3e9cef190 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/AbstractTransactionAspectTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/AbstractTransactionAspectTests.java @@ -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"); * 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 org.junit.Before; import org.junit.Test; import org.springframework.dao.OptimisticLockingFailureException; @@ -57,16 +58,11 @@ public abstract class AbstractTransactionAspectTests { protected Method setNameMethod; - public AbstractTransactionAspectTests() { - try { - // Cache the methods we'll be testing - exceptionalMethod = ITestBean.class.getMethod("exceptional", new Class[] { Throwable.class }); - getNameMethod = ITestBean.class.getMethod("getName", (Class[]) null); - setNameMethod = ITestBean.class.getMethod("setName", new Class[] { String.class} ); - } - catch (NoSuchMethodException ex) { - throw new RuntimeException("Shouldn't happen", ex); - } + @Before + public void setup() throws Exception { + exceptionalMethod = ITestBean.class.getMethod("exceptional", Throwable.class); + getNameMethod = ITestBean.class.getMethod("getName"); + setNameMethod = ITestBean.class.getMethod("setName", String.class); } diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceEditorTests.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceEditorTests.java index e16c92b6f71..f3ca7163533 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceEditorTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceEditorTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ public class TransactionAttributeSourceEditorTests { editor.setAsText(null); TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue(); - Method m = Object.class.getMethod("hashCode", (Class[]) null); + Method m = Object.class.getMethod("hashCode"); assertNull(tas.getTransactionAttribute(m, null)); } @@ -62,21 +62,21 @@ public class TransactionAttributeSourceEditorTests { "java.lang.Object.not*=PROPAGATION_REQUIRED"); TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue(); - checkTransactionProperties(tas, Object.class.getMethod("hashCode", (Class[]) null), + checkTransactionProperties(tas, Object.class.getMethod("hashCode"), TransactionDefinition.PROPAGATION_REQUIRED); - checkTransactionProperties(tas, Object.class.getMethod("equals", new Class[] { Object.class }), + checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class), TransactionDefinition.PROPAGATION_MANDATORY); - checkTransactionProperties(tas, Object.class.getMethod("wait", (Class[]) null), + checkTransactionProperties(tas, Object.class.getMethod("wait"), TransactionDefinition.PROPAGATION_SUPPORTS); - checkTransactionProperties(tas, Object.class.getMethod("wait", new Class[] { long.class }), + checkTransactionProperties(tas, Object.class.getMethod("wait", long.class), 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); - checkTransactionProperties(tas, Object.class.getMethod("notify", (Class[]) null), + checkTransactionProperties(tas, Object.class.getMethod("notify"), TransactionDefinition.PROPAGATION_SUPPORTS); - checkTransactionProperties(tas, Object.class.getMethod("notifyAll", (Class[]) null), + checkTransactionProperties(tas, Object.class.getMethod("notifyAll"), TransactionDefinition.PROPAGATION_REQUIRED); - checkTransactionProperties(tas, Object.class.getMethod("toString", (Class[]) null), -1); + checkTransactionProperties(tas, Object.class.getMethod("toString"), -1); } @Test @@ -84,21 +84,21 @@ public class TransactionAttributeSourceEditorTests { editor.setAsText("java.lang.Object.*=PROPAGATION_REQUIRED"); TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue(); - checkTransactionProperties(tas, Object.class.getMethod("hashCode", (Class[]) null), + checkTransactionProperties(tas, Object.class.getMethod("hashCode"), TransactionDefinition.PROPAGATION_REQUIRED); - checkTransactionProperties(tas, Object.class.getMethod("equals", new Class[] { Object.class }), + checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class), TransactionDefinition.PROPAGATION_REQUIRED); - checkTransactionProperties(tas, Object.class.getMethod("wait", (Class[]) null), + checkTransactionProperties(tas, Object.class.getMethod("wait"), TransactionDefinition.PROPAGATION_REQUIRED); - checkTransactionProperties(tas, Object.class.getMethod("wait", new Class[] { long.class }), + checkTransactionProperties(tas, Object.class.getMethod("wait", long.class), 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); - checkTransactionProperties(tas, Object.class.getMethod("notify", (Class[]) null), + checkTransactionProperties(tas, Object.class.getMethod("notify"), TransactionDefinition.PROPAGATION_REQUIRED); - checkTransactionProperties(tas, Object.class.getMethod("notifyAll", (Class[]) null), + checkTransactionProperties(tas, Object.class.getMethod("notifyAll"), TransactionDefinition.PROPAGATION_REQUIRED); - checkTransactionProperties(tas, Object.class.getMethod("toString", (Class[]) null), + checkTransactionProperties(tas, Object.class.getMethod("toString"), TransactionDefinition.PROPAGATION_REQUIRED); } diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceTests.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceTests.java index a6fb9f75c59..ade9b34bc57 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceTests.java @@ -41,13 +41,13 @@ public class TransactionAttributeSourceTests { public void matchAlwaysTransactionAttributeSource() throws Exception { MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource(); TransactionAttribute ta = tas.getTransactionAttribute( - Object.class.getMethod("hashCode", (Class[]) null), null); + Object.class.getMethod("hashCode"), null); assertNotNull(ta); assertTrue(TransactionDefinition.PROPAGATION_REQUIRED == ta.getPropagationBehavior()); tas.setTransactionAttribute(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS)); ta = tas.getTransactionAttribute( - IOException.class.getMethod("getMessage", (Class[]) null), IOException.class); + IOException.class.getMethod("getMessage"), IOException.class); assertNotNull(ta); assertTrue(TransactionDefinition.PROPAGATION_SUPPORTS == ta.getPropagationBehavior()); } @@ -60,7 +60,7 @@ public class TransactionAttributeSourceTests { attributes.put("*ashCode", "PROPAGATION_REQUIRED"); tas.setProperties(attributes); TransactionAttribute ta = tas.getTransactionAttribute( - Object.class.getMethod("hashCode", (Class[]) null), null); + Object.class.getMethod("hashCode"), null); assertNotNull(ta); assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior()); } @@ -73,7 +73,7 @@ public class TransactionAttributeSourceTests { attributes.put("hashCod*", "PROPAGATION_REQUIRED"); tas.setProperties(attributes); TransactionAttribute ta = tas.getTransactionAttribute( - Object.class.getMethod("hashCode", (Class[]) null), null); + Object.class.getMethod("hashCode"), null); assertNotNull(ta); assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior()); } @@ -87,7 +87,7 @@ public class TransactionAttributeSourceTests { attributes.put("hashCode", "PROPAGATION_MANDATORY"); tas.setProperties(attributes); TransactionAttribute ta = tas.getTransactionAttribute( - Object.class.getMethod("hashCode", (Class[]) null), null); + Object.class.getMethod("hashCode"), null); assertNotNull(ta); assertEquals(TransactionDefinition.PROPAGATION_MANDATORY, ta.getPropagationBehavior()); } @@ -100,7 +100,7 @@ public class TransactionAttributeSourceTests { attributes.put("", "PROPAGATION_MANDATORY"); tas.setProperties(attributes); TransactionAttribute ta = tas.getTransactionAttribute( - Object.class.getMethod("hashCode", (Class[]) null), null); + Object.class.getMethod("hashCode"), null); assertNull(ta); } diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java index bc1d76c6ea3..4c4088e98d7 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -47,6 +47,7 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests @Rule public final ExpectedException thrown = ExpectedException.none(); + @Override protected Object advised(Object target, PlatformTransactionManager ptm, TransactionAttributeSource[] tas) throws Exception { TransactionInterceptor ti = new TransactionInterceptor(); @@ -76,6 +77,7 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests return pf.getProxy(); } + /** * A TransactionInterceptor should be serializable if its * PlatformTransactionManager is. @@ -109,7 +111,7 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests tas2.setProperties(props); TransactionInterceptor ti = new TransactionInterceptor(); - ti.setTransactionAttributeSources(new TransactionAttributeSource[] {tas1, tas2}); + ti.setTransactionAttributeSources(tas1, tas2); PlatformTransactionManager ptm = new SerializableTransactionManager(); ti.setTransactionManager(ptm); ti = (TransactionInterceptor) SerializationTestUtils.serializeAndDeserialize(ti); @@ -255,8 +257,10 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests verify(beanFactory, times(1)).getBean(PlatformTransactionManager.class); } + private TransactionInterceptor createTransactionInterceptor(BeanFactory beanFactory, String transactionManagerName, PlatformTransactionManager transactionManager) { + TransactionInterceptor ti = new TransactionInterceptor(); if (beanFactory != null) { ti.setBeanFactory(beanFactory); @@ -317,6 +321,6 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests public void rollback(TransactionStatus status) throws TransactionException { throw new UnsupportedOperationException(); } - } + } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolverTests.java index 31dfc5bdb7a..4a596e560ca 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolverTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -80,7 +80,7 @@ public class SimpleMappingExceptionResolverTests { @Test public void defaultErrorViewDifferentHandlerClass() { exceptionResolver.setDefaultErrorView("default-view"); - exceptionResolver.setMappedHandlerClasses(new Class[] {String.class}); + exceptionResolver.setMappedHandlerClasses(String.class); ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException); assertNull(mav); } @@ -161,7 +161,7 @@ public class SimpleMappingExceptionResolverTests { public void exactExceptionMappingWithHandlerClassSpecified() { Properties props = new Properties(); props.setProperty("java.lang.Exception", "error"); - exceptionResolver.setMappedHandlerClasses(new Class[] {String.class}); + exceptionResolver.setMappedHandlerClasses(String.class); exceptionResolver.setExceptionMappings(props); ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException); assertEquals("error", mav.getViewName()); @@ -171,7 +171,7 @@ public class SimpleMappingExceptionResolverTests { public void exactExceptionMappingWithHandlerInterfaceSpecified() { Properties props = new Properties(); props.setProperty("java.lang.Exception", "error"); - exceptionResolver.setMappedHandlerClasses(new Class[] {Comparable.class}); + exceptionResolver.setMappedHandlerClasses(Comparable.class); exceptionResolver.setExceptionMappings(props); ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException); assertEquals("error", mav.getViewName()); @@ -191,7 +191,7 @@ public class SimpleMappingExceptionResolverTests { public void simpleExceptionMappingWithHandlerClassSpecifiedButWrongHandler() { Properties props = new Properties(); props.setProperty("Exception", "error"); - exceptionResolver.setMappedHandlerClasses(new Class[] {String.class}); + exceptionResolver.setMappedHandlerClasses(String.class); exceptionResolver.setExceptionMappings(props); ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException); assertNull(mav); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChainTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChainTests.java index 0df5000519c..b2056a88361 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChainTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChainTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -16,11 +16,9 @@ package org.springframework.web.servlet.mvc.method.annotation; -import static org.junit.Assert.*; -import static org.mockito.BDDMockito.*; - import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import java.util.List; 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.method.ControllerAdviceBean; +import static org.junit.Assert.*; +import static org.mockito.BDDMockito.*; + /** * Unit tests for {@link RequestResponseBodyAdviceChain}. * @@ -80,7 +81,6 @@ public class RequestResponseBodyAdviceChainTests { @SuppressWarnings("unchecked") @Test public void requestBodyAdvice() throws IOException { - RequestBodyAdvice requestAdvice = Mockito.mock(RequestBodyAdvice.class); ResponseBodyAdvice responseAdvice = Mockito.mock(ResponseBodyAdvice.class); List advice = Arrays.asList(requestAdvice, responseAdvice); @@ -104,7 +104,6 @@ public class RequestResponseBodyAdviceChainTests { @SuppressWarnings("unchecked") @Test public void responseBodyAdvice() { - RequestBodyAdvice requestAdvice = Mockito.mock(RequestBodyAdvice.class); ResponseBodyAdvice responseAdvice = Mockito.mock(ResponseBodyAdvice.class); List advice = Arrays.asList(requestAdvice, responseAdvice); @@ -123,9 +122,8 @@ public class RequestResponseBodyAdviceChainTests { @Test public void controllerAdvice() { - 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, this.converterType, this.request, this.response); @@ -135,9 +133,8 @@ public class RequestResponseBodyAdviceChainTests { @Test public void controllerAdviceNotApplicable() { - 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, this.converterType, this.request, this.response); @@ -164,6 +161,7 @@ public class RequestResponseBodyAdviceChainTests { } } + @ControllerAdvice(annotations = Controller.class) private static class TargetedControllerAdvice implements ResponseBodyAdvice { @@ -182,6 +180,7 @@ public class RequestResponseBodyAdviceChainTests { } } + @SuppressWarnings("unused") @ResponseBody public String handle(String body) { diff --git a/src/docs/asciidoc/core/core-expressions.adoc b/src/docs/asciidoc/core/core-expressions.adoc index fcb95d8bda8..7f0b0acaa6e 100644 --- a/src/docs/asciidoc/core/core-expressions.adoc +++ b/src/docs/asciidoc/core/core-expressions.adoc @@ -1089,7 +1089,7 @@ expression string. StandardEvaluationContext context = new StandardEvaluationContext(); context.registerFunction("reverseString", - StringUtils.class.getDeclaredMethod("reverseString", new Class[] { String.class })); + StringUtils.class.getDeclaredMethod("reverseString", String.class)); String helloWorldReversed = parser.parseExpression( "#reverseString('hello')").getValue(context, String.class); diff --git a/src/docs/asciidoc/web/webmvc.adoc b/src/docs/asciidoc/web/webmvc.adoc index 7889b17629d..dec160b7bd1 100644 --- a/src/docs/asciidoc/web/webmvc.adoc +++ b/src/docs/asciidoc/web/webmvc.adoc @@ -342,7 +342,7 @@ This is recommended for applications that use Java-based Spring configuration: @Override protected Class[] getServletConfigClasses() { - return new Class[] { MyWebConfig.class }; + return new Class[] { MyWebConfig.class }; } @Override