11/*
2- * Copyright 2002-2017 the original author or authors.
2+ * Copyright 2002-2018 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -83,6 +83,7 @@ public void commitWithoutExistingTransaction() {
8383 TestTransactionManager tm = new TestTransactionManager (false , true );
8484 TransactionStatus status = tm .getTransaction (null );
8585 tm .commit (status );
86+
8687 assertTrue ("triggered begin" , tm .begin );
8788 assertTrue ("triggered commit" , tm .commit );
8889 assertTrue ("no rollback" , !tm .rollback );
@@ -94,6 +95,7 @@ public void rollbackWithoutExistingTransaction() {
9495 TestTransactionManager tm = new TestTransactionManager (false , true );
9596 TransactionStatus status = tm .getTransaction (null );
9697 tm .rollback (status );
98+
9799 assertTrue ("triggered begin" , tm .begin );
98100 assertTrue ("no commit" , !tm .commit );
99101 assertTrue ("triggered rollback" , tm .rollback );
@@ -106,6 +108,7 @@ public void rollbackOnlyWithoutExistingTransaction() {
106108 TransactionStatus status = tm .getTransaction (null );
107109 status .setRollbackOnly ();
108110 tm .commit (status );
111+
109112 assertTrue ("triggered begin" , tm .begin );
110113 assertTrue ("no commit" , !tm .commit );
111114 assertTrue ("triggered rollback" , tm .rollback );
@@ -117,6 +120,7 @@ public void commitWithExistingTransaction() {
117120 TestTransactionManager tm = new TestTransactionManager (true , true );
118121 TransactionStatus status = tm .getTransaction (null );
119122 tm .commit (status );
123+
120124 assertTrue ("no begin" , !tm .begin );
121125 assertTrue ("no commit" , !tm .commit );
122126 assertTrue ("no rollback" , !tm .rollback );
@@ -128,6 +132,7 @@ public void rollbackWithExistingTransaction() {
128132 TestTransactionManager tm = new TestTransactionManager (true , true );
129133 TransactionStatus status = tm .getTransaction (null );
130134 tm .rollback (status );
135+
131136 assertTrue ("no begin" , !tm .begin );
132137 assertTrue ("no commit" , !tm .commit );
133138 assertTrue ("no rollback" , !tm .rollback );
@@ -140,6 +145,7 @@ public void rollbackOnlyWithExistingTransaction() {
140145 TransactionStatus status = tm .getTransaction (null );
141146 status .setRollbackOnly ();
142147 tm .commit (status );
148+
143149 assertTrue ("no begin" , !tm .begin );
144150 assertTrue ("no commit" , !tm .commit );
145151 assertTrue ("no rollback" , !tm .rollback );
@@ -155,6 +161,7 @@ public void transactionTemplate() {
155161 protected void doInTransactionWithoutResult (TransactionStatus status ) {
156162 }
157163 });
164+
158165 assertTrue ("triggered begin" , tm .begin );
159166 assertTrue ("triggered commit" , tm .commit );
160167 assertTrue ("no rollback" , !tm .rollback );
@@ -170,6 +177,7 @@ public void transactionTemplateWithCallbackPreference() {
170177 protected void doInTransactionWithoutResult (TransactionStatus status ) {
171178 }
172179 });
180+
173181 assertSame (template , ptm .getDefinition ());
174182 assertFalse (ptm .getStatus ().isRollbackOnly ());
175183 }
@@ -300,9 +308,22 @@ public void transactionTemplateInitialization() {
300308 assertTrue ("Correct isolation level set" , template .getIsolationLevel () == TransactionDefinition .ISOLATION_REPEATABLE_READ );
301309 }
302310
311+ @ Test
312+ public void transactionTemplateEquality () {
313+ TestTransactionManager tm1 = new TestTransactionManager (false , true );
314+ TestTransactionManager tm2 = new TestTransactionManager (false , true );
315+ TransactionTemplate template1 = new TransactionTemplate (tm1 );
316+ TransactionTemplate template2 = new TransactionTemplate (tm2 );
317+ TransactionTemplate template3 = new TransactionTemplate (tm2 );
318+
319+ assertNotEquals (template1 , template2 );
320+ assertNotEquals (template1 , template3 );
321+ assertEquals (template2 , template3 );
322+ }
323+
303324
304325 @ After
305- public void tearDown () {
326+ public void clear () {
306327 assertTrue (TransactionSynchronizationManager .getResourceMap ().isEmpty ());
307328 assertFalse (TransactionSynchronizationManager .isSynchronizationActive ());
308329 }
0 commit comments