Merge pull request #10122 from j0rdanit0/BAEL-4590
Added code examples from the article.
This commit is contained in:
commit
502a128c91
|
@ -72,6 +72,12 @@
|
|||
<version>${org.springframework.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>${spring-boot-starter.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.baeldung.transactional;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
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;
|
||||
|
||||
@SpringBootApplication
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class TransactionalDetectionUnitTest {
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void givenTransactional_whenCheckingForActiveTransaction_thenReceiveTrue() {
|
||||
assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNoTransactional_whenCheckingForActiveTransaction_thenReceiveFalse() {
|
||||
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue