Skip to content

Commit a9325c9

Browse files
committed
Polishing SqlxmlTypeHandlerTest
See mybatis#1221
1 parent 81aafdf commit a9325c9

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

src/test/java/org/apache/ibatis/type/SqlxmlTypeHandlerTest.java

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public static void setUp() throws Exception {
7171
Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
7272
"org.postgresql.Driver", url, null));
7373
configuration.setEnvironment(environment);
74-
configuration.setUseGeneratedKeys(true);
7574
configuration.addMapper(Mapper.class);
7675
sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
7776

@@ -154,58 +153,42 @@ public void shouldGetResultNullFromCallableStatement() throws Exception {
154153
}
155154

156155
@Test
157-
public void shouldReturnXmlAsString() throws Exception {
158-
SqlSession session = sqlSessionFactory.openSession();
159-
try {
156+
public void shouldReturnXmlAsString() {
157+
try (SqlSession session = sqlSessionFactory.openSession()) {
160158
Mapper mapper = session.getMapper(Mapper.class);
161159
XmlBean bean = mapper.select(1);
162160
assertEquals("<title>XML data</title>",
163161
bean.getContent());
164-
} finally {
165-
session.close();
166162
}
167163
}
168164

169165
@Test
170-
public void shouldReturnNull() throws Exception {
171-
SqlSession session = sqlSessionFactory.openSession();
172-
try {
166+
public void shouldReturnNull() {
167+
try (SqlSession session = sqlSessionFactory.openSession()) {
173168
Mapper mapper = session.getMapper(Mapper.class);
174169
XmlBean bean = mapper.select(2);
175170
assertNull(bean.getContent());
176-
} finally {
177-
session.close();
178171
}
179172
}
180173

181174
@Test
182-
public void shouldInsertXmlString() throws Exception {
175+
public void shouldInsertXmlString() {
183176
final Integer id = 100;
184177
final String content = "<books><book><title>Save XML</title></book><book><title>Get XML</title></book></books>";
185178
// Insert
186-
{
187-
SqlSession session = sqlSessionFactory.openSession();
188-
try {
189-
Mapper mapper = session.getMapper(Mapper.class);
190-
XmlBean bean = new XmlBean();
191-
bean.setId(id);
192-
bean.setContent(content);
193-
mapper.insert(bean);
194-
session.commit();
195-
} finally {
196-
session.close();
197-
}
179+
try (SqlSession session = sqlSessionFactory.openSession()) {
180+
Mapper mapper = session.getMapper(Mapper.class);
181+
XmlBean bean = new XmlBean();
182+
bean.setId(id);
183+
bean.setContent(content);
184+
mapper.insert(bean);
185+
session.commit();
198186
}
199187
// Select to verify
200-
{
201-
SqlSession session = sqlSessionFactory.openSession();
202-
try {
203-
Mapper mapper = session.getMapper(Mapper.class);
204-
XmlBean bean = mapper.select(id);
205-
assertEquals(content, bean.getContent());
206-
} finally {
207-
session.close();
208-
}
188+
try (SqlSession session = sqlSessionFactory.openSession()) {
189+
Mapper mapper = session.getMapper(Mapper.class);
190+
XmlBean bean = mapper.select(id);
191+
assertEquals(content, bean.getContent());
209192
}
210193
}
211194

0 commit comments

Comments
 (0)