Skip to content

Commit 9c46b6e

Browse files
committed
Polishing tests
1 parent 4bf1912 commit 9c46b6e

27 files changed

+120
-123
lines changed

src/test/java/org/mybatis/spring/MyBatisSpringTest.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2017 the original author or authors.
2+
* Copyright 2010-2019 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.
@@ -38,12 +38,12 @@
3838
import static org.junit.jupiter.api.Assertions.fail;
3939
import static org.junit.jupiter.api.Assertions.assertThrows;
4040

41-
public final class MyBatisSpringTest extends AbstractMyBatisSpringTest {
41+
class MyBatisSpringTest extends AbstractMyBatisSpringTest {
4242

4343
private SqlSession session;
4444

4545
@AfterEach
46-
public void validateSessionClose() {
46+
void validateSessionClose() {
4747
// assume if the Executor is closed, the Session is too
4848
if ((session != null) && !executorInterceptor.isExecutorClosed()) {
4949
session = null;
@@ -55,7 +55,7 @@ public void validateSessionClose() {
5555

5656
// ensure MyBatis API still works with SpringManagedTransaction
5757
@Test
58-
public void testMyBatisAPI() {
58+
void testMyBatisAPI() {
5959
session = sqlSessionFactory.openSession();
6060
session.getMapper(TestMapper.class).findTest();
6161
session.close();
@@ -66,7 +66,7 @@ public void testMyBatisAPI() {
6666
}
6767

6868
@Test
69-
public void testMyBatisAPIWithCommit() {
69+
void testMyBatisAPIWithCommit() {
7070
session = sqlSessionFactory.openSession();
7171
session.getMapper(TestMapper.class).findTest();
7272
session.commit(true);
@@ -78,7 +78,7 @@ public void testMyBatisAPIWithCommit() {
7878
}
7979

8080
@Test
81-
public void testMyBatisAPIWithRollback() {
81+
void testMyBatisAPIWithRollback() {
8282
session = sqlSessionFactory.openSession();
8383
session.getMapper(TestMapper.class).findTest();
8484
session.rollback(true);
@@ -91,7 +91,7 @@ public void testMyBatisAPIWithRollback() {
9191

9292
// basic tests using SqlSessionUtils instead of using the MyBatis API directly
9393
@Test
94-
public void testSpringAPI() {
94+
void testSpringAPI() {
9595
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
9696
session.getMapper(TestMapper.class).findTest();
9797
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
@@ -102,7 +102,7 @@ public void testSpringAPI() {
102102
}
103103

104104
@Test
105-
public void testSpringAPIWithCommit() {
105+
void testSpringAPIWithCommit() {
106106
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
107107
session.getMapper(TestMapper.class).findTest();
108108
session.commit(true);
@@ -113,7 +113,7 @@ public void testSpringAPIWithCommit() {
113113
}
114114

115115
@Test
116-
public void testSpringAPIWithRollback() {
116+
void testSpringAPIWithRollback() {
117117
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
118118
session.getMapper(TestMapper.class).findTest();
119119
session.rollback(true);
@@ -124,7 +124,7 @@ public void testSpringAPIWithRollback() {
124124
}
125125

126126
@Test
127-
public void testSpringAPIWithMyBatisClose() {
127+
void testSpringAPIWithMyBatisClose() {
128128
// This is a programming error and could lead to connection leak if there is a transaction
129129
// in progress. But, the API allows it, so make sure it at least works without a tx.
130130
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
@@ -137,7 +137,7 @@ public void testSpringAPIWithMyBatisClose() {
137137

138138
// Spring API should work with a MyBatis TransactionFactories
139139
@Test
140-
public void testWithNonSpringTransactionFactory() {
140+
void testWithNonSpringTransactionFactory() {
141141
Environment original = sqlSessionFactory.getConfiguration().getEnvironment();
142142
Environment nonSpring = new Environment("non-spring", new JdbcTransactionFactory(), dataSource);
143143
sqlSessionFactory.getConfiguration().setEnvironment(nonSpring);
@@ -159,7 +159,7 @@ public void testWithNonSpringTransactionFactory() {
159159
// Spring TX, non-Spring TransactionFactory, Spring managed DataSource
160160
// this should not work since the DS will be out of sync with MyBatis
161161
@Test
162-
public void testNonSpringTxFactoryWithTx() throws Exception {
162+
void testNonSpringTxFactoryWithTx() throws Exception {
163163
Environment original = sqlSessionFactory.getConfiguration().getEnvironment();
164164
Environment nonSpring = new Environment("non-spring", new JdbcTransactionFactory(), dataSource);
165165
sqlSessionFactory.getConfiguration().setEnvironment(nonSpring);
@@ -184,7 +184,7 @@ public void testNonSpringTxFactoryWithTx() throws Exception {
184184
// Spring TX, non-Spring TransactionFactory, MyBatis managed DataSource
185185
// this should work since the DS is managed MyBatis
186186
@Test
187-
public void testNonSpringTxFactoryNonSpringDSWithTx() throws java.sql.SQLException {
187+
void testNonSpringTxFactoryNonSpringDSWithTx() throws java.sql.SQLException {
188188
Environment original = sqlSessionFactory.getConfiguration().getEnvironment();
189189

190190
MockDataSource mockDataSource = new MockDataSource();
@@ -222,7 +222,7 @@ public void testNonSpringTxFactoryNonSpringDSWithTx() throws java.sql.SQLExcepti
222222
}
223223

224224
@Test
225-
public void testChangeExecutorTypeInTx() throws Exception {
225+
void testChangeExecutorTypeInTx() throws Exception {
226226
TransactionStatus status = null;
227227

228228
try {
@@ -244,7 +244,7 @@ public void testChangeExecutorTypeInTx() throws Exception {
244244
}
245245

246246
@Test
247-
public void testChangeExecutorTypeInTxRequiresNew() throws Exception {
247+
void testChangeExecutorTypeInTxRequiresNew() throws Exception {
248248

249249
try {
250250
txManager.setDataSource(dataSource);
@@ -276,7 +276,7 @@ public void testChangeExecutorTypeInTxRequiresNew() throws Exception {
276276
}
277277

278278
@Test
279-
public void testWithJtaTxManager() {
279+
void testWithJtaTxManager() {
280280
JtaTransactionManager jtaManager = new JtaTransactionManager(new MockUserTransaction());
281281

282282
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
@@ -297,7 +297,7 @@ public void testWithJtaTxManager() {
297297
}
298298

299299
@Test
300-
public void testWithJtaTxManagerAndNonSpringTxManager() throws java.sql.SQLException {
300+
void testWithJtaTxManagerAndNonSpringTxManager() throws java.sql.SQLException {
301301
Environment original = sqlSessionFactory.getConfiguration().getEnvironment();
302302

303303
MockDataSource mockDataSource = new MockDataSource();
@@ -344,7 +344,7 @@ public void testWithJtaTxManagerAndNonSpringTxManager() throws java.sql.SQLExcep
344344
}
345345

346346
@Test
347-
public void testWithTxSupports() {
347+
void testWithTxSupports() {
348348
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
349349
txDef.setPropagationBehaviorName("PROPAGATION_SUPPORTS");
350350

@@ -363,7 +363,7 @@ public void testWithTxSupports() {
363363

364364

365365
@Test
366-
public void testRollbackWithTxSupports() {
366+
void testRollbackWithTxSupports() {
367367
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
368368
txDef.setPropagationBehaviorName("PROPAGATION_SUPPORTS");
369369

@@ -381,7 +381,7 @@ public void testRollbackWithTxSupports() {
381381
}
382382

383383
@Test
384-
public void testWithTxRequired() {
384+
void testWithTxRequired() {
385385
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
386386
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
387387

@@ -399,7 +399,7 @@ public void testWithTxRequired() {
399399
}
400400

401401
@Test
402-
public void testSqlSessionCommitWithTx() {
402+
void testSqlSessionCommitWithTx() {
403403
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
404404
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
405405

@@ -424,7 +424,7 @@ public void testSqlSessionCommitWithTx() {
424424
}
425425

426426
@Test
427-
public void testWithInterleavedTx() throws Exception {
427+
void testWithInterleavedTx() {
428428
// this session will use one Connection
429429
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
430430
session.getMapper(TestMapper.class).findTest();
@@ -460,7 +460,7 @@ public void testWithInterleavedTx() throws Exception {
460460
}
461461

462462
@Test
463-
public void testSuspendAndResume() throws Exception {
463+
void testSuspendAndResume() {
464464

465465
try {
466466
txManager.setDataSource(dataSource);
@@ -512,7 +512,7 @@ public void testSuspendAndResume() throws Exception {
512512
}
513513

514514
@Test
515-
public void testBatch() {
515+
void testBatch() {
516516
setupBatchStatements();
517517

518518
session = SqlSessionUtils.getSqlSession(sqlSessionFactory, ExecutorType.BATCH, exceptionTranslator);
@@ -533,7 +533,7 @@ public void testBatch() {
533533
}
534534

535535
@Test
536-
public void testBatchInTx() {
536+
void testBatchInTx() {
537537
setupBatchStatements();
538538

539539
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
@@ -557,7 +557,7 @@ public void testBatchInTx() {
557557
}
558558

559559
@Test
560-
public void testBatchWithError() {
560+
void testBatchWithError() {
561561
try {
562562
setupBatchStatements();
563563

@@ -577,7 +577,7 @@ public void testBatchWithError() {
577577
}
578578

579579
@Test
580-
public void testBatchInTxWithError() {
580+
void testBatchInTxWithError() {
581581
setupBatchStatements();
582582

583583
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();

src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2017 the original author or authors.
2+
* Copyright 2010-2019 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 @@
4747

4848
import com.mockrunner.mock.jdbc.MockDataSource;
4949

50-
public final class SqlSessionFactoryBeanTest {
50+
class SqlSessionFactoryBeanTest {
5151

5252
private static final class TestObjectFactory extends DefaultObjectFactory {
5353
private static final long serialVersionUID = 1L;}
@@ -57,7 +57,7 @@ private static final class TestObjectWrapperFactory extends DefaultObjectWrapper
5757

5858
private SqlSessionFactoryBean factoryBean;
5959

60-
public void setupFactoryBean() {
60+
void setupFactoryBean() {
6161
factoryBean = new SqlSessionFactoryBean();
6262
factoryBean.setDataSource(dataSource);
6363
}
@@ -72,20 +72,20 @@ void testDefaults() throws Exception {
7272
// DataSource is the only required property that does not have a default value, so test for both
7373
// not setting it at all and setting it to null
7474
@Test
75-
void testNullDataSource() throws Exception {
75+
void testNullDataSource() {
7676
factoryBean = new SqlSessionFactoryBean();
7777
assertThrows(IllegalArgumentException.class, factoryBean::getObject);
7878
}
7979

8080
@Test
81-
void testSetNullDataSource() throws Exception {
81+
void testSetNullDataSource() {
8282
factoryBean = new SqlSessionFactoryBean();
8383
factoryBean.setDataSource(null);
8484
assertThrows(IllegalArgumentException.class, factoryBean::getObject);
8585
}
8686

8787
@Test
88-
void testNullSqlSessionFactoryBuilder() throws Exception {
88+
void testNullSqlSessionFactoryBuilder() {
8989
setupFactoryBean();
9090
factoryBean.setSqlSessionFactoryBuilder(null);
9191
assertThrows(IllegalArgumentException.class, factoryBean::getObject);

src/test/java/org/mybatis/spring/SqlSessionTemplateTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2017 the original author or authors.
2+
* Copyright 2010-2019 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.
@@ -79,17 +79,17 @@ void testGetConnectionInTx() throws java.sql.SQLException {
7979
}
8080

8181
@Test
82-
void testCommit() throws SQLException {
82+
void testCommit() {
8383
assertThrows(UnsupportedOperationException.class, sqlSessionTemplate::commit);
8484
}
8585

8686
@Test
87-
void testClose() throws SQLException {
87+
void testClose() {
8888
assertThrows(UnsupportedOperationException.class, sqlSessionTemplate::close);
8989
}
9090

9191
@Test
92-
void testRollback() throws SQLException {
92+
void testRollback() {
9393
assertThrows(UnsupportedOperationException.class, sqlSessionTemplate::rollback);
9494
}
9595

src/test/java/org/mybatis/spring/annotation/MapperScanTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2017 the original author or authors.
2+
* Copyright 2010-2019 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.
@@ -46,14 +46,14 @@
4646
* <p>
4747
* This test works fine with Spring 3.1 and 3.2 but with 3.1 the registrar is called twice.
4848
*/
49-
public final class MapperScanTest {
49+
class MapperScanTest {
5050
private AnnotationConfigApplicationContext applicationContext;
5151

5252
@BeforeEach
5353
void setupContext() {
5454
applicationContext = new AnnotationConfigApplicationContext();
5555

56-
setupSqlSessionFactory("sqlSessionFactory");
56+
setupSqlSessionFactory();
5757

5858
// assume support for autowiring fields is added by MapperScannerConfigurer
5959
// via
@@ -195,11 +195,11 @@ void testScanWithNameConflict() {
195195
.isSameAs(Object.class);
196196
}
197197

198-
private void setupSqlSessionFactory(String name) {
198+
private void setupSqlSessionFactory() {
199199
GenericBeanDefinition definition = new GenericBeanDefinition();
200200
definition.setBeanClass(SqlSessionFactoryBean.class);
201201
definition.getPropertyValues().add("dataSource", new MockDataSource());
202-
applicationContext.registerBeanDefinition(name, definition);
202+
applicationContext.registerBeanDefinition("sqlSessionFactory", definition);
203203
}
204204

205205
private void assertBeanNotLoaded(String name) {
@@ -225,7 +225,7 @@ void testScanWithExplicitSqlSessionFactory() {
225225
}
226226

227227
@Test
228-
void testScanWithExplicitSqlSessionTemplate() throws Exception {
228+
void testScanWithExplicitSqlSessionTemplate() {
229229
GenericBeanDefinition definition = new GenericBeanDefinition();
230230
definition.setBeanClass(SqlSessionTemplate.class);
231231
ConstructorArgumentValues constructorArgs = new ConstructorArgumentValues();

src/test/java/org/mybatis/spring/asyncsynchronization/AsyncAfterCompletionHelper.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2017 the original author or authors.
2+
* Copyright 2010-2019 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.
@@ -80,9 +80,6 @@ public Object invoke(final Object proxy, final Method method,
8080

8181
/**
8282
* Creates proxy that performs afterCompletion call on a separate thread
83-
*
84-
* @param synchronization
85-
* @return
8683
*/
8784
public TransactionSynchronization createSynchronizationWithAsyncAfterComplete(
8885
TransactionSynchronization synchronization) {

src/test/java/org/mybatis/spring/asyncsynchronization/SqlSessionTemplateAsyncAfterCompletionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2017 the original author or authors.
2+
* Copyright 2010-2019 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.
@@ -30,5 +30,5 @@
3030
@Disabled // FIXME: Enable after migrate BMUnitRunner to BMUnitExtension
3131
// @ExtendWith(BMUnitRunner.class)
3232
@BMRule(name = "proxy synchronizations", targetClass = "TransactionSynchronizationManager", targetMethod = "registerSynchronization(TransactionSynchronization)", helper = "org.mybatis.spring.asyncsynchronization.AsyncAfterCompletionHelper", action = "$1=createSynchronizationWithAsyncAfterComplete($1)")
33-
public class SqlSessionTemplateAsyncAfterCompletionTest extends SqlSessionTemplateTest {
33+
class SqlSessionTemplateAsyncAfterCompletionTest extends SqlSessionTemplateTest {
3434
}

0 commit comments

Comments
 (0)