In tests configured with Spring’s @Transactional annotation, methods annotated with @BeforeTransaction or
@AfterTransaction must be void and have no arguments. These methods are executed before or after a transaction, respectively. Deviating
from this contract by having a non-void return type or accepting arguments will cause Spring to throw a runtime error.
Ensure that methods annotated with @BeforeTransaction or @AfterTransaction have a void return type and do not accept any
arguments.
@Transactional
public class TransactionalTest {
@BeforeTransaction
public String setupTransaction(int x) { // non-compliant, method should be void and have no argument
// Setup logic
}
@AfterTransaction
public int cleanupTransaction(int x) { // non-compliant, method should be void and have no argument
// Cleanup logic
}
}
@Transactional
public class TransactionalTest {
@BeforeTransaction
public void setupTransaction() {
// Setup logic
}
@AfterTransaction
public void cleanupTransaction() {
// Cleanup logic
}
}