Skip to content

Commit

Permalink
完善测试
Browse files Browse the repository at this point in the history
  • Loading branch information
abel533 committed Dec 11, 2015
1 parent b46057e commit 3a9cc73
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/test/java/tk/mybatis/mapper/model/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
* @since 2015-12-06 10:31
*/
public class Entity<ID extends Serializable, NAME extends Serializable> {
//这里的a,b,c,d仅用来测试FieldHelper中的静态字段
private static Integer a, b, c, d;

private ID id;

Expand Down
20 changes: 20 additions & 0 deletions src/test/java/tk/mybatis/mapper/test/country/TestSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ public void testDynamicSelectPage() {
}
}

/**
* 查询全部
*/
@Test
public void testAllColumns() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
Country country = new Country();
//35,'China','CN'
country.setCountrycode("CN");
country.setId(35);
country.setCountryname("China");
List<Country> countryList = mapper.select(country);
Assert.assertEquals(1, countryList.size());
} finally {
sqlSession.close();
}
}

/**
* 入参为null时查询全部
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void testDynamicUpdateByPrimaryKey() {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
Country country = new Country();
country.setId(174);
country.setCountryname(null);
country.setCountryname("美国");
Assert.assertEquals(1, mapper.updateByPrimaryKey(country));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,19 @@ public void testSelectColumnsByExample() {
}
}

@Test
public void testOrderBy() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
Example example = new Example(Country.class);
example.setOrderByClause("id desc");
List<Country> countries = mapper.selectByExample(example);
//查询总数
Assert.assertEquals(183, (int) countries.get(0).getId());
} finally {
sqlSession.close();
}
}

}

0 comments on commit 3a9cc73

Please sign in to comment.