Skip to content

Commit 7b0a10c

Browse files
committed
Ploshing test code
1 parent 2f2a721 commit 7b0a10c

File tree

4 files changed

+46
-47
lines changed

4 files changed

+46
-47
lines changed

src/test/java/org/mybatis/scripting/freemarker/CustomizedDataContextTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
/**
4242
* @author elwood
4343
*/
44-
public class CustomizedDataContextTest {
45-
protected static SqlSessionFactory sqlSessionFactory;
44+
class CustomizedDataContextTest {
45+
private static SqlSessionFactory sqlSessionFactory;
4646

4747
@BeforeAll
48-
public static void setUp() throws Exception {
48+
static void setUp() throws Exception {
4949
Class.forName("org.hsqldb.jdbcDriver");
5050

5151
JDBCDataSource dataSource = new JDBCDataSource();
@@ -75,11 +75,12 @@ public static void setUp() throws Exception {
7575
}
7676

7777
public static class CustomSqlSource extends FreeMarkerSqlSource {
78-
public CustomSqlSource(Template template, Configuration configuration, Version version) {
78+
CustomSqlSource(Template template, Configuration configuration, Version version) {
7979
super(template, configuration, version);
8080
}
8181

8282
@Override
83+
@SuppressWarnings("unchecked")
8384
protected Object preProcessDataContext(Object dataContext, boolean isMap) {
8485
dataContext = super.preProcessDataContext(dataContext, isMap);
8586
if (isMap) {
@@ -99,11 +100,11 @@ protected SqlSource createSqlSource(Template template, Configuration configurati
99100
}
100101

101102
@Test
102-
public void test() {
103+
void test() {
103104
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
104105
CustomizedDataContextMapper mapper = sqlSession.getMapper(CustomizedDataContextMapper.class);
105106
List<Name> names = mapper.find();
106-
Assertions.assertTrue(names.size() == 1);
107+
Assertions.assertEquals(1, names.size());
107108
}
108109
}
109110
}

src/test/java/org/mybatis/scripting/freemarker/FreeMarkerInAnnotationsTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-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.
@@ -39,11 +39,11 @@
3939
*
4040
* @author elwood
4141
*/
42-
public class FreeMarkerInAnnotationsTest {
43-
protected static SqlSessionFactory sqlSessionFactory;
42+
class FreeMarkerInAnnotationsTest {
43+
private static SqlSessionFactory sqlSessionFactory;
4444

4545
@BeforeAll
46-
public static void setUp() throws Exception {
46+
static void setUp() throws Exception {
4747
Class.forName("org.hsqldb.jdbcDriver");
4848

4949
JDBCDataSource dataSource = new JDBCDataSource();
@@ -73,16 +73,16 @@ public static void setUp() throws Exception {
7373
}
7474

7575
@Test
76-
public void testNoParamsCall() {
76+
void testNoParamsCall() {
7777
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
7878
NameMapper mapper = sqlSession.getMapper(NameMapper.class);
7979
List<Name> allNames = mapper.getAllNames();
80-
Assertions.assertTrue(allNames.size() == 5);
80+
Assertions.assertEquals(5, allNames.size());
8181
}
8282
}
8383

8484
@Test
85-
public void testMyBatisParamCall() {
85+
void testMyBatisParamCall() {
8686
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
8787
NameMapper mapper = sqlSession.getMapper(NameMapper.class);
8888
Name pebble = mapper.findName("Pebbles");
@@ -91,7 +91,7 @@ public void testMyBatisParamCall() {
9191
}
9292

9393
@Test
94-
public void testInQuery() {
94+
void testInQuery() {
9595
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
9696
NameMapper mapper = sqlSession.getMapper(NameMapper.class);
9797
List<Name> namesByIds = mapper.findNamesByIds(new ArrayList<Integer>() {
@@ -102,12 +102,12 @@ public void testInQuery() {
102102
add(4);
103103
}
104104
});
105-
Assertions.assertTrue(namesByIds.size() == 3);
105+
Assertions.assertEquals(3, namesByIds.size());
106106
}
107107
}
108108

109109
@Test
110-
public void testParamObject() {
110+
void testParamObject() {
111111
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
112112
NameMapper mapper = sqlSession.getMapper(NameMapper.class);
113113
Name name = mapper.find(new NameParam(4));
@@ -116,15 +116,15 @@ public void testParamObject() {
116116
}
117117

118118
@Test
119-
public void testStringParam() {
119+
void testStringParam() {
120120
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
121121
NameMapper mapper = sqlSession.getMapper(NameMapper.class);
122122
List<Name> stdLangResult = mapper.getNamesOddBehaviourStdLang("Pebbles");
123123
List<Name> freeMarkerLangResult = mapper.getNamesOddBehaviourFreeMarkerLang("Pebbles");
124-
Assertions.assertTrue(stdLangResult.size() == 1);
125-
Assertions.assertTrue(stdLangResult.get(0).getFirstName().equals("Pebbles"));
126-
Assertions.assertTrue(freeMarkerLangResult.size() == 1);
127-
Assertions.assertTrue(freeMarkerLangResult.get(0).getFirstName().equals("Pebbles"));
124+
Assertions.assertEquals(1, stdLangResult.size());
125+
Assertions.assertEquals("Pebbles", stdLangResult.get(0).getFirstName());
126+
Assertions.assertEquals(1, freeMarkerLangResult.size());
127+
Assertions.assertEquals("Pebbles", freeMarkerLangResult.get(0).getFirstName());
128128
}
129129
}
130130
}

src/test/java/org/mybatis/scripting/freemarker/FreeMarkerInXmlTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-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.
@@ -36,11 +36,11 @@
3636
*
3737
* @author elwood
3838
*/
39-
public class FreeMarkerInXmlTest {
40-
protected static SqlSessionFactory sqlSessionFactory;
39+
class FreeMarkerInXmlTest {
40+
private static SqlSessionFactory sqlSessionFactory;
4141

4242
@BeforeAll
43-
public static void setUp() throws Exception {
43+
static void setUp() throws Exception {
4444
Connection conn = null;
4545

4646
try {
@@ -67,15 +67,15 @@ public static void setUp() throws Exception {
6767
}
6868

6969
@Test
70-
public void testNoParamsCall() {
70+
void testNoParamsCall() {
7171
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
7272
List<Name> allNames = sqlSession.selectList("getAllNames");
73-
Assertions.assertTrue(allNames.size() == 5);
73+
Assertions.assertEquals(5, allNames.size());
7474
}
7575
}
7676

7777
@Test
78-
public void testMyBatisParamCall() {
78+
void testMyBatisParamCall() {
7979
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
8080
HashMap<String, Object> paramsMap = new HashMap<>();
8181
paramsMap.put("name", "Pebbles");
@@ -85,7 +85,7 @@ public void testMyBatisParamCall() {
8585
}
8686

8787
@Test
88-
public void testInQuery() {
88+
void testInQuery() {
8989
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
9090
HashMap<String, Object> paramsMap = new HashMap<>();
9191
paramsMap.put("ids", new ArrayList<Integer>() {
@@ -97,27 +97,27 @@ public void testInQuery() {
9797
}
9898
});
9999
List<Name> namesByIds = sqlSession.selectList("findNamesByIds", paramsMap);
100-
Assertions.assertTrue(namesByIds.size() == 3);
100+
Assertions.assertEquals(3, namesByIds.size());
101101
}
102102
}
103103

104104
@Test
105-
public void testParamObject() {
105+
void testParamObject() {
106106
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
107107
Name name = sqlSession.selectOne("find", new NameParam(4));
108108
Assertions.assertTrue(name != null && name.getId() == 4);
109109
}
110110
}
111111

112112
@Test
113-
public void testStringParam() {
113+
void testStringParam() {
114114
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
115115
List<Name> stdLangResult = sqlSession.selectList("getNamesOddBehaviourStdLang", "Pebbles");
116116
List<Name> freeMarkerLangResult = sqlSession.selectList("getNamesOddBehaviourFreeMarkerLang", "Pebbles");
117-
Assertions.assertTrue(stdLangResult.size() == 1);
118-
Assertions.assertTrue(stdLangResult.get(0).getFirstName().equals("Pebbles"));
119-
Assertions.assertTrue(freeMarkerLangResult.size() == 1);
120-
Assertions.assertTrue(freeMarkerLangResult.get(0).getFirstName().equals("Pebbles"));
117+
Assertions.assertEquals(1, stdLangResult.size());
118+
Assertions.assertEquals("Pebbles", stdLangResult.get(0).getFirstName());
119+
Assertions.assertEquals(1, freeMarkerLangResult.size());
120+
Assertions.assertEquals("Pebbles", freeMarkerLangResult.get(0).getFirstName());
121121
}
122122
}
123123
}

src/test/java/org/mybatis/scripting/freemarker/PreparedParamsTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-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.
@@ -40,11 +40,11 @@
4040
*
4141
* @author elwood
4242
*/
43-
public class PreparedParamsTest {
44-
protected static SqlSessionFactory sqlSessionFactory;
43+
class PreparedParamsTest {
44+
private static SqlSessionFactory sqlSessionFactory;
4545

4646
@BeforeAll
47-
public static void setUp() throws Exception {
47+
static void setUp() throws Exception {
4848
Class.forName("org.hsqldb.jdbcDriver");
4949

5050
JDBCDataSource dataSource = new JDBCDataSource();
@@ -74,7 +74,7 @@ public static void setUp() throws Exception {
7474
}
7575

7676
@Test
77-
public void testInCall() {
77+
void testInCall() {
7878
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
7979
PreparedParamsMapper mapper = sqlSession.getMapper(PreparedParamsMapper.class);
8080
List<Name> names = mapper.findByNames(new ArrayList<String>() {
@@ -85,25 +85,23 @@ public void testInCall() {
8585
add("Betty");
8686
}
8787
});
88-
Assertions.assertTrue(names.size() == 3);
88+
Assertions.assertEquals(3, names.size());
8989
}
9090
}
9191

9292
/**
9393
* PersistenceException will be thrown with cause of UnsupportedOperationException
9494
*/
9595
@Test
96-
public void testParamsObjectCall() {
96+
void testParamsObjectCall() {
9797
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
9898
final PreparedParamsMapper mapper = sqlSession.getMapper(PreparedParamsMapper.class);
99-
Assertions.assertThrows(PersistenceException.class, () -> {
100-
mapper.findUsingParamsObject(new PreparedParam());
101-
});
99+
Assertions.assertThrows(PersistenceException.class, () -> mapper.findUsingParamsObject(new PreparedParam()));
102100
}
103101
}
104102

105103
@Test
106-
public void testNoParamsCall() {
104+
void testNoParamsCall() {
107105
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
108106
PreparedParamsMapper mapper = sqlSession.getMapper(PreparedParamsMapper.class);
109107
Name name = mapper.findUsingParams(new PreparedParam.InnerClass());

0 commit comments

Comments
 (0)