|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -package sample.mybatis; |
| 17 | +package sample.mybatis.dao; |
18 | 18 |
|
19 |
| -import org.apache.ibatis.session.SqlSession; |
20 | 19 | import org.junit.Test;
|
21 | 20 | import org.junit.runner.RunWith;
|
22 | 21 | import org.mybatis.spring.boot.test.autoconfigure.MybatisTest;
|
23 | 22 | import org.springframework.beans.factory.annotation.Autowired;
|
24 |
| -import org.springframework.boot.test.context.TestConfiguration; |
25 |
| -import org.springframework.context.annotation.Bean; |
| 23 | +import org.springframework.context.annotation.Import; |
26 | 24 | import org.springframework.test.context.junit4.SpringRunner;
|
27 |
| -import sample.mybatis.dao.CityDao; |
28 | 25 | import sample.mybatis.domain.City;
|
29 | 26 |
|
30 | 27 | import static org.assertj.core.api.Assertions.assertThat;
|
31 | 28 |
|
32 | 29 | /**
|
| 30 | + * Tests for {@link CityDao}. |
33 | 31 | * @author wonwoo
|
34 | 32 | * @since 1.2.1
|
35 | 33 | */
|
36 | 34 | @RunWith(SpringRunner.class)
|
37 | 35 | @MybatisTest
|
38 |
| -public class SampleSqlSessionTest { |
| 36 | +@Import(CityDao.class) |
| 37 | +public class CityDaoTest { |
39 | 38 |
|
40 | 39 | @Autowired
|
41 |
| - private SqlSession sqlSession; |
42 |
| - |
43 |
| - @Test |
44 |
| - public void sqlSessionIsNotNullTest() { |
45 |
| - assertThat(sqlSession).isNotNull(); |
46 |
| - } |
| 40 | + private CityDao cityDao; |
47 | 41 |
|
48 | 42 | @Test
|
49 | 43 | public void selectCityByIdTest() {
|
50 |
| - City city = sqlSession.selectOne("selectCityById", 1); |
| 44 | + City city = cityDao.selectCityById(1); |
51 | 45 | assertThat(city.getName()).isEqualTo("San Francisco");
|
52 | 46 | assertThat(city.getState()).isEqualTo("CA");
|
53 | 47 | assertThat(city.getCountry()).isEqualTo("US");
|
54 | 48 | }
|
55 | 49 |
|
56 |
| - @TestConfiguration |
57 |
| - public static class Config { |
58 |
| - @Bean |
59 |
| - public CityDao cityDao(SqlSession sqlSession) { |
60 |
| - return new CityDao(sqlSession); |
61 |
| - } |
62 |
| - } |
63 | 50 | }
|
0 commit comments