Allow non-public @Transactional test methods

Prior to this commit, the TransactionalTestExecutionListener required
@Transactional test methods to be public; however, neither TestNG nor
JUnit 5 require that @Test methods are public. Consequently, non-public
transactional test methods silently run *without* a transaction.

This commit removes the 'public' restriction on transactional test
methods by setting the 'publicMethodsOnly' flag in
AnnotationTransactionAttributeSource to false.

Issue: SPR-14000
master
Sam Brannen 9 years ago
parent 197434b3ec
commit df7b24b8e7
  1. 3
      spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java
  2. 2
      spring-test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTests.java
  3. 2
      spring-test/src/test/java/org/springframework/test/context/testng/ConcreteTransactionalTestNGSpringContextTests.java

@ -136,7 +136,8 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
@SuppressWarnings("deprecation")
private static final TransactionConfigurationAttributes defaultTxConfigAttributes = new TransactionConfigurationAttributes();
protected final TransactionAttributeSource attributeSource = new AnnotationTransactionAttributeSource();
// Do not require @Transactional test methods to be public.
protected final TransactionAttributeSource attributeSource = new AnnotationTransactionAttributeSource(false);
@SuppressWarnings("deprecation")
private TransactionConfigurationAttributes configurationAttributes;

@ -135,7 +135,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests
}
@Test
public void modifyTestDataWithinTransaction() {
void modifyTestDataWithinTransaction() {
assertInTransaction(true);
assertAddPerson(JANE);
assertAddPerson(SUE);

@ -205,7 +205,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@Test
public void modifyTestDataWithinTransaction() {
void modifyTestDataWithinTransaction() {
assertInTransaction(true);
assertAddPerson(JANE);
assertAddPerson(SUE);

Loading…
Cancel
Save