Skip to content

Commit 7e7474c

Browse files
committed
完善测试。
1 parent 59b4f4e commit 7e7474c

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

src/test/java/com/github/abel533/mapper/MybatisJavaHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class MybatisJavaHelper {
5252
// 注册通用Mapper接口 - 可以自动注册继承的接口
5353
mapperHelper.registerMapper(Mapper.class);
5454
mapperHelper.registerMapper(HsqldbMapper.class);
55+
mapperHelper.registerMapper(MySqlMapper.class);
5556
//配置完成后,执行下面的操作
5657
mapperHelper.processConfiguration(session.getConfiguration());
5758
//OK - mapperHelper的任务已经完成,可以不管了

src/test/java/com/github/abel533/test/jdbc/TestJDBC.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import org.junit.Assert;
3232
import org.junit.Test;
3333

34-
import java.util.List;
35-
3634
/**
3735
* Created by liuzh on 2014/11/21.
3836
*/
@@ -46,19 +44,11 @@ public void testJDBC() {
4644
try {
4745
CountryJDBCMapper mapper = sqlSession.getMapper(CountryJDBCMapper.class);
4846
CountryJDBC country = new CountryJDBC();
49-
country.setId(10086);
5047
country.setCountrycode("CN");
5148
Assert.assertEquals(1, mapper.insert(country));
52-
53-
//查询CN结果
54-
country = new CountryJDBC();
55-
country.setCountrycode("CN");
56-
List<CountryJDBC> list = mapper.select(country);
57-
58-
Assert.assertEquals(1, list.size());
59-
//删除插入的数据,以免对其他测试产生影响
60-
Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086));
49+
Assert.assertNotNull(country.getId());
6150
} finally {
51+
sqlSession.rollback();
6252
sqlSession.close();
6353
}
6454
}

src/test/java/com/github/abel533/test/mysql/TestInsertList.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.github.abel533.test.mysql;
22

3-
import com.github.abel533.entity.Example;
43
import com.github.abel533.mapper.CountryMapper;
54
import com.github.abel533.mapper.MybatisHelper;
65
import com.github.abel533.model.Country;
76
import org.apache.ibatis.session.SqlSession;
87
import org.junit.Assert;
8+
import org.junit.Test;
99

1010
import java.util.ArrayList;
1111
import java.util.List;
@@ -21,28 +21,23 @@ public class TestInsertList {
2121
* 插入完整数据
2222
*/
2323
//该方法测试需要mysql或者h2数据库,所以这里注释掉
24-
//@Test
24+
@Test
2525
public void testInsert() {
2626
SqlSession sqlSession = MybatisHelper.getSqlSession();
2727
try {
2828
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
2929
List<Country> countryList = new ArrayList<Country>();
3030
for (int i = 0; i < 10; i++) {
3131
Country country = new Country();
32-
country.setId(10086 + i);
3332
country.setCountrycode("CN" + i);
3433
country.setCountryname("天朝" + i);
3534
countryList.add(country);
3635
}
3736
int count = mapper.insertList(countryList);
3837
Assert.assertEquals(10, count);
39-
40-
41-
Example example = new Example(Country.class);
42-
example.createCriteria().andGreaterThanOrEqualTo("id",10086);
43-
List<Country> list = mapper.selectByExample(example);
44-
45-
Assert.assertEquals("CN2",list.get(2).getCountrycode());
38+
for (Country country : countryList) {
39+
Assert.assertNotNull(country.getId());
40+
}
4641
} finally {
4742
sqlSession.rollback();
4843
sqlSession.close();

0 commit comments

Comments
 (0)