Support @[Before|After]Transaction on non-public methods
In order to align with the relaxed programming models of TestNG and the
upcoming JUnit 5 (with regard to method visibility), this commit
removes the requirement that @BeforeTransaction and @AfterTransaction
methods must be 'public'.
Issue: SPR-13997
@ -246,6 +246,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
@@ -246,6 +246,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
if(logger.isDebugEnabled()){
logger.debug("Executing @BeforeTransaction method ["+method+"] for test context "+testContext);
}
ReflectionUtils.makeAccessible(method);
method.invoke(testContext.getTestInstance());
}
}
@ -273,6 +274,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
@@ -273,6 +274,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
if(logger.isDebugEnabled()){
logger.debug("Executing @AfterTransaction method ["+method+"] for test context "+testContext);
@ -79,7 +81,7 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
@@ -79,7 +81,7 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
@ -88,7 +90,7 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
@@ -88,7 +90,7 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
@ -115,7 +117,6 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
@@ -115,7 +117,6 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
@ -124,7 +125,6 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
@@ -124,7 +125,6 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
@ -134,6 +134,7 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
@@ -134,6 +134,7 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
@ -120,7 +120,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
@@ -120,7 +120,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
}
@BeforeTransaction
publicvoidbeforeTransaction(){
voidbeforeTransaction(){
assertNumRowsInPersonTable(1,"before a transactional test method");
assertAddPerson(YODA);
}
@ -152,7 +152,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
@@ -152,7 +152,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
@ -190,7 +190,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
@@ -190,7 +190,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@BeforeTransaction
publicvoidbeforeTransaction(){
voidbeforeTransaction(){
assertNumRowsInPersonTable(1,"before a transactional test method");
assertAddPerson(YODA);
}
@ -222,7 +222,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
@@ -222,7 +222,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
Indicates that the annotated `public void` method should be executed __before__ a
Indicates that the annotated `void` method should be executed __before__ a
transaction is started for test methods configured to run within a transaction via the
`@Transactional` annotation.
@ -863,7 +863,7 @@ transaction is started for test methods configured to run within a transaction v
@@ -863,7 +863,7 @@ transaction is started for test methods configured to run within a transaction v
[subs="verbatim,quotes"]
----
**@BeforeTransaction**
public void beforeTransaction() {
void beforeTransaction() {
// logic to be executed before a transaction is started
}
----
@ -872,7 +872,7 @@ transaction is started for test methods configured to run within a transaction v
@@ -872,7 +872,7 @@ transaction is started for test methods configured to run within a transaction v
+
Indicates that the annotated `public void` method should be executed __after__ a
Indicates that the annotated `void` method should be executed __after__ a
transaction has ended for test methods configured to run within a transaction via the
`@Transactional` annotation.
@ -882,7 +882,7 @@ transaction has ended for test methods configured to run within a transaction vi
@@ -882,7 +882,7 @@ transaction has ended for test methods configured to run within a transaction vi
[subs="verbatim,quotes"]
----
**@AfterTransaction**
public void afterTransaction() {
void afterTransaction() {
// logic to be executed after a transaction has ended
}
----
@ -3197,8 +3197,8 @@ but outside the transactional context -- for example, to verify the initial data
@@ -3197,8 +3197,8 @@ but outside the transactional context -- for example, to verify the initial data
prior to execution of your test or to verify expected transactional commit behavior after
test execution (if the test was configured not to roll back the transaction).
`TransactionalTestExecutionListener` supports the `@BeforeTransaction` and
`@AfterTransaction` annotations exactly for such scenarios. Simply annotate any `public
void` method in your test class with one of these annotations, and the
`@AfterTransaction` annotations exactly for such scenarios. Simply annotate any `void`
method in your test class with one of these annotations, and the
`TransactionalTestExecutionListener` ensures that your __before transaction method__ or
__after transaction method__ is executed at the appropriate time.
@ -677,6 +677,7 @@ Spring 4.3 also improves the caching abstraction as follows:
@@ -677,6 +677,7 @@ Spring 4.3 also improves the caching abstraction as follows:
* The JUnit support in the _Spring TestContext Framework_ now requires JUnit 4.12 or higher.
* New `SpringRunner` __alias__ for the `SpringJUnit4ClassRunner`.
* `@BeforeTransaction` and `@AfterTransaction` methods are no longer required to be `public`.
* Server-side Spring MVC Test supports expectations on response headers with multiple values.
* Server-side Spring MVC Test parses form data request content and populates request parameters.
* Client-side REST test support allows indicating how many times a request is expected and