Skip to content

Commit 753591a

Browse files
authored
Merge pull request #3363 from hazendaz/pom-cleanup
tests: Use assertDoesNotThrow to complete assertions where exceptions…
2 parents eee66f1 + 1b7d688 commit 753591a

File tree

9 files changed

+121
-82
lines changed

9 files changed

+121
-82
lines changed

src/test/java/org/apache/ibatis/builder/XmlMapperBuilderTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.googlecode.catchexception.apis.BDDCatchException.when;
2020
import static org.assertj.core.api.Assertions.assertThat;
2121
import static org.assertj.core.api.BDDAssertions.then;
22+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2223

2324
import java.io.InputStream;
2425
import java.util.regex.Pattern;
@@ -36,14 +37,16 @@
3637
class XmlMapperBuilderTest {
3738

3839
@Test
39-
void shouldSuccessfullyLoadXMLMapperFile() throws Exception {
40-
Configuration configuration = new Configuration();
41-
String resource = "org/apache/ibatis/builder/AuthorMapper.xml";
42-
try (InputStream inputStream = Resources.getResourceAsStream(resource)) {
43-
XMLMapperBuilder builder = new XMLMapperBuilder(inputStream, configuration, resource,
44-
configuration.getSqlFragments());
45-
builder.parse();
46-
}
40+
void shouldSuccessfullyLoadXMLMapperFile() {
41+
assertDoesNotThrow(() -> {
42+
Configuration configuration = new Configuration();
43+
String resource = "org/apache/ibatis/builder/AuthorMapper.xml";
44+
try (InputStream inputStream = Resources.getResourceAsStream(resource)) {
45+
XMLMapperBuilder builder = new XMLMapperBuilder(inputStream, configuration, resource,
46+
configuration.getSqlFragments());
47+
builder.parse();
48+
}
49+
});
4750
}
4851

4952
@Test

src/test/java/org/apache/ibatis/executor/BaseExecutorTest.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.apache.ibatis.executor;
1717

18+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1819
import static org.junit.jupiter.api.Assertions.assertEquals;
1920
import static org.junit.jupiter.api.Assertions.assertNotNull;
2021
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -452,29 +453,31 @@ void shouldMapConstructorResults() throws Exception {
452453
}
453454

454455
@Test
455-
void shouldClearDeferredLoads() throws Exception {
456-
457-
Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
458-
try {
459-
MappedStatement selectBlog = ExecutorTestHelper.prepareComplexSelectBlogMappedStatement(config);
460-
MappedStatement selectPosts = ExecutorTestHelper.prepareSelectPostsForBlogMappedStatement(config);
461-
config.addMappedStatement(selectBlog);
462-
config.addMappedStatement(selectPosts);
463-
MappedStatement selectAuthor = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
464-
MappedStatement insertAuthor = ExecutorTestHelper.prepareInsertAuthorMappedStatement(config);
465-
466-
// generate DeferredLoads
467-
executor.query(selectPosts, 1, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
468-
469-
Author author = new Author(-1, "someone", "******", "[email protected]", null, Section.NEWS);
470-
executor.update(insertAuthor, author);
471-
executor.query(selectAuthor, -1, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
472-
executor.flushStatements();
473-
executor.rollback(true);
474-
} finally {
475-
executor.rollback(true);
476-
executor.close(false);
477-
}
456+
void shouldClearDeferredLoads() {
457+
assertDoesNotThrow(() -> {
458+
459+
Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
460+
try {
461+
MappedStatement selectBlog = ExecutorTestHelper.prepareComplexSelectBlogMappedStatement(config);
462+
MappedStatement selectPosts = ExecutorTestHelper.prepareSelectPostsForBlogMappedStatement(config);
463+
config.addMappedStatement(selectBlog);
464+
config.addMappedStatement(selectPosts);
465+
MappedStatement selectAuthor = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
466+
MappedStatement insertAuthor = ExecutorTestHelper.prepareInsertAuthorMappedStatement(config);
467+
468+
// generate DeferredLoads
469+
executor.query(selectPosts, 1, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
470+
471+
Author author = new Author(-1, "someone", "******", "[email protected]", null, Section.NEWS);
472+
executor.update(insertAuthor, author);
473+
executor.query(selectAuthor, -1, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
474+
executor.flushStatements();
475+
executor.rollback(true);
476+
} finally {
477+
executor.rollback(true);
478+
executor.close(false);
479+
}
480+
});
478481
}
479482

480483
@Test

src/test/java/org/apache/ibatis/executor/ReuseExecutorTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.apache.ibatis.executor;
1717

18+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
19+
1820
import org.apache.ibatis.transaction.Transaction;
1921
import org.junit.jupiter.api.Test;
2022

@@ -26,8 +28,8 @@ void dummy() {
2628

2729
@Override
2830
@Test
29-
public void shouldFetchPostWithBlogWithCompositeKey() throws Exception {
30-
super.shouldFetchPostWithBlogWithCompositeKey();
31+
public void shouldFetchPostWithBlogWithCompositeKey() {
32+
assertDoesNotThrow(super::shouldFetchPostWithBlogWithCompositeKey);
3133
}
3234

3335
@Override

src/test/java/org/apache/ibatis/jdbc/PooledDataSourceTest.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.apache.ibatis.jdbc;
1717

18+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1819
import static org.junit.jupiter.api.Assertions.assertEquals;
1920
import static org.junit.jupiter.api.Assertions.assertNotNull;
2021

@@ -72,19 +73,23 @@ void shouldProperlyMaintainPoolOf3ActiveAnd2IdleConnections() throws Exception {
7273
}
7374

7475
@Test
75-
void shouldNotFailCallingToStringOverAnInvalidConnection() throws Exception {
76-
PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
77-
Connection c = ds.getConnection();
78-
c.close();
79-
c.toString();
76+
void shouldNotFailCallingToStringOverAnInvalidConnection() {
77+
assertDoesNotThrow(() -> {
78+
PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
79+
Connection c = ds.getConnection();
80+
c.close();
81+
c.toString();
82+
});
8083
}
8184

8285
@Test
83-
void ShouldReturnRealConnection() throws Exception {
84-
PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
85-
Connection c = ds.getConnection();
86-
PooledDataSource.unwrapConnection(c);
87-
c.close();
86+
void ShouldReturnRealConnection() {
87+
assertDoesNotThrow(() -> {
88+
PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
89+
Connection c = ds.getConnection();
90+
PooledDataSource.unwrapConnection(c);
91+
c.close();
92+
});
8893
}
8994

9095
}

src/test/java/org/apache/ibatis/submitted/integer_enum/IntegerEnumTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.apache.ibatis.submitted.integer_enum;
1717

18+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
19+
1820
import java.io.Reader;
1921

2022
import org.apache.ibatis.BaseDataTest;
@@ -25,11 +27,13 @@
2527
class IntegerEnumTest extends BaseDataTest {
2628

2729
@Test
28-
void shouldParseMapWithIntegerJdbcType() throws Exception {
29-
String resource = "org/apache/ibatis/submitted/integer_enum/MapperConfig.xml";
30-
Reader reader = Resources.getResourceAsReader(resource);
31-
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
32-
builder.build(reader);
30+
void shouldParseMapWithIntegerJdbcType() {
31+
assertDoesNotThrow(() -> {
32+
String resource = "org/apache/ibatis/submitted/integer_enum/MapperConfig.xml";
33+
Reader reader = Resources.getResourceAsReader(resource);
34+
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
35+
builder.build(reader);
36+
});
3337
}
3438

3539
}

src/test/java/org/apache/ibatis/submitted/map_class_name_conflict/MapperNameTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616
package org.apache.ibatis.submitted.map_class_name_conflict;
1717

18-
import java.io.IOException;
18+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
19+
1920
import java.io.Reader;
2021

2122
import org.apache.ibatis.io.Resources;
@@ -25,9 +26,11 @@
2526
class MapperNameTest {
2627

2728
@Test
28-
void initDatabase() throws IOException {
29-
String resource = "org/apache/ibatis/submitted/map_class_name_conflict/ibatisConfig.xml";
30-
Reader reader = Resources.getResourceAsReader(resource);
31-
new SqlSessionFactoryBuilder().build(reader);
29+
void initDatabase() {
30+
assertDoesNotThrow(() -> {
31+
String resource = "org/apache/ibatis/submitted/map_class_name_conflict/ibatisConfig.xml";
32+
Reader reader = Resources.getResourceAsReader(resource);
33+
new SqlSessionFactoryBuilder().build(reader);
34+
});
3235
}
3336
}

src/test/java/org/apache/ibatis/submitted/refid_resolution/ExternalRefidResolutionTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.apache.ibatis.submitted.refid_resolution;
1717

18+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
19+
1820
import java.io.Reader;
1921

2022
import org.apache.ibatis.io.Resources;
@@ -27,12 +29,14 @@
2729
*/
2830
class ExternalRefidResolutionTest {
2931
@Test
30-
void externalRefAfterSelectKey() throws Exception {
31-
String resource = "org/apache/ibatis/submitted/refid_resolution/ExternalMapperConfig.xml";
32-
try (Reader reader = Resources.getResourceAsReader(resource)) {
33-
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
34-
SqlSessionFactory sqlSessionFactory = builder.build(reader);
35-
sqlSessionFactory.getConfiguration().getMappedStatementNames();
36-
}
32+
void externalRefAfterSelectKey() {
33+
assertDoesNotThrow(() -> {
34+
String resource = "org/apache/ibatis/submitted/refid_resolution/ExternalMapperConfig.xml";
35+
try (Reader reader = Resources.getResourceAsReader(resource)) {
36+
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
37+
SqlSessionFactory sqlSessionFactory = builder.build(reader);
38+
sqlSessionFactory.getConfiguration().getMappedStatementNames();
39+
}
40+
});
3741
}
3842
}

src/test/java/org/apache/ibatis/submitted/serializecircular/SerializeCircularTest.java

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.apache.ibatis.submitted.serializecircular;
1717

18+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
19+
1820
import java.io.Reader;
1921

2022
import org.apache.ibatis.BaseDataTest;
@@ -27,32 +29,40 @@
2729
class SerializeCircularTest {
2830

2931
@Test
30-
void serializeAndDeserializeObjectsWithAggressiveLazyLoadingWithoutPreloadingAttribute() throws Exception {
31-
try (SqlSession sqlSession = createSessionWithAggressiveLazyLoading()) {
32-
testSerializeWithoutPreloadingAttribute(sqlSession);
33-
}
32+
void serializeAndDeserializeObjectsWithAggressiveLazyLoadingWithoutPreloadingAttribute() {
33+
assertDoesNotThrow(() -> {
34+
try (SqlSession sqlSession = createSessionWithAggressiveLazyLoading()) {
35+
testSerializeWithoutPreloadingAttribute(sqlSession);
36+
}
37+
});
3438
}
3539

3640
@Test
37-
void serializeAndDeserializeObjectsWithAggressiveLazyLoadingWithPreloadingAttribute() throws Exception {
38-
try (SqlSession sqlSession = createSessionWithAggressiveLazyLoading()) {
39-
testSerializeWithPreloadingAttribute(sqlSession);
40-
}
41+
void serializeAndDeserializeObjectsWithAggressiveLazyLoadingWithPreloadingAttribute() {
42+
assertDoesNotThrow(() -> {
43+
try (SqlSession sqlSession = createSessionWithAggressiveLazyLoading()) {
44+
testSerializeWithPreloadingAttribute(sqlSession);
45+
}
46+
});
4147
}
4248

4349
@Test
44-
void serializeAndDeserializeObjectsWithoutAggressiveLazyLoadingWithoutPreloadingAttribute() throws Exception {
45-
try (SqlSession sqlSession = createSessionWithoutAggressiveLazyLoading()) {
46-
// expected problem with deserializing
47-
testSerializeWithoutPreloadingAttribute(sqlSession);
48-
}
50+
void serializeAndDeserializeObjectsWithoutAggressiveLazyLoadingWithoutPreloadingAttribute() {
51+
assertDoesNotThrow(() -> {
52+
try (SqlSession sqlSession = createSessionWithoutAggressiveLazyLoading()) {
53+
// expected problem with deserializing
54+
testSerializeWithoutPreloadingAttribute(sqlSession);
55+
}
56+
});
4957
}
5058

5159
@Test
52-
void serializeAndDeserializeObjectsWithoutAggressiveLazyLoadingWithPreloadingAttribute() throws Exception {
53-
try (SqlSession sqlSession = createSessionWithoutAggressiveLazyLoading()) {
54-
testSerializeWithPreloadingAttribute(sqlSession);
55-
}
60+
void serializeAndDeserializeObjectsWithoutAggressiveLazyLoadingWithPreloadingAttribute() {
61+
assertDoesNotThrow(() -> {
62+
try (SqlSession sqlSession = createSessionWithoutAggressiveLazyLoading()) {
63+
testSerializeWithPreloadingAttribute(sqlSession);
64+
}
65+
});
5666
}
5767

5868
private SqlSession createSessionWithoutAggressiveLazyLoading() throws Exception {

src/test/java/org/apache/ibatis/submitted/xml_references/EnumWithOgnlTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.apache.ibatis.submitted.xml_references;
1717

18+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
19+
1820
import java.io.Reader;
1921
import java.util.Properties;
2022

@@ -48,10 +50,13 @@ void configuration() {
4850
}
4951

5052
@Test
51-
void mixedConfiguration() throws Exception {
52-
try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_references/ibatisConfig.xml")) {
53-
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
54-
sqlSessionFactory.getConfiguration().addMapper(PersonMapper2.class);
55-
}
53+
void mixedConfiguration() {
54+
assertDoesNotThrow(() -> {
55+
try (Reader reader = Resources
56+
.getResourceAsReader("org/apache/ibatis/submitted/xml_references/ibatisConfig.xml")) {
57+
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
58+
sqlSessionFactory.getConfiguration().addMapper(PersonMapper2.class);
59+
}
60+
});
5661
}
5762
}

0 commit comments

Comments
 (0)