Skip to content

Instantly share code, notes, and snippets.

@aboodz
Last active December 4, 2025 15:56
Show Gist options
  • Select an option

  • Save aboodz/669bf3be61f48f1d0f3ec329e3b83719 to your computer and use it in GitHub Desktop.

Select an option

Save aboodz/669bf3be61f48f1d0f3ec329e3b83719 to your computer and use it in GitHub Desktop.
A fake transaction template that can be used in unit testing
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