Last active
December 4, 2025 15:56
-
-
Save aboodz/669bf3be61f48f1d0f3ec329e3b83719 to your computer and use it in GitHub Desktop.
A fake transaction template that can be used in unit testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.springframework.transaction.TransactionException; | |
| import org.springframework.transaction.support.SimpleTransactionStatus; | |
| import org.springframework.transaction.support.TransactionCallback; | |
| import org.springframework.transaction.support.TransactionTemplate; | |
| import static org.mockito.Mockito.spy; | |
| public class FakeTransactionTemplate extends TransactionTemplate { | |
| public static FakeTransactionTemplate spied() { | |
| return spy(new FakeTransactionTemplate()); | |
| } | |
| @Override | |
| public <T> T execute(TransactionCallback<T> action) throws TransactionException { | |
| return action.doInTransaction(new SimpleTransactionStatus()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment