1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.localtime;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19
20 import java.io.Reader;
21 import java.time.LocalTime;
22 import java.util.TimeZone;
23
24 import org.apache.ibatis.BaseDataTest;
25 import org.apache.ibatis.io.Resources;
26 import org.apache.ibatis.session.SqlSession;
27 import org.apache.ibatis.session.SqlSessionFactory;
28 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
29 import org.junit.jupiter.api.BeforeAll;
30 import org.junit.jupiter.api.Test;
31
32 class LocalTimeTest {
33
34 private static SqlSessionFactory sqlSessionFactory;
35
36 @BeforeAll
37 static void setUp() throws Exception {
38 try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/localtime/mybatis-config.xml")) {
39 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
40 }
41 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
42 "org/apache/ibatis/submitted/localtime/CreateDB.sql");
43 }
44
45 @Test
46 void shouldSelectLocalTimeWithNanoseconds() {
47 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
48 Mapper mapper = sqlSession.getMapper(Mapper.class);
49 Record record = mapper.selectById(1);
50 assertEquals(LocalTime.of(11, 22, 33, 123456789), record.getT());
51 }
52 }
53
54 @Test
55 void shouldInsertLocalTimeWithNanoseconds() {
56 TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
57 LocalTime t = LocalTime.of(11, 22, 33, 123456789);
58 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
59 Mapper mapper = sqlSession.getMapper(Mapper.class);
60 Record record = new Record();
61 record.setId(2);
62 record.setT(t);
63 int result = mapper.insertLocalTime(record);
64 assertEquals(1, result);
65 sqlSession.commit();
66 }
67 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
68 Mapper mapper = sqlSession.getMapper(Mapper.class);
69 Record record = mapper.selectById(2);
70 assertEquals(t, record.getT());
71 }
72 }
73
74 }