Added code examples from the article.

This commit is contained in:
Jordan Simpson 2020-10-03 00:42:54 -05:00
parent 8cf889d27e
commit 43ad7afa07
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package com.baeldung.transactional;
import com.baeldung.persistence.service.transactional.PersistenceTransactionalTestConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ContextConfiguration(classes = PersistenceTransactionalTestConfig.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class TransactionalDetectionTest {
@Test
@Transactional
public void givenTransactional_whenCheckingForActiveTransaction_thenReceiveTrue() {
assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
}
@Test
public void givenNoTransactional_whenCheckingForActiveTransaction_thenReceiveFalse() {
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
}
}