Skip to content

Remove duplicated setup in JpaTransactionManagerTests #34807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ void verifyTransactionSynchronizationManagerState() {

@Test
void testTransactionCommit() {
given(manager.getTransaction()).willReturn(tx);

final List<String> l = new ArrayList<>();
l.add("test");

Expand All @@ -106,7 +104,6 @@ void testTransactionCommit() {

@Test
void testTransactionCommitWithRollbackException() {
given(manager.getTransaction()).willReturn(tx);
given(tx.getRollbackOnly()).willReturn(true);
willThrow(new RollbackException()).given(tx).commit();

Expand Down Expand Up @@ -138,7 +135,6 @@ void testTransactionCommitWithRollbackException() {

@Test
void testTransactionRollback() {
given(manager.getTransaction()).willReturn(tx);
given(tx.isActive()).willReturn(true);

final List<String> l = new ArrayList<>();
Expand All @@ -163,8 +159,6 @@ void testTransactionRollback() {

@Test
void testTransactionRollbackWithAlreadyRolledBack() {
given(manager.getTransaction()).willReturn(tx);

final List<String> l = new ArrayList<>();
l.add("test");

Expand All @@ -186,7 +180,6 @@ void testTransactionRollbackWithAlreadyRolledBack() {

@Test
void testTransactionRollbackOnly() {
given(manager.getTransaction()).willReturn(tx);
given(tx.isActive()).willReturn(true);

final List<String> l = new ArrayList<>();
Expand Down Expand Up @@ -214,8 +207,6 @@ void testTransactionRollbackOnly() {

@Test
void testParticipatingTransactionWithCommit() {
given(manager.getTransaction()).willReturn(tx);

final List<String> l = new ArrayList<>();
l.add("test");

Expand All @@ -241,7 +232,6 @@ void testParticipatingTransactionWithCommit() {

@Test
void testParticipatingTransactionWithRollback() {
given(manager.getTransaction()).willReturn(tx);
given(tx.isActive()).willReturn(true);

final List<String> l = new ArrayList<>();
Expand Down Expand Up @@ -269,7 +259,6 @@ void testParticipatingTransactionWithRollback() {

@Test
void testParticipatingTransactionWithRollbackOnly() {
given(manager.getTransaction()).willReturn(tx);
given(tx.isActive()).willReturn(true);
given(tx.getRollbackOnly()).willReturn(true);
willThrow(new RollbackException()).given(tx).commit();
Expand Down Expand Up @@ -304,10 +293,6 @@ void testParticipatingTransactionWithRollbackOnly() {
void testParticipatingTransactionWithRequiresNew() {
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

given(factory.createEntityManager()).willReturn(manager);
given(manager.getTransaction()).willReturn(tx);
given(manager.isOpen()).willReturn(true);

final List<String> l = new ArrayList<>();
l.add("test");

Expand Down Expand Up @@ -335,7 +320,6 @@ void testParticipatingTransactionWithRequiresNew() {
void testParticipatingTransactionWithRequiresNewAndPrebound() {
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

given(manager.getTransaction()).willReturn(tx);

final List<String> l = new ArrayList<>();
l.add("test");
Expand Down Expand Up @@ -374,8 +358,6 @@ void testParticipatingTransactionWithRequiresNewAndPrebound() {
void testPropagationSupportsAndRequiresNew() {
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);

given(manager.getTransaction()).willReturn(tx);

final List<String> l = new ArrayList<>();
l.add("test");

Expand Down Expand Up @@ -405,10 +387,6 @@ void testPropagationSupportsAndRequiresNew() {
void testPropagationSupportsAndRequiresNewAndEarlyAccess() {
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);

given(factory.createEntityManager()).willReturn(manager);
given(manager.getTransaction()).willReturn(tx);
given(manager.isOpen()).willReturn(true);

final List<String> l = new ArrayList<>();
l.add("test");

Expand Down Expand Up @@ -443,7 +421,6 @@ void testTransactionWithRequiresNewInAfterCompletion() {
EntityManager manager2 = mock();
EntityTransaction tx2 = mock();

given(manager.getTransaction()).willReturn(tx);
given(factory.createEntityManager()).willReturn(manager, manager2);
given(manager2.getTransaction()).willReturn(tx2);
given(manager2.isOpen()).willReturn(true);
Expand Down Expand Up @@ -479,8 +456,6 @@ public void afterCompletion(int status) {

@Test
void testTransactionCommitWithPropagationSupports() {
given(manager.isOpen()).willReturn(true);

final List<String> l = new ArrayList<>();
l.add("test");

Expand All @@ -507,8 +482,6 @@ void testTransactionCommitWithPropagationSupports() {

@Test
void testTransactionRollbackWithPropagationSupports() {
given(manager.isOpen()).willReturn(true);

tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);

assertThat(TransactionSynchronizationManager.hasResource(factory)).isFalse();
Expand All @@ -532,8 +505,6 @@ void testTransactionRollbackWithPropagationSupports() {

@Test
void testTransactionCommitWithPrebound() {
given(manager.getTransaction()).willReturn(tx);

final List<String> l = new ArrayList<>();
l.add("test");

Expand Down Expand Up @@ -563,7 +534,6 @@ void testTransactionCommitWithPrebound() {

@Test
void testTransactionRollbackWithPrebound() {
given(manager.getTransaction()).willReturn(tx);
given(tx.isActive()).willReturn(true);

assertThat(TransactionSynchronizationManager.hasResource(factory)).isFalse();
Expand Down Expand Up @@ -655,8 +625,6 @@ void testTransactionRollbackWithPreboundAndPropagationSupports() {
void testInvalidIsolation() {
tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);

given(manager.isOpen()).willReturn(true);

assertThatExceptionOfType(InvalidIsolationLevelException.class).isThrownBy(() ->
tt.execute(new TransactionCallbackWithoutResult() {
@Override
Expand All @@ -669,8 +637,6 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {

@Test
void testTransactionFlush() {
given(manager.getTransaction()).willReturn(tx);

assertThat(TransactionSynchronizationManager.hasResource(factory)).isFalse();
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();

Expand Down