Skip to content

Commit 71396ac

Browse files
committed
Polishing JavaDoc
1 parent 6837111 commit 71396ac

File tree

1 file changed

+47
-42
lines changed

1 file changed

+47
-42
lines changed

org.springframework.test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@
2727

2828
import org.apache.commons.logging.Log;
2929
import org.apache.commons.logging.LogFactory;
30-
3130
import org.springframework.beans.BeansException;
3231
import org.springframework.beans.factory.BeanFactory;
3332
import org.springframework.core.annotation.AnnotationUtils;
@@ -50,19 +49,19 @@
5049

5150
/**
5251
* <p>
53-
* <code>TestExecutionListener</code> which provides support for executing
54-
* tests within transactions by using
52+
* <code>TestExecutionListener</code> that provides support for executing
53+
* tests within transactions by using the
5554
* {@link org.springframework.transaction.annotation.Transactional &#064;Transactional}
5655
* and {@link NotTransactional &#064;NotTransactional} annotations.
5756
* </p>
5857
* <p>
59-
* Changes to the database during a test run with &#064;Transactional will be
58+
* Changes to the database during a test that is run with &#064;Transactional will be
6059
* run within a transaction that will, by default, be automatically
6160
* <em>rolled back</em> after completion of the test; whereas, changes to the
62-
* database during a test run with &#064;NotTransactional will <strong>not</strong>
63-
* be run within a transaction. Similarly, test methods that are not annotated
64-
* with either &#064;Transactional (at the class or method level) or
65-
* &#064;NotTransactional will not be run within a transaction.
61+
* database during a test that is run with &#064;NotTransactional will <strong>not</strong>
62+
* be run within a transaction. Test methods that are not annotated with either
63+
* &#064;Transactional (at the class or method level) or &#064;NotTransactional
64+
* will not be run within a transaction.
6665
* </p>
6766
* <p>
6867
* Transactional commit and rollback behavior can be configured via the
@@ -73,7 +72,7 @@
7372
* is to be used to drive transactions.
7473
* </p>
7574
* <p>
76-
* When executing transactional tests, it is sometimes useful to be able execute
75+
* When executing transactional tests, it is sometimes useful to be able to execute
7776
* certain <em>set up</em> or <em>tear down</em> code outside of a
7877
* transaction. <code>TransactionalTestExecutionListener</code> provides such
7978
* support for methods annotated with
@@ -102,8 +101,8 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
102101

103102
private volatile int transactionsStarted = 0;
104103

105-
private final Map<Method, TransactionContext> transactionContextCache =
106-
Collections.synchronizedMap(new IdentityHashMap<Method, TransactionContext>());
104+
private final Map<Method, TransactionContext> transactionContextCache = Collections.synchronizedMap(new IdentityHashMap<Method, TransactionContext>());
105+
107106

108107
/**
109108
* If the test method of the supplied {@link TestContext test context} is
@@ -123,19 +122,20 @@ public void beforeTestMethod(TestContext testContext) throws Exception {
123122
Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null");
124123

125124
if (this.transactionContextCache.remove(testMethod) != null) {
126-
throw new IllegalStateException("Cannot start new transaction without ending existing transaction: " +
127-
"Invoke endTransaction() before startNewTransaction().");
125+
throw new IllegalStateException("Cannot start new transaction without ending existing transaction: "
126+
+ "Invoke endTransaction() before startNewTransaction().");
128127
}
129128

130129
if (testMethod.isAnnotationPresent(NotTransactional.class)) {
131130
return;
132131
}
133132

134-
TransactionAttribute transactionAttribute =
135-
this.attributeSource.getTransactionAttribute(testMethod, testContext.getTestClass());
133+
TransactionAttribute transactionAttribute = this.attributeSource.getTransactionAttribute(testMethod,
134+
testContext.getTestClass());
136135
TransactionDefinition transactionDefinition = null;
137136
if (transactionAttribute != null) {
138137
transactionDefinition = new DelegatingTransactionAttribute(transactionAttribute) {
138+
139139
public String getName() {
140140
return testMethod.getName();
141141
}
@@ -144,14 +144,15 @@ public String getName() {
144144

145145
if (transactionDefinition != null) {
146146
if (logger.isDebugEnabled()) {
147-
logger.debug("Explicit transaction definition [" + transactionDefinition +
148-
"] found for test context [" + testContext + "]");
147+
logger.debug("Explicit transaction definition [" + transactionDefinition + "] found for test context ["
148+
+ testContext + "]");
149149
}
150150
String qualifier = transactionAttribute.getQualifier();
151151
PlatformTransactionManager tm;
152152
if (StringUtils.hasLength(qualifier)) {
153-
// Use autowire-capable factory in order to support extended qualifier matching
154-
// (only exposed on the internal BeanFactory, not on the ApplicationContext).
153+
// Use autowire-capable factory in order to support extended
154+
// qualifier matching (only exposed on the internal BeanFactory,
155+
// not on the ApplicationContext).
155156
BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory();
156157
tm = TransactionAspectUtils.getTransactionManager(bf, qualifier);
157158
}
@@ -231,8 +232,8 @@ protected void runAfterTransactionMethods(TestContext testContext) throws Except
231232
for (Method method : methods) {
232233
try {
233234
if (logger.isDebugEnabled()) {
234-
logger.debug("Executing @AfterTransaction method [" + method + "] for test context [" +
235-
testContext + "]");
235+
logger.debug("Executing @AfterTransaction method [" + method + "] for test context [" + testContext
236+
+ "]");
236237
}
237238
method.invoke(testContext.getTestInstance());
238239
}
@@ -241,15 +242,15 @@ protected void runAfterTransactionMethods(TestContext testContext) throws Except
241242
if (afterTransactionException == null) {
242243
afterTransactionException = targetException;
243244
}
244-
logger.error("Exception encountered while executing @AfterTransaction method [" + method +
245-
"] for test context [" + testContext + "]", targetException);
245+
logger.error("Exception encountered while executing @AfterTransaction method [" + method
246+
+ "] for test context [" + testContext + "]", targetException);
246247
}
247248
catch (Exception ex) {
248249
if (afterTransactionException == null) {
249250
afterTransactionException = ex;
250251
}
251-
logger.error("Exception encountered while executing @AfterTransaction method [" + method +
252-
"] for test context [" + testContext + "]", ex);
252+
logger.error("Exception encountered while executing @AfterTransaction method [" + method
253+
+ "] for test context [" + testContext + "]", ex);
253254
}
254255
}
255256

@@ -270,8 +271,8 @@ private void startNewTransaction(TestContext testContext, TransactionContext txC
270271
txContext.startTransaction();
271272
++this.transactionsStarted;
272273
if (logger.isInfoEnabled()) {
273-
logger.info("Began transaction (" + this.transactionsStarted + "): transaction manager [" +
274-
txContext.transactionManager + "]; rollback [" + isRollback(testContext) + "]");
274+
logger.info("Began transaction (" + this.transactionsStarted + "): transaction manager ["
275+
+ txContext.transactionManager + "]; rollback [" + isRollback(testContext) + "]");
275276
}
276277
}
277278

@@ -285,13 +286,13 @@ private void startNewTransaction(TestContext testContext, TransactionContext txC
285286
private void endTransaction(TestContext testContext, TransactionContext txContext) throws Exception {
286287
boolean rollback = isRollback(testContext);
287288
if (logger.isTraceEnabled()) {
288-
logger.trace("Ending transaction for test context [" + testContext + "]; transaction manager [" +
289-
txContext.transactionStatus + "]; rollback [" + rollback + "]");
289+
logger.trace("Ending transaction for test context [" + testContext + "]; transaction manager ["
290+
+ txContext.transactionStatus + "]; rollback [" + rollback + "]");
290291
}
291292
txContext.endTransaction(rollback);
292293
if (logger.isInfoEnabled()) {
293-
logger.info((rollback ? "Rolled back" : "Committed") +
294-
" transaction after test execution for test context [" + testContext + "]");
294+
logger.info((rollback ? "Rolled back" : "Committed")
295+
+ " transaction after test execution for test context [" + testContext + "]");
295296
}
296297
}
297298

@@ -310,8 +311,8 @@ protected final PlatformTransactionManager getTransactionManager(TestContext tes
310311
}
311312
catch (BeansException ex) {
312313
if (logger.isWarnEnabled()) {
313-
logger.warn("Caught exception while retrieving transaction manager with bean name [" +
314-
tmName + "] for test context [" + testContext + "]", ex);
314+
logger.warn("Caught exception while retrieving transaction manager with bean name [" + tmName
315+
+ "] for test context [" + testContext + "]", ex);
315316
}
316317
throw ex;
317318
}
@@ -345,15 +346,15 @@ protected final boolean isRollback(TestContext testContext) throws Exception {
345346
if (rollbackAnnotation != null) {
346347
boolean rollbackOverride = rollbackAnnotation.value();
347348
if (logger.isDebugEnabled()) {
348-
logger.debug("Method-level @Rollback(" + rollbackOverride + ") overrides default rollback [" +
349-
rollback + "] for test context [" + testContext + "]");
349+
logger.debug("Method-level @Rollback(" + rollbackOverride + ") overrides default rollback [" + rollback
350+
+ "] for test context [" + testContext + "]");
350351
}
351352
rollback = rollbackOverride;
352353
}
353354
else {
354355
if (logger.isDebugEnabled()) {
355-
logger.debug("No method-level @Rollback override: using default rollback [" +
356-
rollback + "] for test context [" + testContext + "]");
356+
logger.debug("No method-level @Rollback override: using default rollback [" + rollback
357+
+ "] for test context [" + testContext + "]");
357358
}
358359
}
359360
return rollback;
@@ -478,16 +479,18 @@ private TransactionConfigurationAttributes retrieveConfigurationAttributes(TestC
478479
defaultRollback = (Boolean) AnnotationUtils.getDefaultValue(annotationType, "defaultRollback");
479480
}
480481

481-
TransactionConfigurationAttributes configAttributes =
482-
new TransactionConfigurationAttributes(transactionManagerName, defaultRollback);
482+
TransactionConfigurationAttributes configAttributes = new TransactionConfigurationAttributes(
483+
transactionManagerName, defaultRollback);
483484
if (logger.isDebugEnabled()) {
484-
logger.debug("Retrieved TransactionConfigurationAttributes [" + configAttributes + "] for class [" + clazz + "]");
485+
logger.debug("Retrieved TransactionConfigurationAttributes [" + configAttributes + "] for class ["
486+
+ clazz + "]");
485487
}
486488
this.configurationAttributes = configAttributes;
487489
}
488490
return this.configurationAttributes;
489491
}
490492

493+
491494
/**
492495
* Internal context holder for a specific test method.
493496
*/
@@ -499,7 +502,9 @@ private static class TransactionContext {
499502

500503
private TransactionStatus transactionStatus;
501504

502-
public TransactionContext(PlatformTransactionManager transactionManager, TransactionDefinition transactionDefinition) {
505+
506+
public TransactionContext(PlatformTransactionManager transactionManager,
507+
TransactionDefinition transactionDefinition) {
503508
this.transactionManager = transactionManager;
504509
this.transactionDefinition = transactionDefinition;
505510
}

0 commit comments

Comments
 (0)