11/*
2- * Copyright 2010-2023 the original author or authors.
2+ * Copyright 2010-2024 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.
@@ -47,7 +47,7 @@ class MyBatisSpringTest extends AbstractMyBatisSpringTest {
4747 @ AfterEach
4848 void validateSessionClose () {
4949 // assume if the Executor is closed, the Session is too
50- if (( session != null ) && !executorInterceptor .isExecutorClosed ()) {
50+ if (session != null && !executorInterceptor .isExecutorClosed ()) {
5151 session = null ;
5252 fail ("SqlSession is not closed" );
5353 } else {
@@ -140,8 +140,8 @@ void testSpringAPIWithMyBatisClose() {
140140 // Spring API should work with a MyBatis TransactionFactories
141141 @ Test
142142 void testWithNonSpringTransactionFactory () {
143- Environment original = sqlSessionFactory .getConfiguration ().getEnvironment ();
144- Environment nonSpring = new Environment ("non-spring" , new JdbcTransactionFactory (), dataSource );
143+ var original = sqlSessionFactory .getConfiguration ().getEnvironment ();
144+ var nonSpring = new Environment ("non-spring" , new JdbcTransactionFactory (), dataSource );
145145 sqlSessionFactory .getConfiguration ().setEnvironment (nonSpring );
146146
147147 try {
@@ -162,8 +162,8 @@ void testWithNonSpringTransactionFactory() {
162162 // this should not work since the DS will be out of sync with MyBatis
163163 @ Test
164164 void testNonSpringTxFactoryWithTx () throws Exception {
165- Environment original = sqlSessionFactory .getConfiguration ().getEnvironment ();
166- Environment nonSpring = new Environment ("non-spring" , new JdbcTransactionFactory (), dataSource );
165+ var original = sqlSessionFactory .getConfiguration ().getEnvironment ();
166+ var nonSpring = new Environment ("non-spring" , new JdbcTransactionFactory (), dataSource );
167167 sqlSessionFactory .getConfiguration ().setEnvironment (nonSpring );
168168
169169 TransactionStatus status = null ;
@@ -186,12 +186,12 @@ void testNonSpringTxFactoryWithTx() throws Exception {
186186 // this should work since the DS is managed MyBatis
187187 @ Test
188188 void testNonSpringTxFactoryNonSpringDSWithTx () throws java .sql .SQLException {
189- Environment original = sqlSessionFactory .getConfiguration ().getEnvironment ();
189+ var original = sqlSessionFactory .getConfiguration ().getEnvironment ();
190190
191- MockDataSource mockDataSource = new MockDataSource ();
191+ var mockDataSource = new MockDataSource ();
192192 mockDataSource .setupConnection (createMockConnection ());
193193
194- Environment nonSpring = new Environment ("non-spring" , new JdbcTransactionFactory (), mockDataSource );
194+ var nonSpring = new Environment ("non-spring" , new JdbcTransactionFactory (), mockDataSource );
195195 sqlSessionFactory .getConfiguration ().setEnvironment (nonSpring );
196196
197197 TransactionStatus status ;
@@ -211,7 +211,7 @@ void testNonSpringTxFactoryNonSpringDSWithTx() throws java.sql.SQLException {
211211
212212 // SqlSession uses its own connection
213213 // that connection will not have committed since no SQL was executed by the session
214- MockConnection mockConnection = (MockConnection ) mockDataSource .getConnection ();
214+ var mockConnection = (MockConnection ) mockDataSource .getConnection ();
215215 assertThat (mockConnection .getNumberCommits ()).as ("should call commit on Connection" ).isEqualTo (0 );
216216 assertThat (mockConnection .getNumberRollbacks ()).as ("should not call rollback on Connection" ).isEqualTo (0 );
217217 assertCommitSession ();
@@ -248,16 +248,16 @@ void testChangeExecutorTypeInTxRequiresNew() throws Exception {
248248
249249 try {
250250 txManager .setDataSource (dataSource );
251- TransactionStatus status = txManager .getTransaction (new DefaultTransactionDefinition ());
251+ var status = txManager .getTransaction (new DefaultTransactionDefinition ());
252252
253253 session = SqlSessionUtils .getSqlSession (sqlSessionFactory );
254254
255255 // start a new tx while the other is in progress
256- DefaultTransactionDefinition txRequiresNew = new DefaultTransactionDefinition ();
256+ var txRequiresNew = new DefaultTransactionDefinition ();
257257 txRequiresNew .setPropagationBehaviorName ("PROPAGATION_REQUIRES_NEW" );
258- TransactionStatus status2 = txManager .getTransaction (txRequiresNew );
258+ var status2 = txManager .getTransaction (txRequiresNew );
259259
260- SqlSession session2 = SqlSessionUtils .getSqlSession (sqlSessionFactory , ExecutorType .BATCH , exceptionTranslator );
260+ var session2 = SqlSessionUtils .getSqlSession (sqlSessionFactory , ExecutorType .BATCH , exceptionTranslator );
261261
262262 SqlSessionUtils .closeSqlSession (session2 , sqlSessionFactory );
263263 txManager .rollback (status2 );
@@ -277,12 +277,12 @@ void testChangeExecutorTypeInTxRequiresNew() throws Exception {
277277
278278 @ Test
279279 void testWithJtaTxManager () {
280- JtaTransactionManager jtaManager = new JtaTransactionManager (Mockito .mock (UserTransaction .class ));
280+ var jtaManager = new JtaTransactionManager (Mockito .mock (UserTransaction .class ));
281281
282- DefaultTransactionDefinition txDef = new DefaultTransactionDefinition ();
282+ var txDef = new DefaultTransactionDefinition ();
283283 txDef .setPropagationBehaviorName ("PROPAGATION_REQUIRED" );
284284
285- TransactionStatus status = jtaManager .getTransaction (txDef );
285+ var status = jtaManager .getTransaction (txDef );
286286
287287 session = SqlSessionUtils .getSqlSession (sqlSessionFactory );
288288 session .getMapper (TestMapper .class ).findTest ();
@@ -298,20 +298,20 @@ void testWithJtaTxManager() {
298298
299299 @ Test
300300 void testWithJtaTxManagerAndNonSpringTxManager () throws java .sql .SQLException {
301- Environment original = sqlSessionFactory .getConfiguration ().getEnvironment ();
301+ var original = sqlSessionFactory .getConfiguration ().getEnvironment ();
302302
303- MockDataSource mockDataSource = new MockDataSource ();
303+ var mockDataSource = new MockDataSource ();
304304 mockDataSource .setupConnection (createMockConnection ());
305305
306- Environment nonSpring = new Environment ("non-spring" , new ManagedTransactionFactory (), mockDataSource );
306+ var nonSpring = new Environment ("non-spring" , new ManagedTransactionFactory (), mockDataSource );
307307 sqlSessionFactory .getConfiguration ().setEnvironment (nonSpring );
308308
309- JtaTransactionManager jtaManager = new JtaTransactionManager (Mockito .mock (UserTransaction .class ));
309+ var jtaManager = new JtaTransactionManager (Mockito .mock (UserTransaction .class ));
310310
311- DefaultTransactionDefinition txDef = new DefaultTransactionDefinition ();
311+ var txDef = new DefaultTransactionDefinition ();
312312 txDef .setPropagationBehaviorName ("PROPAGATION_REQUIRED" );
313313
314- TransactionStatus status = jtaManager .getTransaction (txDef );
314+ var status = jtaManager .getTransaction (txDef );
315315
316316 try {
317317 session = SqlSessionUtils .getSqlSession (sqlSessionFactory );
@@ -326,7 +326,7 @@ void testWithJtaTxManagerAndNonSpringTxManager() throws java.sql.SQLException {
326326 assertNoCommitJdbc ();
327327 assertCommitSession ();
328328
329- MockConnection mockConnection = (MockConnection ) mockDataSource .getConnection ();
329+ var mockConnection = (MockConnection ) mockDataSource .getConnection ();
330330 assertThat (mockConnection .getNumberCommits ()).as ("should call commit on Connection" ).isEqualTo (0 );
331331 assertThat (mockConnection .getNumberRollbacks ()).as ("should not call rollback on Connection" ).isEqualTo (0 );
332332
@@ -345,10 +345,10 @@ void testWithJtaTxManagerAndNonSpringTxManager() throws java.sql.SQLException {
345345
346346 @ Test
347347 void testWithTxSupports () {
348- DefaultTransactionDefinition txDef = new DefaultTransactionDefinition ();
348+ var txDef = new DefaultTransactionDefinition ();
349349 txDef .setPropagationBehaviorName ("PROPAGATION_SUPPORTS" );
350350
351- TransactionStatus status = txManager .getTransaction (txDef );
351+ var status = txManager .getTransaction (txDef );
352352
353353 session = SqlSessionUtils .getSqlSession (sqlSessionFactory );
354354 session .getMapper (TestMapper .class ).findTest ();
@@ -363,10 +363,10 @@ void testWithTxSupports() {
363363
364364 @ Test
365365 void testRollbackWithTxSupports () {
366- DefaultTransactionDefinition txDef = new DefaultTransactionDefinition ();
366+ var txDef = new DefaultTransactionDefinition ();
367367 txDef .setPropagationBehaviorName ("PROPAGATION_SUPPORTS" );
368368
369- TransactionStatus status = txManager .getTransaction (txDef );
369+ var status = txManager .getTransaction (txDef );
370370
371371 session = SqlSessionUtils .getSqlSession (sqlSessionFactory );
372372 session .getMapper (TestMapper .class ).findTest ();
@@ -381,10 +381,10 @@ void testRollbackWithTxSupports() {
381381
382382 @ Test
383383 void testWithTxRequired () {
384- DefaultTransactionDefinition txDef = new DefaultTransactionDefinition ();
384+ var txDef = new DefaultTransactionDefinition ();
385385 txDef .setPropagationBehaviorName ("PROPAGATION_REQUIRED" );
386386
387- TransactionStatus status = txManager .getTransaction (txDef );
387+ var status = txManager .getTransaction (txDef );
388388
389389 session = SqlSessionUtils .getSqlSession (sqlSessionFactory );
390390 session .getMapper (TestMapper .class ).findTest ();
@@ -399,10 +399,10 @@ void testWithTxRequired() {
399399
400400 @ Test
401401 void testSqlSessionCommitWithTx () {
402- DefaultTransactionDefinition txDef = new DefaultTransactionDefinition ();
402+ var txDef = new DefaultTransactionDefinition ();
403403 txDef .setPropagationBehaviorName ("PROPAGATION_REQUIRED" );
404404
405- TransactionStatus status = txManager .getTransaction (txDef );
405+ var status = txManager .getTransaction (txDef );
406406
407407 session = SqlSessionUtils .getSqlSession (sqlSessionFactory );
408408 session .getMapper (TestMapper .class ).findTest ();
@@ -429,7 +429,7 @@ void testWithInterleavedTx() {
429429 session .getMapper (TestMapper .class ).findTest ();
430430
431431 // this transaction should use another Connection
432- TransactionStatus status = txManager .getTransaction (new DefaultTransactionDefinition ());
432+ var status = txManager .getTransaction (new DefaultTransactionDefinition ());
433433
434434 // session continues using original connection
435435 session .getMapper (TestMapper .class ).insertTest ("test2" );
@@ -463,16 +463,16 @@ void testSuspendAndResume() {
463463
464464 try {
465465 txManager .setDataSource (dataSource );
466- TransactionStatus status = txManager .getTransaction (new DefaultTransactionDefinition ());
466+ var status = txManager .getTransaction (new DefaultTransactionDefinition ());
467467
468468 session = SqlSessionUtils .getSqlSession (sqlSessionFactory );
469469
470470 // start a new tx while the other is in progress
471- DefaultTransactionDefinition txRequiresNew = new DefaultTransactionDefinition ();
471+ var txRequiresNew = new DefaultTransactionDefinition ();
472472 txRequiresNew .setPropagationBehaviorName ("PROPAGATION_REQUIRES_NEW" );
473- TransactionStatus status2 = txManager .getTransaction (txRequiresNew );
473+ var status2 = txManager .getTransaction (txRequiresNew );
474474
475- SqlSession session2 = SqlSessionUtils .getSqlSession (sqlSessionFactory );
475+ var session2 = SqlSessionUtils .getSqlSession (sqlSessionFactory );
476476
477477 assertThat (session ).as ("getSqlSession() should not return suspended SqlSession" ).isNotSameAs (session2 );
478478
@@ -535,10 +535,10 @@ void testBatch() {
535535 void testBatchInTx () {
536536 setupBatchStatements ();
537537
538- DefaultTransactionDefinition txDef = new DefaultTransactionDefinition ();
538+ var txDef = new DefaultTransactionDefinition ();
539539 txDef .setPropagationBehaviorName ("PROPAGATION_REQUIRED" );
540540
541- TransactionStatus status = txManager .getTransaction (txDef );
541+ var status = txManager .getTransaction (txDef );
542542
543543 session = SqlSessionUtils .getSqlSession (sqlSessionFactory , ExecutorType .BATCH , exceptionTranslator );
544544
@@ -577,10 +577,10 @@ void testBatchWithError() {
577577 void testBatchInTxWithError () {
578578 setupBatchStatements ();
579579
580- DefaultTransactionDefinition txDef = new DefaultTransactionDefinition ();
580+ var txDef = new DefaultTransactionDefinition ();
581581 txDef .setPropagationBehaviorName ("PROPAGATION_REQUIRED" );
582582
583- TransactionStatus status = txManager .getTransaction (txDef );
583+ var status = txManager .getTransaction (txDef );
584584
585585 session = SqlSessionUtils .getSqlSession (sqlSessionFactory , ExecutorType .BATCH , exceptionTranslator );
586586
0 commit comments