Skip to content

Commit 999a442

Browse files
authored
Merge pull request #1268 from kazuki43zoo/use-auto-close-sqlsession-on-test
Replace to auto-close instead of explicit close on test that using SqlSession
2 parents 96a0bf1 + 6fe0f77 commit 999a442

File tree

122 files changed

+767
-2315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+767
-2315
lines changed

src/test/java/org/apache/ibatis/autoconstructor/AutoConstructorTest.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-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.
@@ -54,57 +54,42 @@ public static void setUp() throws Exception {
5454

5555
@Test
5656
public void fullyPopulatedSubject() {
57-
final SqlSession sqlSession = sqlSessionFactory.openSession();
58-
try {
57+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
5958
final AutoConstructorMapper mapper = sqlSession.getMapper(AutoConstructorMapper.class);
6059
final Object subject = mapper.getSubject(1);
6160
Assert.assertNotNull(subject);
62-
} finally {
63-
sqlSession.close();
6461
}
6562
}
6663

6764
@Test(expected = PersistenceException.class)
6865
public void primitiveSubjects() {
69-
final SqlSession sqlSession = sqlSessionFactory.openSession();
70-
try {
66+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
7167
final AutoConstructorMapper mapper = sqlSession.getMapper(AutoConstructorMapper.class);
7268
mapper.getSubjects();
73-
} finally {
74-
sqlSession.close();
7569
}
7670
}
7771

7872
@Test
7973
public void wrapperSubject() {
80-
final SqlSession sqlSession = sqlSessionFactory.openSession();
81-
try {
74+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
8275
final AutoConstructorMapper mapper = sqlSession.getMapper(AutoConstructorMapper.class);
8376
verifySubjects(mapper.getWrapperSubjects());
84-
} finally {
85-
sqlSession.close();
8677
}
8778
}
8879

8980
@Test
9081
public void annotatedSubject() {
91-
final SqlSession sqlSession = sqlSessionFactory.openSession();
92-
try {
82+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
9383
final AutoConstructorMapper mapper = sqlSession.getMapper(AutoConstructorMapper.class);
9484
verifySubjects(mapper.getAnnotatedSubjects());
95-
} finally {
96-
sqlSession.close();
9785
}
9886
}
9987

10088
@Test(expected = PersistenceException.class)
10189
public void badSubject() {
102-
final SqlSession sqlSession = sqlSessionFactory.openSession();
103-
try {
90+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
10491
final AutoConstructorMapper mapper = sqlSession.getMapper(AutoConstructorMapper.class);
10592
mapper.getBadSubjects();
106-
} finally {
107-
sqlSession.close();
10893
}
10994
}
11095

0 commit comments

Comments
 (0)