1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -83,6 +83,7 @@ public void commitWithoutExistingTransaction() {
83
83
TestTransactionManager tm = new TestTransactionManager (false , true );
84
84
TransactionStatus status = tm .getTransaction (null );
85
85
tm .commit (status );
86
+
86
87
assertTrue ("triggered begin" , tm .begin );
87
88
assertTrue ("triggered commit" , tm .commit );
88
89
assertTrue ("no rollback" , !tm .rollback );
@@ -94,6 +95,7 @@ public void rollbackWithoutExistingTransaction() {
94
95
TestTransactionManager tm = new TestTransactionManager (false , true );
95
96
TransactionStatus status = tm .getTransaction (null );
96
97
tm .rollback (status );
98
+
97
99
assertTrue ("triggered begin" , tm .begin );
98
100
assertTrue ("no commit" , !tm .commit );
99
101
assertTrue ("triggered rollback" , tm .rollback );
@@ -106,6 +108,7 @@ public void rollbackOnlyWithoutExistingTransaction() {
106
108
TransactionStatus status = tm .getTransaction (null );
107
109
status .setRollbackOnly ();
108
110
tm .commit (status );
111
+
109
112
assertTrue ("triggered begin" , tm .begin );
110
113
assertTrue ("no commit" , !tm .commit );
111
114
assertTrue ("triggered rollback" , tm .rollback );
@@ -117,6 +120,7 @@ public void commitWithExistingTransaction() {
117
120
TestTransactionManager tm = new TestTransactionManager (true , true );
118
121
TransactionStatus status = tm .getTransaction (null );
119
122
tm .commit (status );
123
+
120
124
assertTrue ("no begin" , !tm .begin );
121
125
assertTrue ("no commit" , !tm .commit );
122
126
assertTrue ("no rollback" , !tm .rollback );
@@ -128,6 +132,7 @@ public void rollbackWithExistingTransaction() {
128
132
TestTransactionManager tm = new TestTransactionManager (true , true );
129
133
TransactionStatus status = tm .getTransaction (null );
130
134
tm .rollback (status );
135
+
131
136
assertTrue ("no begin" , !tm .begin );
132
137
assertTrue ("no commit" , !tm .commit );
133
138
assertTrue ("no rollback" , !tm .rollback );
@@ -140,6 +145,7 @@ public void rollbackOnlyWithExistingTransaction() {
140
145
TransactionStatus status = tm .getTransaction (null );
141
146
status .setRollbackOnly ();
142
147
tm .commit (status );
148
+
143
149
assertTrue ("no begin" , !tm .begin );
144
150
assertTrue ("no commit" , !tm .commit );
145
151
assertTrue ("no rollback" , !tm .rollback );
@@ -155,6 +161,7 @@ public void transactionTemplate() {
155
161
protected void doInTransactionWithoutResult (TransactionStatus status ) {
156
162
}
157
163
});
164
+
158
165
assertTrue ("triggered begin" , tm .begin );
159
166
assertTrue ("triggered commit" , tm .commit );
160
167
assertTrue ("no rollback" , !tm .rollback );
@@ -170,6 +177,7 @@ public void transactionTemplateWithCallbackPreference() {
170
177
protected void doInTransactionWithoutResult (TransactionStatus status ) {
171
178
}
172
179
});
180
+
173
181
assertSame (template , ptm .getDefinition ());
174
182
assertFalse (ptm .getStatus ().isRollbackOnly ());
175
183
}
@@ -300,9 +308,22 @@ public void transactionTemplateInitialization() {
300
308
assertTrue ("Correct isolation level set" , template .getIsolationLevel () == TransactionDefinition .ISOLATION_REPEATABLE_READ );
301
309
}
302
310
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
+
303
324
304
325
@ After
305
- public void tearDown () {
326
+ public void clear () {
306
327
assertTrue (TransactionSynchronizationManager .getResourceMap ().isEmpty ());
307
328
assertFalse (TransactionSynchronizationManager .isSynchronizationActive ());
308
329
}
0 commit comments