Browse Source

Polishing

pull/931/head
Juergen Hoeller 9 years ago
parent
commit
1239595672
  1. 44
      spring-beans/src/main/java/org/springframework/beans/factory/config/PlaceholderConfigurerSupport.java
  2. 12
      spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java
  3. 9
      spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheManagerTests.java
  4. 11
      spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheCacheManagerTests.java
  5. 16
      spring-context-support/src/test/java/org/springframework/cache/transaction/AbstractTransactionSupportingCacheManagerTests.java
  6. 15
      spring-context/src/main/java/org/springframework/cache/support/AbstractCacheManager.java
  7. 4
      spring-context/src/main/java/org/springframework/scripting/ScriptEvaluator.java
  8. 32
      spring-test/src/main/java/org/springframework/test/context/junit4/statements/RunAfterTestClassCallbacks.java
  9. 38
      spring-test/src/main/java/org/springframework/test/context/junit4/statements/RunAfterTestMethodCallbacks.java
  10. 16
      spring-test/src/main/java/org/springframework/test/context/junit4/statements/RunBeforeTestClassCallbacks.java
  11. 16
      spring-test/src/main/java/org/springframework/test/context/junit4/statements/RunBeforeTestMethodCallbacks.java
  12. 43
      spring-test/src/main/java/org/springframework/test/context/junit4/statements/SpringFailOnTimeout.java
  13. 23
      spring-test/src/main/java/org/springframework/test/context/junit4/statements/SpringRepeat.java
  14. 2
      spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java

44
spring-beans/src/main/java/org/springframework/beans/factory/config/PlaceholderConfigurerSupport.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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,33 +30,33 @@ import org.springframework.util.StringValueResolver; @@ -30,33 +30,33 @@ import org.springframework.util.StringValueResolver;
*
* <p>The default placeholder syntax follows the Ant / Log4J / JSP EL style:
*
*<pre class="code">${...}</pre>
* <pre class="code">${...}</pre>
*
* Example XML bean definition:
*
*<pre class="code">{@code
*<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"/>
* <property name="driverClassName" value="}${driver}{@code "/>
* <property name="url" value="jdbc:}${dbname}{@code "/>
*</bean>
*}</pre>
* <pre class="code">
* <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"/>
* <property name="driverClassName" value="${driver}"/>
* <property name="url" value="jdbc:${dbname}"/>
* </bean>
* </pre>
*
* Example properties file:
*
* <pre class="code"> driver=com.mysql.jdbc.Driver
* <pre class="code">driver=com.mysql.jdbc.Driver
* dbname=mysql:mydb</pre>
*
* Annotated bean definitions may take advantage of property replacement using
* the {@link org.springframework.beans.factory.annotation.Value @Value} annotation:
*
*<pre class="code">@Value("${person.age}")</pre>
* <pre class="code">@Value("${person.age}")</pre>
*
* Implementations check simple property values, lists, maps, props, and bean names
* in bean references. Furthermore, placeholder values can also cross-reference
* other placeholders, like:
*
*<pre class="code">rootPath=myrootdir
*subPath=${rootPath}/subdir</pre>
* <pre class="code">rootPath=myrootdir
* subPath=${rootPath}/subdir</pre>
*
* In contrast to {@link PropertyOverrideConfigurer}, subclasses of this type allow
* filling in of explicit placeholders in bean definitions.
@ -75,9 +75,9 @@ import org.springframework.util.StringValueResolver; @@ -75,9 +75,9 @@ import org.springframework.util.StringValueResolver;
*
* <p>Example XML property with default value:
*
*<pre class="code">{@code
* <property name="url" value="jdbc:}${dbname:defaultdb}{@code "/>
*}</pre>
* <pre class="code">
* <property name="url" value="jdbc:${dbname:defaultdb}"/>
* </pre>
*
* @author Chris Beams
* @author Juergen Hoeller
@ -107,14 +107,14 @@ public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfi @@ -107,14 +107,14 @@ public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfi
/** Defaults to {@value #DEFAULT_VALUE_SEPARATOR} */
protected String valueSeparator = DEFAULT_VALUE_SEPARATOR;
protected boolean ignoreUnresolvablePlaceholders = false;
protected String nullValue;
private BeanFactory beanFactory;
protected boolean ignoreUnresolvablePlaceholders = false;
private String beanName;
private BeanFactory beanFactory;
/**
* Set the prefix that a placeholder string starts with.
@ -143,13 +143,13 @@ public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfi @@ -143,13 +143,13 @@ public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfi
}
/**
* Set a value that should be treated as {@code null} when
* resolved as a placeholder value: e.g. "" (empty String) or "null".
* Set a value that should be treated as {@code null} when resolved
* as a placeholder value: e.g. "" (empty String) or "null".
* <p>Note that this will only apply to full property values,
* not to parts of concatenated values.
* <p>By default, no such null value is defined. This means that
* there is no way to express {@code null} as a property
* value unless you explicitly map a corresponding value here.
* there is no way to express {@code null} as a property value
* unless you explicitly map a corresponding value here.
*/
public void setNullValue(String nullValue) {
this.nullValue = nullValue;

12
spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -24,7 +24,6 @@ import net.sf.ehcache.Status; @@ -24,7 +24,6 @@ import net.sf.ehcache.Status;
import org.springframework.cache.Cache;
import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager;
import org.springframework.util.Assert;
/**
* CacheManager backed by an EhCache {@link net.sf.ehcache.CacheManager}.
@ -81,8 +80,10 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag @@ -81,8 +80,10 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag
@Override
protected Collection<Cache> loadCaches() {
Status status = getCacheManager().getStatus();
Assert.isTrue(Status.STATUS_ALIVE.equals(status),
"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
if (!Status.STATUS_ALIVE.equals(status)) {
throw new IllegalStateException(
"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
}
String[] names = getCacheManager().getCacheNames();
Collection<Cache> caches = new LinkedHashSet<Cache>(names.length);
@ -94,8 +95,7 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag @@ -94,8 +95,7 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag
@Override
protected Cache getMissingCache(String name) {
// check the EhCache cache again
// (in case the cache was added at runtime)
// Check the EhCache cache again (in case the cache was added at runtime)
Ehcache ehcache = getCacheManager().getEhcache(name);
if (ehcache != null) {
return new EhCacheCache(ehcache);

9
spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheManagerTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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,9 +30,12 @@ import org.springframework.cache.transaction.AbstractTransactionSupportingCacheM @@ -30,9 +30,12 @@ import org.springframework.cache.transaction.AbstractTransactionSupportingCacheM
public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCacheManagerTests<EhCacheCacheManager> {
private CacheManager nativeCacheManager;
private EhCacheCacheManager cacheManager;
private EhCacheCacheManager transactionalCacheManager;
@Before
public void setup() {
nativeCacheManager = new CacheManager(new Configuration().name("EhCacheCacheManagerTests")
@ -58,7 +61,8 @@ public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCache @@ -58,7 +61,8 @@ public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCache
protected EhCacheCacheManager getCacheManager(boolean transactionAware) {
if (transactionAware) {
return transactionalCacheManager;
} else {
}
else {
return cacheManager;
}
}
@ -77,4 +81,5 @@ public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCache @@ -77,4 +81,5 @@ public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCache
protected void removeNativeCache(String cacheName) {
nativeCacheManager.removeCache(cacheName);
}
}

11
spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheCacheManagerTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -33,9 +33,12 @@ import static org.mockito.BDDMockito.*; @@ -33,9 +33,12 @@ import static org.mockito.BDDMockito.*;
public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheManagerTests<JCacheCacheManager> {
private CacheManagerMock cacheManagerMock;
private JCacheCacheManager cacheManager;
private JCacheCacheManager transactionalCacheManager;
@Before
public void setupOnce() {
cacheManagerMock = new CacheManagerMock();
@ -55,7 +58,8 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM @@ -55,7 +58,8 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM
protected JCacheCacheManager getCacheManager(boolean transactionAware) {
if (transactionAware) {
return transactionalCacheManager;
} else {
}
else {
return cacheManager;
}
}
@ -75,9 +79,11 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM @@ -75,9 +79,11 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM
cacheManagerMock.removeCache(cacheName);
}
private static class CacheManagerMock {
private final List<String> cacheNames;
private final CacheManager cacheManager;
private CacheManagerMock() {
@ -103,4 +109,5 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM @@ -103,4 +109,5 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM
given(cacheManager.getCache(name)).willReturn(null);
}
}
}

16
spring-context-support/src/test/java/org/springframework/cache/transaction/AbstractTransactionSupportingCacheManagerTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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,11 +42,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C @@ -42,11 +42,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
/**
* Returns the {@link CacheManager} to use.
*
* @param transactionAware if the requested cache manager should be aware
* of the transaction
* @return the cache manager to use
* @see org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager#setTransactionAware(boolean)
* @see org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager#setTransactionAware
*/
protected abstract T getCacheManager(boolean transactionAware);
@ -65,6 +64,7 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C @@ -65,6 +64,7 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
*/
protected abstract void removeNativeCache(String cacheName);
@Test
public void getOnExistingCache() {
assertThat(getCacheManager(false).getCache(CACHE_NAME), is(instanceOf(getCacheType())));
@ -77,10 +77,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C @@ -77,10 +77,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
addNativeCache(cacheName);
assertFalse(cacheManager.getCacheNames().contains(cacheName));
try {
assertThat(cacheManager.getCache(cacheName),
is(instanceOf(getCacheType())));
assertThat(cacheManager.getCache(cacheName), is(instanceOf(getCacheType())));
assertTrue(cacheManager.getCacheNames().contains(cacheName));
} finally {
}
finally {
removeNativeCache(cacheName);
}
}
@ -109,8 +109,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C @@ -109,8 +109,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
assertThat(cacheManager.getCache(cacheName),
is(instanceOf(TransactionAwareCacheDecorator.class)));
assertTrue(cacheManager.getCacheNames().contains(cacheName));
} finally {
}
finally {
removeNativeCache(cacheName);
}
}
}

15
spring-context/src/main/java/org/springframework/cache/support/AbstractCacheManager.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -40,7 +40,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing @@ -40,7 +40,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
private final ConcurrentMap<String, Cache> cacheMap = new ConcurrentHashMap<String, Cache>(16);
private Set<String> cacheNames = new LinkedHashSet<String>(16);
private final Set<String> cacheNames = new LinkedHashSet<String>(16);
// Early cache initialization on startup
@ -96,6 +96,16 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing @@ -96,6 +96,16 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
this.cacheNames.add(cache.getName());
}
/**
* Check for a registered cache of the given name.
* In contrast to {@link #getCache(String)}, this method does not trigger
* the lazy creation of missing caches via {@link #getMissingCache(String)}.
* @param name the cache identifier (must not be {@code null})
* @return the associated Cache instance, or {@code null} if none found
* @since 4.1
* @see #getCache(String)
* @see #getMissingCache(String)
*/
protected final Cache lookupCache(String name) {
return this.cacheMap.get(name);
}
@ -120,6 +130,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing @@ -120,6 +130,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
* @param name the name of the cache to retrieve
* @return the missing cache or {@code null} if no such cache exists or could be
* created
* @since 4.1
* @see #getCache(String)
*/
protected Cache getMissingCache(String name) {

4
spring-context/src/main/java/org/springframework/scripting/ScriptEvaluator.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -44,7 +44,7 @@ public interface ScriptEvaluator { @@ -44,7 +44,7 @@ public interface ScriptEvaluator {
* Evaluate the given script with the given arguments.
* @param script the ScriptSource for the script to evaluate
* @param arguments the key-value pairs to expose to the script,
* typically as script variables. May be {@code null}.
* typically as script variables (may be {@code null} or empty)
* @return the return value of the script, if any
* @throws ScriptCompilationException if the evaluator failed to read,
* compile or evaluate the script

32
spring-test/src/main/java/org/springframework/test/context/junit4/statements/RunAfterTestClassCallbacks.java

@ -25,15 +25,17 @@ import org.junit.runners.model.Statement; @@ -25,15 +25,17 @@ import org.junit.runners.model.Statement;
import org.springframework.test.context.TestContextManager;
/**
* {@code RunAfterTestClassCallbacks} is a custom JUnit {@link Statement} which allows the
* <em>Spring TestContext Framework</em> to be plugged into the JUnit execution chain by
* calling {@link TestContextManager#afterTestClass() afterTestClass()} on the supplied
* {@code RunAfterTestClassCallbacks} is a custom JUnit {@link Statement} which allows
* the <em>Spring TestContext Framework</em> to be plugged into the JUnit execution chain
* by calling {@link TestContextManager#afterTestClass afterTestClass()} on the supplied
* {@link TestContextManager}.
*
* @see #evaluate()
* @see RunBeforeTestMethodCallbacks
* <p><strong>NOTE:</strong> This class requires JUnit 4.9 or higher.
*
* @author Sam Brannen
* @since 3.0
* @see #evaluate()
* @see RunBeforeTestClassCallbacks
*/
public class RunAfterTestClassCallbacks extends Statement {
@ -43,8 +45,7 @@ public class RunAfterTestClassCallbacks extends Statement { @@ -43,8 +45,7 @@ public class RunAfterTestClassCallbacks extends Statement {
/**
* Constructs a new {@code RunAfterTestClassCallbacks} statement.
*
* Construct a new {@code RunAfterTestClassCallbacks} statement.
* @param next the next {@code Statement} in the execution chain
* @param testContextManager the TestContextManager upon which to call
* {@code afterTestClass()}
@ -54,12 +55,13 @@ public class RunAfterTestClassCallbacks extends Statement { @@ -54,12 +55,13 @@ public class RunAfterTestClassCallbacks extends Statement {
this.testContextManager = testContextManager;
}
/**
* Invokes the next {@link Statement} in the execution chain (typically an instance of
* Evaluate the next {@link Statement} in the execution chain (typically an instance of
* {@link org.junit.internal.runners.statements.RunAfters RunAfters}), catching any
* exceptions thrown, and then calls {@link TestContextManager#afterTestClass()}. If
* the call to {@code afterTestClass()} throws an exception, it will also be tracked.
* Multiple exceptions will be combined into a {@link MultipleFailureException}.
* exceptions thrown, and then invoke {@link TestContextManager#afterTestClass()}.
* <p>If the invocation of {@code afterTestClass()} throws an exception, it will also
* be tracked. Multiple exceptions will be combined into a {@link MultipleFailureException}.
*/
@Override
public void evaluate() throws Throwable {
@ -67,15 +69,15 @@ public class RunAfterTestClassCallbacks extends Statement { @@ -67,15 +69,15 @@ public class RunAfterTestClassCallbacks extends Statement {
try {
this.next.evaluate();
}
catch (Throwable e) {
errors.add(e);
catch (Throwable ex) {
errors.add(ex);
}
try {
this.testContextManager.afterTestClass();
}
catch (Exception e) {
errors.add(e);
catch (Throwable ex) {
errors.add(ex);
}
if (errors.isEmpty()) {

38
spring-test/src/main/java/org/springframework/test/context/junit4/statements/RunAfterTestMethodCallbacks.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -28,13 +28,15 @@ import org.springframework.test.context.TestContextManager; @@ -28,13 +28,15 @@ import org.springframework.test.context.TestContextManager;
/**
* {@code RunAfterTestMethodCallbacks} is a custom JUnit {@link Statement} which allows
* the <em>Spring TestContext Framework</em> to be plugged into the JUnit execution chain
* by calling {@link TestContextManager#afterTestMethod(Object, Method, Throwable)
* afterTestMethod()} on the supplied {@link TestContextManager}.
* by calling {@link TestContextManager#afterTestMethod afterTestMethod()} on the supplied
* {@link TestContextManager}.
*
* <p><strong>NOTE:</strong> This class requires JUnit 4.9 or higher.
*
* @see #evaluate()
* @see RunBeforeTestMethodCallbacks
* @author Sam Brannen
* @since 3.0
* @see #evaluate()
* @see RunBeforeTestMethodCallbacks
*/
public class RunAfterTestMethodCallbacks extends Statement {
@ -48,8 +50,7 @@ public class RunAfterTestMethodCallbacks extends Statement { @@ -48,8 +50,7 @@ public class RunAfterTestMethodCallbacks extends Statement {
/**
* Constructs a new {@code RunAfterTestMethodCallbacks} statement.
*
* Construct a new {@code RunAfterTestMethodCallbacks} statement.
* @param next the next {@code Statement} in the execution chain
* @param testInstance the current test instance (never {@code null})
* @param testMethod the test method which has just been executed on the
@ -59,19 +60,22 @@ public class RunAfterTestMethodCallbacks extends Statement { @@ -59,19 +60,22 @@ public class RunAfterTestMethodCallbacks extends Statement {
*/
public RunAfterTestMethodCallbacks(Statement next, Object testInstance, Method testMethod,
TestContextManager testContextManager) {
this.next = next;
this.testInstance = testInstance;
this.testMethod = testMethod;
this.testContextManager = testContextManager;
}
/**
* Invokes the next {@link Statement} in the execution chain (typically an instance of
* Evaluate the next {@link Statement} in the execution chain (typically an instance of
* {@link org.junit.internal.runners.statements.RunAfters RunAfters}), catching any
* exceptions thrown, and then calls
* {@link TestContextManager#afterTestMethod(Object, Method, Throwable)} with the
* first caught exception (if any). If the call to {@code afterTestMethod()} throws an
* exception, it will also be tracked. Multiple exceptions will be combined into a
* exceptions thrown, and then invoke
* {@link TestContextManager#afterTestMethod(Object, Method, Throwable)} supplying the
* first caught exception (if any).
* <p>If the invocation of {@code afterTestMethod()} throws an exception, that
* exception will also be tracked. Multiple exceptions will be combined into a
* {@link MultipleFailureException}.
*/
@Override
@ -81,16 +85,16 @@ public class RunAfterTestMethodCallbacks extends Statement { @@ -81,16 +85,16 @@ public class RunAfterTestMethodCallbacks extends Statement {
try {
this.next.evaluate();
}
catch (Throwable e) {
testException = e;
errors.add(e);
catch (Throwable ex) {
testException = ex;
errors.add(ex);
}
try {
this.testContextManager.afterTestMethod(this.testInstance, this.testMethod, testException);
}
catch (Exception e) {
errors.add(e);
catch (Throwable ex) {
errors.add(ex);
}
if (errors.isEmpty()) {

16
spring-test/src/main/java/org/springframework/test/context/junit4/statements/RunBeforeTestClassCallbacks.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -26,10 +26,10 @@ import org.springframework.test.context.TestContextManager; @@ -26,10 +26,10 @@ import org.springframework.test.context.TestContextManager;
* by calling {@link TestContextManager#beforeTestClass() beforeTestClass()} on the
* supplied {@link TestContextManager}.
*
* @see #evaluate()
* @see RunAfterTestMethodCallbacks
* @author Sam Brannen
* @since 3.0
* @see #evaluate()
* @see RunAfterTestMethodCallbacks
*/
public class RunBeforeTestClassCallbacks extends Statement {
@ -39,8 +39,7 @@ public class RunBeforeTestClassCallbacks extends Statement { @@ -39,8 +39,7 @@ public class RunBeforeTestClassCallbacks extends Statement {
/**
* Constructs a new {@code RunBeforeTestClassCallbacks} statement.
*
* Construct a new {@code RunBeforeTestClassCallbacks} statement.
* @param next the next {@code Statement} in the execution chain
* @param testContextManager the TestContextManager upon which to call
* {@code beforeTestClass()}
@ -50,10 +49,11 @@ public class RunBeforeTestClassCallbacks extends Statement { @@ -50,10 +49,11 @@ public class RunBeforeTestClassCallbacks extends Statement {
this.testContextManager = testContextManager;
}
/**
* Calls {@link TestContextManager#beforeTestClass()} and then invokes the next
* {@link Statement} in the execution chain (typically an instance of
* {@link org.junit.internal.runners.statements.RunBefores RunBefores}).
* Invoke {@link TestContextManager#beforeTestClass()} and then evaluate
* the next {@link Statement} in the execution chain (typically an instance
* of {@link org.junit.internal.runners.statements.RunBefores RunBefores}).
*/
@Override
public void evaluate() throws Throwable {

16
spring-test/src/main/java/org/springframework/test/context/junit4/statements/RunBeforeTestMethodCallbacks.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -28,10 +28,10 @@ import org.springframework.test.context.TestContextManager; @@ -28,10 +28,10 @@ import org.springframework.test.context.TestContextManager;
* by calling {@link TestContextManager#beforeTestMethod(Object, Method)
* beforeTestMethod()} on the supplied {@link TestContextManager}.
*
* @see #evaluate()
* @see RunAfterTestMethodCallbacks
* @author Sam Brannen
* @since 3.0
* @see #evaluate()
* @see RunAfterTestMethodCallbacks
*/
public class RunBeforeTestMethodCallbacks extends Statement {
@ -45,8 +45,7 @@ public class RunBeforeTestMethodCallbacks extends Statement { @@ -45,8 +45,7 @@ public class RunBeforeTestMethodCallbacks extends Statement {
/**
* Constructs a new {@code RunBeforeTestMethodCallbacks} statement.
*
* Construct a new {@code RunBeforeTestMethodCallbacks} statement.
* @param next the next {@code Statement} in the execution chain
* @param testInstance the current test instance (never {@code null})
* @param testMethod the test method which is about to be executed on the
@ -56,15 +55,18 @@ public class RunBeforeTestMethodCallbacks extends Statement { @@ -56,15 +55,18 @@ public class RunBeforeTestMethodCallbacks extends Statement {
*/
public RunBeforeTestMethodCallbacks(Statement next, Object testInstance, Method testMethod,
TestContextManager testContextManager) {
this.next = next;
this.testInstance = testInstance;
this.testMethod = testMethod;
this.testContextManager = testContextManager;
}
/**
* Calls {@link TestContextManager#beforeTestMethod(Object, Method)} and then invokes
* the next {@link Statement} in the execution chain (typically an instance of
* Invoke {@link TestContextManager#beforeTestMethod(Object, Method)}
* and then evaluate the next {@link Statement} in the execution chain
* (typically an instance of
* {@link org.junit.internal.runners.statements.RunBefores RunBefores}).
*/
@Override

43
spring-test/src/main/java/org/springframework/test/context/junit4/statements/SpringFailOnTimeout.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -20,17 +20,20 @@ import java.util.concurrent.TimeoutException; @@ -20,17 +20,20 @@ import java.util.concurrent.TimeoutException;
import org.junit.runners.model.Statement;
import org.springframework.test.annotation.Timed;
/**
* {@code SpringFailOnTimeout} is a custom JUnit {@link Statement} which adds
* support for Spring's {@link Timed @Timed} annotation by throwing an exception
* if the next statement in the execution chain takes more than the specified
* number of milliseconds.
* support for Spring's {@link org.springframework.test.annotation.Timed @Timed}
* annotation by throwing an exception if the next statement in the execution
* chain takes more than the specified number of milliseconds.
*
* <p>In contrast to JUnit's
* {@link org.junit.internal.runners.statements.FailOnTimeout FailOnTimeout},
* the next {@code statement} will be executed in the same thread as the
* caller and will therefore not be aborted preemptively.
*
* @see #evaluate()
* @author Sam Brannen
* @since 3.0
* @see #evaluate()
*/
public class SpringFailOnTimeout extends Statement {
@ -40,24 +43,25 @@ public class SpringFailOnTimeout extends Statement { @@ -40,24 +43,25 @@ public class SpringFailOnTimeout extends Statement {
/**
* Constructs a new {@code SpringFailOnTimeout} statement.
*
* @param next the next {@code Statement} in the execution chain
* @param timeout the configured {@code timeout} for the current test
* @see Timed#millis()
* Construct a new {@code SpringFailOnTimeout} statement for the supplied
* {@code timeout}.
* <p>If the supplied {@code timeout} is {@code 0}, the execution of the
* {@code next} statement will not be timed.
* @param next the next {@code Statement} in the execution chain; never {@code null}
* @param timeout the configured {@code timeout} for the current test, in milliseconds;
* never negative
*/
public SpringFailOnTimeout(Statement next, long timeout) {
this.next = next;
this.timeout = timeout;
}
/**
* Invokes the next {@link Statement statement} in the execution chain
* (typically an instance of
* {@link org.junit.internal.runners.statements.InvokeMethod InvokeMethod}
* or {@link org.junit.internal.runners.statements.ExpectException
* ExpectException}) and throws an exception if the next {@code statement}
* takes more than the specified {@code timeout}.
* Evaluate the next {@link Statement statement} in the execution chain
* (typically an instance of {@link SpringRepeat}) and throw a
* {@link TimeoutException} if the next {@code statement} executes longer
* than the specified {@code timeout}.
*/
@Override
public void evaluate() throws Throwable {
@ -68,7 +72,8 @@ public class SpringFailOnTimeout extends Statement { @@ -68,7 +72,8 @@ public class SpringFailOnTimeout extends Statement {
finally {
long elapsed = System.currentTimeMillis() - startTime;
if (elapsed > this.timeout) {
throw new TimeoutException(String.format("Test took %s ms; limit was %s ms.", elapsed, this.timeout));
throw new TimeoutException(
String.format("Test took %s ms; limit was %s ms.", elapsed, this.timeout));
}
}
}

23
spring-test/src/main/java/org/springframework/test/context/junit4/statements/SpringRepeat.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -22,17 +22,14 @@ import org.apache.commons.logging.Log; @@ -22,17 +22,14 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.runners.model.Statement;
import org.springframework.test.annotation.Repeat;
import org.springframework.util.ClassUtils;
/**
* {@code SpringRepeat} is a custom JUnit {@link Statement} which adds support
* for Spring's {@link Repeat @Repeat} annotation by repeating the test for
* the specified number of times.
* for Spring's {@link org.springframework.test.annotation.Repeat @Repeat}
* annotation by repeating the test the specified number of times.
*
* @see #evaluate()
* @author Sam Brannen
* @since 3.0
* @see #evaluate()
*/
public class SpringRepeat extends Statement {
@ -46,12 +43,11 @@ public class SpringRepeat extends Statement { @@ -46,12 +43,11 @@ public class SpringRepeat extends Statement {
/**
* Constructs a new {@code SpringRepeat} statement.
*
* Construct a new {@code SpringRepeat} statement for the supplied
* {@code testMethod} and {@code repeat} count.
* @param next the next {@code Statement} in the execution chain
* @param testMethod the current test method
* @param repeat the configured repeat count for the current test method
* @see Repeat#value()
*/
public SpringRepeat(Statement next, Method testMethod, int repeat) {
this.next = next;
@ -59,16 +55,17 @@ public class SpringRepeat extends Statement { @@ -59,16 +55,17 @@ public class SpringRepeat extends Statement {
this.repeat = Math.max(1, repeat);
}
/**
* Invokes the next {@link Statement statement} in the execution chain for
* the specified repeat count.
* Evaluate the next {@link Statement statement} in the execution chain
* repeatedly, using the specified repeat count.
*/
@Override
public void evaluate() throws Throwable {
for (int i = 0; i < this.repeat; i++) {
if (this.repeat > 1 && logger.isInfoEnabled()) {
logger.info(String.format("Repetition %d of test %s#%s()", (i + 1),
ClassUtils.getShortName(this.testMethod.getDeclaringClass()), this.testMethod.getName()));
this.testMethod.getDeclaringClass().getSimpleName(), this.testMethod.getName()));
}
this.next.evaluate();
}

2
spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java

@ -129,6 +129,8 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran @@ -129,6 +129,8 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
/**
* Same signature as {@link #getTransactionAttribute}, but doesn't cache the result.
* {@link #getTransactionAttribute} is effectively a caching decorator for this method.
* <p>As of 4.1.8, this method can be overridden.
* @since 4.1.8
* @see #getTransactionAttribute
*/
protected TransactionAttribute computeTransactionAttribute(Method method, Class<?> targetClass) {

Loading…
Cancel
Save