Consistent Class array vs vararg declarations (and related polishing)

(cherry picked from commit 3b810f3)
This commit is contained in:
Juergen Hoeller
2018-02-14 14:44:00 +01:00
parent 5ba37762fe
commit 722cb36e01
40 changed files with 486 additions and 489 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ public final 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 final 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 final 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++) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,7 +83,7 @@ public final 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 final 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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ public final 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 final 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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ import static org.junit.Assert.*;
* @author Chris Beams
* @since 19.05.2003
*/
public final class BeanUtilsTests {
public class BeanUtilsTests {
@Test
public void testInstantiateClass() {
@@ -193,7 +193,7 @@ public final class BeanUtilsTests {
source.setFlag2(true);
InvalidProperty target = new InvalidProperty();
BeanUtils.copyProperties(source, target);
assertEquals(target.getName(), "name");
assertEquals("name", target.getName());
assertTrue(target.getFlag1());
assertTrue(target.getFlag2());
}
@@ -226,14 +226,14 @@ public final 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 final 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[][])");
}
@@ -444,5 +444,18 @@ public final class BeanUtilsTests {
value = aValue;
}
}
private static class BeanWithSingleNonDefaultConstructor {
private final String name;
public BeanWithSingleNonDefaultConstructor(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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<Integer, Boolean> map = new HashMap<Integer, Boolean>();
Map<Integer, Boolean> 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()));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 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.
@@ -135,7 +135,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");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ public class ConventionsTests {
@Test
public void emptyList() {
exception.expect(IllegalArgumentException.class);
this.exception.expect(IllegalArgumentException.class);
Conventions.getVariableName(new ArrayList<>());
}
@@ -67,14 +67,14 @@ public class ConventionsTests {
}
@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<String> cls = String.class;
String desiredResult = "java.lang.String.foo";

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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<TestObject> noArgsCons = TestObject.class.getConstructor(new Class[0]);
Constructor<TestObject> 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<TestObject> twoArgCons = TestObject.class.getConstructor(new Class[] { String.class, int.class });
Constructor<TestObject> twoArgCons = TestObject.class.getConstructor(String.class, int.class);
String[] names = discoverer.getParameterNames(twoArgCons);
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<? extends LocalVariableTableParameterNameDiscovererTests> clazz = this.getClass();
Method m1 = clazz.getMethod("staticMethod", new Class[] { Long.TYPE, Long.TYPE });
Method m1 = clazz.getMethod("staticMethod", Long.TYPE, Long.TYPE);
String[] names = discoverer.getParameterNames(m1);
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<InnerClass> clazz = InnerClass.class;
Method m1 = clazz.getMethod("staticMethod", new Class[] { Long.TYPE });
Method m1 = clazz.getMethod("staticMethod", Long.TYPE);
String[] names = discoverer.getParameterNames(m1);
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<? extends LocalVariableTableParameterNameDiscovererTests> clazz = this.getClass();
Method m1 = clazz.getMethod("instanceMethod", new Class[] { Double.TYPE, Double.TYPE });
Method m1 = clazz.getMethod("instanceMethod", Double.TYPE, Double.TYPE);
String[] names = discoverer.getParameterNames(m1);
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<InnerClass> clazz = InnerClass.class;
Method m1 = clazz.getMethod("instanceMethod", new Class[] { String.class });
Method m1 = clazz.getMethod("instanceMethod", String.class);
String[] names = discoverer.getParameterNames(m1);
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<K, V> {
private static long date;
static {
@@ -317,4 +321,5 @@ public class LocalVariableTableParameterNameDiscovererTests {
return date;
}
}
}

View File

@@ -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

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -294,9 +294,9 @@ public class AnnotationMetadataTests {
assertEquals("direct", method.getAnnotationAttributes(DirectAnnotation.class.getName()).get("value"));
assertEquals("direct", method.getAnnotationAttributes(DirectAnnotation.class.getName()).get("myValue"));
List<Object> allMeta = method.getAllAnnotationAttributes(DirectAnnotation.class.getName()).get("value");
assertThat(new HashSet<Object>(allMeta), is(equalTo(new HashSet<Object>(Arrays.asList("direct", "meta")))));
assertThat(new HashSet<>(allMeta), is(equalTo(new HashSet<Object>(Arrays.asList("direct", "meta")))));
allMeta = method.getAllAnnotationAttributes(DirectAnnotation.class.getName()).get("additional");
assertThat(new HashSet<Object>(allMeta), is(equalTo(new HashSet<Object>(Arrays.asList("direct")))));
assertThat(new HashSet<>(allMeta), is(equalTo(new HashSet<Object>(Arrays.asList("direct")))));
assertTrue(metadata.isAnnotated(IsAnnotatedAnnotation.class.getName()));
@@ -309,36 +309,36 @@ 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");
assertThat(new HashSet<Object>(allMeta), is(equalTo(new HashSet<Object>(Arrays.asList("direct", "meta")))));
assertThat(new HashSet<>(allMeta), is(equalTo(new HashSet<Object>(Arrays.asList("direct", "meta")))));
allMeta = metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName()).get("additional");
assertThat(new HashSet<Object>(allMeta), is(equalTo(new HashSet<Object>(Arrays.asList("direct")))));
assertThat(new HashSet<>(allMeta), is(equalTo(new HashSet<Object>(Arrays.asList("direct")))));
}
{ // perform tests with classValuesAsString = true
AnnotationAttributes specialAttrs = (AnnotationAttributes) metadata.getAnnotationAttributes(
@@ -365,9 +365,9 @@ public class AnnotationMetadataTests {
assertArrayEquals(new String[] { Void.class.getName() }, (String[]) optionalArray[0].get("classArray"));
assertArrayEquals(new String[] { Void.class.getName() }, optionalArray[0].getStringArray("classArray"));
assertEquals(metadata.getAnnotationAttributes(DirectAnnotation.class.getName()).get("value"), "direct");
assertEquals("direct", metadata.getAnnotationAttributes(DirectAnnotation.class.getName()).get("value"));
allMeta = metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName()).get("value");
assertThat(new HashSet<Object>(allMeta), is(equalTo(new HashSet<Object>(Arrays.asList("direct", "meta")))));
assertThat(new HashSet<>(allMeta), is(equalTo(new HashSet<Object>(Arrays.asList("direct", "meta")))));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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));
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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));
@@ -110,7 +110,7 @@ public class ObjectUtilsTests {
assertTrue(isEmpty(Collections.emptyList()));
assertTrue(isEmpty(Collections.emptySet()));
Set<String> set = new HashSet<String>();
Set<String> set = new HashSet<>();
set.add("foo");
assertFalse(isEmpty(set));
assertFalse(isEmpty(Arrays.asList("foo")));
@@ -120,7 +120,7 @@ public class ObjectUtilsTests {
public void isEmptyMap() {
assertTrue(isEmpty(Collections.emptyMap()));
HashMap<String, Object> map = new HashMap<String, Object>();
HashMap<String, Object> map = new HashMap<>();
map.put("foo", 42L);
assertFalse(isEmpty(map));
}
@@ -239,18 +239,21 @@ public class ObjectUtilsTests {
}
@Test
@Deprecated
public void hashCodeWithBooleanFalse() {
int expected = Boolean.FALSE.hashCode();
assertEquals(expected, ObjectUtils.hashCode(false));
}
@Test
@Deprecated
public void hashCodeWithBooleanTrue() {
int expected = Boolean.TRUE.hashCode();
assertEquals(expected, ObjectUtils.hashCode(true));
}
@Test
@Deprecated
public void hashCodeWithDouble() {
double dbl = 9830.43;
int expected = (new Double(dbl)).hashCode();
@@ -258,6 +261,7 @@ public class ObjectUtilsTests {
}
@Test
@Deprecated
public void hashCodeWithFloat() {
float flt = 34.8f;
int expected = (new Float(flt)).hashCode();
@@ -265,6 +269,7 @@ public class ObjectUtilsTests {
}
@Test
@Deprecated
public void hashCodeWithLong() {
long lng = 883l;
int expected = (new Long(lng)).hashCode();

View File

@@ -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);

View File

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

View File

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

View File

@@ -4936,7 +4936,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 {
@@ -5021,7 +5021,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@Override
public Class<?>[] getSpecificTargetClasses() {
return new Class[] {Map.class};
return new Class<?>[] {Map.class};
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,9 +70,9 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
public Inventor[] Members = new Inventor[1];
public List Members2 = new ArrayList();
public Map<String,Object> officers = new HashMap<String,Object>();
public Map<String,Object> officers = new HashMap<>();
public List<Map<String, Object>> reverse = new ArrayList<Map<String, Object>>();
public List<Map<String, Object>> reverse = new ArrayList<>();
@SuppressWarnings("unchecked")
IEEE() {
@@ -419,7 +419,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
@Test
public void testSpecialVariables() throws Exception {
// create an array of integers
List<Integer> primes = new ArrayList<Integer>();
List<Integer> primes = new ArrayList<>();
primes.addAll(Arrays.asList(2,3,5,7,11,13,17));
// create parser and set variable 'primes' as the array of integers
@@ -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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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];

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -93,8 +93,8 @@ 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;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -93,7 +93,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 =

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -368,8 +368,7 @@ public abstract class JdbcUtils {
@Override
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
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 +

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -165,7 +165,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();
@@ -340,7 +340,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
EntityManagerFactoryWithInfo mockEmf2 = mock(EntityManagerFactoryWithInfo.class);
Map<String, String> persistenceUnits = new HashMap<String, String>();
Map<String, String> persistenceUnits = new HashMap<>();
persistenceUnits.put("", "pu1");
persistenceUnits.put("Person", "pu2");
ExpectedLookupTemplate jt = new ExpectedLookupTemplate();
@@ -379,7 +379,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
public void testPersistenceUnitsFromJndiWithDefaultUnit() {
EntityManagerFactoryWithInfo mockEmf2 = mock(EntityManagerFactoryWithInfo.class);
Map<String, String> persistenceUnits = new HashMap<String, String>();
Map<String, String> persistenceUnits = new HashMap<>();
persistenceUnits.put("System", "pu1");
persistenceUnits.put("Person", "pu2");
ExpectedLookupTemplate jt = new ExpectedLookupTemplate();
@@ -407,7 +407,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
@Test
public void testSinglePersistenceUnitFromJndi() {
Map<String, String> persistenceUnits = new HashMap<String, String>();
Map<String, String> persistenceUnits = new HashMap<>();
persistenceUnits.put("Person", "pu1");
ExpectedLookupTemplate jt = new ExpectedLookupTemplate();
jt.addObject("java:comp/env/pu1", mockEmf);
@@ -436,10 +436,10 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
EntityManager mockEm2 = mock(EntityManager.class);
EntityManager mockEm3 = mock(EntityManager.class);
Map<String, String> persistenceContexts = new HashMap<String, String>();
Map<String, String> persistenceContexts = new HashMap<>();
persistenceContexts.put("", "pc1");
persistenceContexts.put("Person", "pc2");
Map<String, String> extendedPersistenceContexts = new HashMap<String, String>();
Map<String, String> extendedPersistenceContexts = new HashMap<>();
extendedPersistenceContexts .put("", "pc3");
ExpectedLookupTemplate jt = new ExpectedLookupTemplate();
jt.addObject("java:comp/env/pc1", mockEm);
@@ -476,10 +476,10 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
EntityManager mockEm2 = mock(EntityManager.class);
EntityManager mockEm3 = mock(EntityManager.class);
Map<String, String> persistenceContexts = new HashMap<String, String>();
Map<String, String> persistenceContexts = new HashMap<>();
persistenceContexts.put("System", "pc1");
persistenceContexts.put("Person", "pc2");
Map<String, String> extendedPersistenceContexts = new HashMap<String, String>();
Map<String, String> extendedPersistenceContexts = new HashMap<>();
extendedPersistenceContexts .put("System", "pc3");
ExpectedLookupTemplate jt = new ExpectedLookupTemplate();
jt.addObject("java:comp/env/pc1", mockEm);
@@ -516,9 +516,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
EntityManager mockEm = mock(EntityManager.class);
EntityManager mockEm2 = mock(EntityManager.class);
Map<String, String> persistenceContexts = new HashMap<String, String>();
Map<String, String> persistenceContexts = new HashMap<>();
persistenceContexts.put("System", "pc1");
Map<String, String> extendedPersistenceContexts = new HashMap<String, String>();
Map<String, String> extendedPersistenceContexts = new HashMap<>();
extendedPersistenceContexts .put("System", "pc2");
ExpectedLookupTemplate jt = new ExpectedLookupTemplate();
jt.addObject("java:comp/env/pc1", mockEm);
@@ -896,4 +896,5 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
throw new IllegalStateException();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,7 +87,7 @@ public class CastorUnmarshallerTests extends AbstractUnmarshallerTests<CastorMar
@Test
public void unmarshalTargetClass() throws Exception {
CastorMarshaller unmarshaller = new CastorMarshaller();
unmarshaller.setTargetClasses(new Class[] {Flights.class});
unmarshaller.setTargetClasses(Flights.class);
unmarshaller.afterPropertiesSet();
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
Object flights = unmarshaller.unmarshal(source);
@@ -98,7 +98,7 @@ public class CastorUnmarshallerTests extends AbstractUnmarshallerTests<CastorMar
public void setBothTargetClassesAndMapping() throws IOException {
CastorMarshaller unmarshaller = new CastorMarshaller();
unmarshaller.setMappingLocation(new ClassPathResource("order-mapping.xml", CastorMarshaller.class));
unmarshaller.setTargetClasses(new Class[] {Order.class});
unmarshaller.setTargetClasses(Order.class);
unmarshaller.afterPropertiesSet();
String xml = "<order>" +
@@ -181,7 +181,6 @@ public class CastorUnmarshallerTests extends AbstractUnmarshallerTests<CastorMar
}
@Test
@Ignore("Fails on the build server for some reason")
public void clearCollectionsFalse() throws Exception {
Flights flights = new Flights();
flights.setFlight(new Flight[] {new Flight(), null});
@@ -190,15 +189,14 @@ public class CastorUnmarshallerTests extends AbstractUnmarshallerTests<CastorMar
Object result = unmarshalFlights();
assertSame("Result Flights is different object.", flights, result);
assertEquals("Result Flights has incorrect number of Flight.", 3, ((Flights) result).getFlightCount());
assertNull("Flight shouldn't have number.", flights.getFlight(0).getNumber());
assertEquals("Result Flights has incorrect number of Flights.", 3, ((Flights) result).getFlightCount());
assertNull("Null Flight was expected.", flights.getFlight()[1]);
testFlight(flights.getFlight()[2]);
}
@Test
public void unmarshalStreamSourceWithXmlOptions() throws Exception {
final AtomicReference<XMLReader> result = new AtomicReference<XMLReader>();
final AtomicReference<XMLReader> result = new AtomicReference<>();
CastorMarshaller marshaller = new CastorMarshaller() {
@Override
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) {
@@ -225,7 +223,7 @@ public class CastorUnmarshallerTests extends AbstractUnmarshallerTests<CastorMar
@Test
public void unmarshalSaxSourceWithXmlOptions() throws Exception {
final AtomicReference<XMLReader> result = new AtomicReference<XMLReader>();
final AtomicReference<XMLReader> result = new AtomicReference<>();
CastorMarshaller marshaller = new CastorMarshaller() {
@Override
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,12 +36,12 @@ import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.extended.EncodedByteArrayConverter;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
import com.thoughtworks.xstream.io.json.JsonWriter;
import org.custommonkey.xmlunit.XMLAssert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -54,10 +54,7 @@ import org.xml.sax.ContentHandler;
import org.springframework.util.xml.StaxUtils;
import static org.custommonkey.xmlunit.XMLAssert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
@@ -71,16 +68,18 @@ public class XStreamMarshallerTests {
private Flight flight;
@Before
public void createMarshaller() throws Exception {
public void createMarshaller() {
marshaller = new XStreamMarshaller();
Map<String, String> aliases = new HashMap<String, String>();
Map<String, String> aliases = new HashMap<>();
aliases.put("flight", Flight.class.getName());
marshaller.setAliases(aliases);
flight = new Flight();
flight.setFlightNumber(42L);
}
@Test
public void marshalDOMResult() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
@@ -95,7 +94,7 @@ public class XStreamMarshallerTests {
flightElement.appendChild(numberElement);
Text text = expected.createTextNode("42");
numberElement.appendChild(text);
assertXMLEqual("Marshaller writes invalid DOMResult", expected, document);
XMLAssert.assertXMLEqual("Marshaller writes invalid DOMResult", expected, document);
}
// see SWS-392
@@ -124,7 +123,7 @@ public class XStreamMarshallerTests {
eFlightElement.appendChild(eNumberElement);
Text text = expected.createTextNode("42");
eNumberElement.appendChild(text);
assertXMLEqual("Marshaller writes invalid DOMResult", expected, existent);
XMLAssert.assertXMLEqual("Marshaller writes invalid DOMResult", expected, existent);
}
@Test
@@ -132,7 +131,7 @@ public class XStreamMarshallerTests {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
marshaller.marshal(flight, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
XMLAssert.assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
@@ -141,7 +140,7 @@ public class XStreamMarshallerTests {
StreamResult result = new StreamResult(os);
marshaller.marshal(flight, result);
String s = new String(os.toByteArray(), "UTF-8");
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, s);
XMLAssert.assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, s);
}
@Test
@@ -166,7 +165,7 @@ public class XStreamMarshallerTests {
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
Result result = StaxUtils.createStaxResult(streamWriter);
marshaller.marshal(flight, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
XMLAssert.assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
@@ -176,16 +175,16 @@ public class XStreamMarshallerTests {
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
Result result = StaxUtils.createStaxResult(eventWriter);
marshaller.marshal(flight, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
XMLAssert.assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void converters() throws Exception {
marshaller.setConverters(new Converter[]{new EncodedByteArrayConverter()});
marshaller.setConverters(new EncodedByteArrayConverter());
byte[] buf = new byte[]{0x1, 0x2};
Writer writer = new StringWriter();
marshaller.marshal(buf, new StreamResult(writer));
assertXMLEqual("<byte-array>AQI=</byte-array>", writer.toString());
XMLAssert.assertXMLEqual("<byte-array>AQI=</byte-array>", writer.toString());
Reader reader = new StringReader(writer.toString());
byte[] bufResult = (byte[]) marshaller.unmarshal(new StreamSource(reader));
assertTrue("Invalid result", Arrays.equals(buf, bufResult));
@@ -193,11 +192,11 @@ public class XStreamMarshallerTests {
@Test
public void useAttributesFor() throws Exception {
marshaller.setUseAttributeForTypes(new Class[]{Long.TYPE});
marshaller.setUseAttributeForTypes(Long.TYPE);
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
String expected = "<flight flightNumber=\"42\" />";
assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
XMLAssert.assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
}
@Test
@@ -206,7 +205,7 @@ public class XStreamMarshallerTests {
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
String expected = "<flight flightNumber=\"42\" />";
assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
XMLAssert.assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
}
@Test
@@ -215,23 +214,22 @@ public class XStreamMarshallerTests {
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
String expected = "<flight flightNumber=\"42\" />";
assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
XMLAssert.assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
}
@Test
public void useAttributesForClassStringListMap() throws Exception {
marshaller
.setUseAttributeFor(Collections.singletonMap(Flight.class, Collections.singletonList("flightNumber")));
marshaller.setUseAttributeFor(Collections.singletonMap(Flight.class, Collections.singletonList("flightNumber")));
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
String expected = "<flight flightNumber=\"42\" />";
assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
XMLAssert.assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
}
@Test
@Ignore("Fails on JDK 8 build 108")
public void aliasesByTypeStringClassMap() throws Exception {
Map<String, Class<?>> aliases = new HashMap<String, Class<?>>();
Map<String, Class<?>> aliases = new HashMap<>();
aliases.put("flight", Flight.class);
FlightSubclass flight = new FlightSubclass();
flight.setFlightNumber(42);
@@ -239,13 +237,13 @@ public class XStreamMarshallerTests {
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
assertXMLEqual("Marshaller does not use attributes", EXPECTED_STRING, writer.toString());
XMLAssert.assertXMLEqual("Marshaller does not use attributes", EXPECTED_STRING, writer.toString());
}
@Test
@Ignore("Fails on JDK 8 build 108")
public void aliasesByTypeStringStringMap() throws Exception {
Map<String, String> aliases = new HashMap<String, String>();
Map<String, String> aliases = new HashMap<>();
aliases.put("flight", Flight.class.getName());
FlightSubclass flight = new FlightSubclass();
flight.setFlightNumber(42);
@@ -253,7 +251,7 @@ public class XStreamMarshallerTests {
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
assertXMLEqual("Marshaller does not use attributes", EXPECTED_STRING, writer.toString());
XMLAssert.assertXMLEqual("Marshaller does not use attributes", EXPECTED_STRING, writer.toString());
}
@Test
@@ -262,7 +260,7 @@ public class XStreamMarshallerTests {
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
String expected = "<flight><flightNo>42</flightNo></flight>";
assertXMLEqual("Marshaller does not use aliases", expected, writer.toString());
XMLAssert.assertXMLEqual("Marshaller does not use aliases", expected, writer.toString());
}
@Test
@@ -272,7 +270,7 @@ public class XStreamMarshallerTests {
marshaller.setOmittedFields(omittedFieldsMap);
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
assertXpathNotExists("/flight/flightNumber", writer.toString());
XMLAssert.assertXpathNotExists("/flight/flightNumber", writer.toString());
}
@Test
@@ -282,7 +280,7 @@ public class XStreamMarshallerTests {
flights.getFlights().add(flight);
flights.getStrings().add("42");
Map<String, Class<?>> aliases = new HashMap<String, Class<?>>();
Map<String, Class<?>> aliases = new HashMap<>();
aliases.put("flight", Flight.class);
aliases.put("flights", Flights.class);
marshaller.setAliases(aliases);
@@ -293,10 +291,10 @@ public class XStreamMarshallerTests {
Writer writer = new StringWriter();
marshaller.marshal(flights, new StreamResult(writer));
String result = writer.toString();
assertXpathNotExists("/flights/flights", result);
assertXpathExists("/flights/flight", result);
assertXpathNotExists("/flights/strings", result);
assertXpathExists("/flights/string", result);
XMLAssert.assertXpathNotExists("/flights/flights", result);
XMLAssert.assertXpathExists("/flights/flight", result);
XMLAssert.assertXpathNotExists("/flights/strings", result);
XMLAssert.assertXpathExists("/flights/string", result);
}
@Test
@@ -337,8 +335,7 @@ public class XStreamMarshallerTests {
flight.setFlightNumber(42);
marshaller.marshal(flight, result);
String expected = "<flight><number>42</number></flight>";
assertXMLEqual("Marshaller writes invalid StreamResult", expected, writer.toString());
XMLAssert.assertXMLEqual("Marshaller writes invalid StreamResult", expected, writer.toString());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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 {
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,8 +30,6 @@ import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.util.MetaAnnotationUtils.AnnotationDescriptor;
import org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.Assert.*;
@@ -46,19 +44,21 @@ import static org.springframework.test.util.MetaAnnotationUtils.*;
*/
public class MetaAnnotationUtilsTests {
private void assertAtComponentOnComposedAnnotation(Class<?> rootDeclaringClass, String name,
Class<? extends Annotation> composedAnnotationType) {
private void assertAtComponentOnComposedAnnotation(
Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, name, composedAnnotationType);
}
private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass, String name,
Class<? extends Annotation> composedAnnotationType) {
assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, composedAnnotationType, name,
composedAnnotationType);
private void assertAtComponentOnComposedAnnotation(
Class<?> startClass, Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
assertAtComponentOnComposedAnnotation(startClass, rootDeclaringClass, composedAnnotationType, name, composedAnnotationType);
}
private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass,
Class<?> declaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(startClass, Component.class);
assertNotNull("AnnotationDescriptor should not be null", descriptor);
assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass());
@@ -69,25 +69,29 @@ public class MetaAnnotationUtilsTests {
assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType());
}
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass, String name,
Class<? extends Annotation> composedAnnotationType) {
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, name,
composedAnnotationType);
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
Class<?> startClass, String name, Class<? extends Annotation> composedAnnotationType) {
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
startClass, startClass, name, composedAnnotationType);
}
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass,
Class<?> rootDeclaringClass, String name, Class<? extends Annotation> 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<? extends Annotation> composedAnnotationType) {
Class<Component> 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());
@@ -98,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<Transactional> descriptor;
descriptor = findAnnotationDescriptor(InheritedAnnotationInterface.class, Transactional.class);
AnnotationDescriptor<Transactional> descriptor =
findAnnotationDescriptor(InheritedAnnotationInterface.class, Transactional.class);
assertNotNull(descriptor);
assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass());
@@ -139,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<Order> descriptor;
descriptor = findAnnotationDescriptor(NonInheritedAnnotationInterface.class, Order.class);
AnnotationDescriptor<Order> descriptor =
findAnnotationDescriptor(NonInheritedAnnotationInterface.class, Order.class);
assertNotNull(descriptor);
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass());
@@ -168,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<Component> annotationType = Component.class;
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(HasLocalAndMetaComponentAnnotation.class,
annotationType);
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(
HasLocalAndMetaComponentAnnotation.class, annotationType);
assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass());
assertEquals(annotationType, descriptor.getAnnotationType());
assertNull(descriptor.getComposedAnnotation());
@@ -190,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<Component> descriptor =
findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class);
AnnotationDescriptor<Component> descriptor;
descriptor = findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class);
assertNotNull(descriptor);
assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass());
assertEquals(Meta1.class, descriptor.getDeclaringClass());
@@ -206,7 +207,7 @@ public class MetaAnnotationUtilsTests {
@Test
public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndAnnotatedSuperclass() {
AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(
MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, ContextConfiguration.class);
MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, ContextConfiguration.class);
assertNotNull("AnnotationDescriptor should not be null", descriptor);
assertEquals("rootDeclaringClass", MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, descriptor.getRootDeclaringClass());
@@ -215,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);
}
/**
@@ -255,8 +255,8 @@ public class MetaAnnotationUtilsTests {
@Test
public void findAnnotationDescriptorOnAnnotatedClassWithMissingTargetMetaAnnotation() {
// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(InheritedAnnotationClass.class,
Component.class);
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(
InheritedAnnotationClass.class, Component.class);
assertNull("Should not find @Component on InheritedAnnotationClass", descriptor);
}
@@ -265,8 +265,8 @@ public class MetaAnnotationUtilsTests {
*/
@Test
public void findAnnotationDescriptorOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(MetaCycleAnnotatedClass.class,
Component.class);
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(
MetaCycleAnnotatedClass.class, Component.class);
assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor);
}
@@ -274,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());
@@ -320,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());
@@ -351,10 +348,10 @@ public class MetaAnnotationUtilsTests {
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() throws Exception {
public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() {
Class<Component> 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());
@@ -362,45 +359,45 @@ public class MetaAnnotationUtilsTests {
}
@Test
public void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() throws Exception {
public void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() {
Class<HasMetaComponentAnnotation> startClass = HasMetaComponentAnnotation.class;
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, "meta1", Meta1.class);
}
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() throws Exception {
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() {
Class<?> startClass = MetaConfigWithDefaultAttributesTestCase.class;
Class<ContextConfiguration> 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<ContextConfiguration> 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());
}
@@ -414,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());
@@ -437,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);
}
/**
@@ -447,8 +442,8 @@ public class MetaAnnotationUtilsTests {
@Test
public void findAnnotationDescriptorForTypesOnMetaMetaAnnotatedClass() {
Class<MetaMetaAnnotatedClass> startClass = MetaMetaAnnotatedClass.class;
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, Meta2.class, "meta2",
MetaMeta.class);
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
startClass, startClass, Meta2.class, "meta2", MetaMeta.class);
}
/**
@@ -457,8 +452,8 @@ public class MetaAnnotationUtilsTests {
@Test
public void findAnnotationDescriptorForTypesOnMetaMetaMetaAnnotatedClass() {
Class<MetaMetaMetaAnnotatedClass> startClass = MetaMetaMetaAnnotatedClass.class;
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, Meta2.class, "meta2",
MetaMetaMeta.class);
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
startClass, startClass, Meta2.class, "meta2", MetaMetaMeta.class);
}
/**
@@ -469,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);
}
@@ -480,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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("equals", new Class[] { Object.class }),
TransactionDefinition.PROPAGATION_MANDATORY);
checkTransactionProperties(tas, Object.class.getMethod("wait", (Class[]) null),
TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("wait", new Class[] { long.class }),
TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("wait", new Class[] { long.class, int.class }),
TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("notify", (Class[]) null),
TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("notifyAll", (Class[]) null),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("toString", (Class[]) null), -1);
checkTransactionProperties(tas, Object.class.getMethod("hashCode"),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class),
TransactionDefinition.PROPAGATION_MANDATORY);
checkTransactionProperties(tas, Object.class.getMethod("wait"),
TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("wait", long.class),
TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("wait", long.class, int.class),
TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("notify"),
TransactionDefinition.PROPAGATION_SUPPORTS);
checkTransactionProperties(tas, Object.class.getMethod("notifyAll"),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("toString"), -1);
}
@Test
@@ -84,22 +84,22 @@ public class TransactionAttributeSourceEditorTests {
editor.setAsText("java.lang.Object.*=PROPAGATION_REQUIRED");
TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue();
checkTransactionProperties(tas, Object.class.getMethod("hashCode", (Class[]) null),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("equals", new Class[] { Object.class }),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("wait", (Class[]) null),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("wait", new Class[] { long.class }),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("wait", new Class[] { long.class, int.class }),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("notify", (Class[]) null),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("notifyAll", (Class[]) null),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("toString", (Class[]) null),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("hashCode"),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("wait"),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("wait", long.class),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("wait", long.class, int.class),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("notify"),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("notifyAll"),
TransactionDefinition.PROPAGATION_REQUIRED);
checkTransactionProperties(tas, Object.class.getMethod("toString"),
TransactionDefinition.PROPAGATION_REQUIRED);
}
private void checkTransactionProperties(TransactionAttributeSource tas, Method method, int propagationBehavior) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,19 +35,17 @@ import static org.junit.Assert.*;
* @since 15.10.2003
* @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
*/
public final class TransactionAttributeSourceTests {
public class TransactionAttributeSourceTests {
@Test
public void matchAlwaysTransactionAttributeSource() throws Exception {
MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource();
TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null);
TransactionAttribute ta = tas.getTransactionAttribute(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);
ta = tas.getTransactionAttribute(IOException.class.getMethod("getMessage"), IOException.class);
assertNotNull(ta);
assertTrue(TransactionDefinition.PROPAGATION_SUPPORTS == ta.getPropagationBehavior());
}
@@ -63,54 +61,46 @@ public final class TransactionAttributeSourceTests {
}
@Test
public void nameMatchTransactionAttributeSourceWithStarAtStartOfMethodName()
throws NoSuchMethodException {
public void nameMatchTransactionAttributeSourceWithStarAtStartOfMethodName() throws Exception {
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
Properties attributes = new Properties();
attributes.put("*ashCode", "PROPAGATION_REQUIRED");
tas.setProperties(attributes);
TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null);
TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null);
assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior());
}
@Test
public void nameMatchTransactionAttributeSourceWithStarAtEndOfMethodName()
throws NoSuchMethodException {
public void nameMatchTransactionAttributeSourceWithStarAtEndOfMethodName() throws Exception {
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
Properties attributes = new Properties();
attributes.put("hashCod*", "PROPAGATION_REQUIRED");
tas.setProperties(attributes);
TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null);
TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null);
assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior());
}
@Test
public void nameMatchTransactionAttributeSourceMostSpecificMethodNameIsDefinitelyMatched()
throws NoSuchMethodException {
public void nameMatchTransactionAttributeSourceMostSpecificMethodNameIsDefinitelyMatched() throws Exception {
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
Properties attributes = new Properties();
attributes.put("*", "PROPAGATION_REQUIRED");
attributes.put("hashCode", "PROPAGATION_MANDATORY");
tas.setProperties(attributes);
TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null);
TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null);
assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_MANDATORY, ta.getPropagationBehavior());
}
@Test
public void nameMatchTransactionAttributeSourceWithEmptyMethodName()
throws NoSuchMethodException {
public void nameMatchTransactionAttributeSourceWithEmptyMethodName() throws Exception {
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
Properties attributes = new Properties();
attributes.put("", "PROPAGATION_MANDATORY");
tas.setProperties(attributes);
TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null);
TransactionAttribute ta = tas.getTransactionAttribute(Object.class.getMethod("hashCode"), null);
assertNull(ta);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,6 +46,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();
@@ -75,6 +76,7 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests
return pf.getProxy();
}
/**
* A TransactionInterceptor should be serializable if its
* PlatformTransactionManager is.
@@ -108,7 +110,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);
@@ -254,8 +256,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);
@@ -316,6 +320,6 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests
public void rollback(TransactionStatus status) throws TransactionException {
throw new UnsupportedOperationException();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,7 +76,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("Handler not mapped - ModelAndView should be null", mav);
}
@@ -146,7 +146,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());
@@ -156,7 +156,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());
@@ -176,7 +176,7 @@ public class SimpleMappingExceptionResolverTests {
public void simpleExceptionMappingWithHandlerSpecifiedButWrongHandlerClass() {
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("Handler not mapped - ModelAndView should be null", mav);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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<String> responseAdvice = Mockito.mock(ResponseBodyAdvice.class);
List<Object> 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<String> responseAdvice = Mockito.mock(ResponseBodyAdvice.class);
List<Object> 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<String> {
@@ -182,6 +180,7 @@ public class RequestResponseBodyAdviceChainTests {
}
}
@SuppressWarnings("unused")
@ResponseBody
public String handle(String body) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -94,7 +94,7 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry {
WebSocketHandler actual = WebSocketHandlerDecorator.unwrap(handler);
if (!(actual instanceof SubProtocolWebSocketHandler)) {
throw new IllegalArgumentException("No SubProtocolWebSocketHandler in " + handler);
};
}
return (SubProtocolWebSocketHandler) actual;
}

View File

@@ -1052,7 +1052,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);

View File

@@ -313,13 +313,13 @@ Note that we can achieve the same with java-based configurations:
@Override
protected Class<?>[] getRootConfigClasses() {
// GolfingAppConfig defines beans that would be in root-context.xml
return new Class[] { GolfingAppConfig.class };
return new Class<?>[] { GolfingAppConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
// GolfingWebConfig defines beans that would be in golfing-servlet.xml
return new Class[] { GolfingWebConfig.class };
return new Class<?>[] { GolfingWebConfig.class };
}
@Override
@@ -4702,7 +4702,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