Consistent Class array vs vararg declarations (and related polishing)

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

View File

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

View File

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

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