From 29e8ba3efcf80734c4376d1388b2d79c9179898d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 26 Jul 2016 00:03:21 +0200 Subject: [PATCH] Polishing (cherry picked from commit cc93c2a) --- .../org/springframework/tests/Assume.java | 50 ++++--------------- .../interceptor/TransactionAspectSupport.java | 16 +++--- 2 files changed, 17 insertions(+), 49 deletions(-) diff --git a/spring-core/src/test/java/org/springframework/tests/Assume.java b/spring-core/src/test/java/org/springframework/tests/Assume.java index e7923851a5..2b629eaf8a 100644 --- a/spring-core/src/test/java/org/springframework/tests/Assume.java +++ b/spring-core/src/test/java/org/springframework/tests/Assume.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.lang.reflect.Method; import java.util.Set; import org.apache.commons.logging.Log; - import org.junit.AssumptionViolatedException; import org.springframework.util.ClassUtils; @@ -33,38 +32,8 @@ import static org.junit.Assume.*; * conditions hold {@code true}. If the assumption fails, it means the test should be * skipped. * - *

For example, if a set of tests require at least JDK 1.7 it can use - * {@code Assume#atLeast(JavaVersion.JAVA_17)} as shown below: - * - *

- * public void MyTests {
- *
- *   @BeforeClass
- *   public static void assumptions() {
- *       Assume.atLeast(JavaVersion.JAVA_17);
- *   }
- *
- *   // ... all the test methods that require at least JDK 1.7
- * }
- * 
- * - * If only a single test requires at least JDK 1.7 it can use the - * {@code Assume#atLeast(JavaVersion.JAVA_17)} as shown below: - * - *
- * public void MyTests {
- *
- *   @Test
- *   public void requiresJdk17 {
- *       Assume.atLeast(JavaVersion.JAVA_17);
- *       // ... perform the actual test
- *   }
- * }
- * 
- * - * In addition to assumptions based on the JDK version, tests can be categorized into - * {@link TestGroup}s. Active groups are enabled using the 'testGroups' system property, - * usually activated from the gradle command line: + * Tests can be categorized into {@link TestGroup}s. Active groups are enabled using + * the 'testGroups' system property, usually activated from the gradle command line: *
  * gradle test -PtestGroups="performance"
  * 
@@ -76,7 +45,6 @@ import static org.junit.Assume.*; * @author Phillip Webb * @author Sam Brannen * @since 3.2 - * @see #atLeast(JavaVersion) * @see #group(TestGroup) * @see #group(TestGroup, Executable) */ @@ -92,8 +60,8 @@ public abstract class Assume { */ public static void atLeast(JavaVersion version) { if (!JavaVersion.runningVersion().isAtLeast(version)) { - throw new AssumptionViolatedException("Requires JDK " + version + " but running " - + JavaVersion.runningVersion()); + throw new AssumptionViolatedException("Requires JDK " + version + " but running " + + JavaVersion.runningVersion()); } } @@ -104,8 +72,7 @@ public abstract class Assume { */ public static void group(TestGroup group) { if (!GROUPS.contains(group)) { - throw new AssumptionViolatedException("Requires unspecified group " + group - + " from " + GROUPS); + throw new AssumptionViolatedException("Requires unspecified group " + group + " from " + GROUPS); } } @@ -154,11 +121,12 @@ public abstract class Assume { } } + /** * @since 4.2 */ - @FunctionalInterface - public static interface Executable { + public interface Executable { + void execute() throws Exception; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java index 6888d46f03..3c22b2ec56 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.transaction.interceptor; import java.lang.reflect.Method; +import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; @@ -85,7 +86,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init new NamedThreadLocal("Current aspect-driven transaction"); - private final ConcurrentHashMap transactionManagerCache = + private final Map transactionManagerCache = new ConcurrentHashMap(); /** @@ -243,7 +244,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init public void afterPropertiesSet() { if (getTransactionManager() == null && this.beanFactory == null) { throw new IllegalStateException( - "Setting the property 'transactionManager' or running in a ListableBeanFactory is required"); + "Setting the property 'transactionManager' or running in a BeanFactory is required"); } if (this.transactionAttributeSource == null) { throw new IllegalStateException( @@ -449,17 +450,16 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init TransactionInfo txInfo = new TransactionInfo(tm, txAttr, joinpointIdentification); if (txAttr != null) { - // We need a transaction for this method + // We need a transaction for this method... if (logger.isTraceEnabled()) { logger.trace("Getting transaction for [" + txInfo.getJoinpointIdentification() + "]"); } - // The transaction manager will flag an error if an incompatible tx already exists + // The transaction manager will flag an error if an incompatible tx already exists. txInfo.newTransactionStatus(status); } else { - // The TransactionInfo.hasTransaction() method will return - // false. We created it only to preserve the integrity of - // the ThreadLocal stack maintained in this class. + // The TransactionInfo.hasTransaction() method will return false. We created it only + // to preserve the integrity of the ThreadLocal stack maintained in this class. if (logger.isTraceEnabled()) logger.trace("Don't need to create transaction for [" + joinpointIdentification + "]: This method isn't transactional.");