1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.type;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19 import static org.junit.jupiter.api.Assertions.assertNull;
20 import static org.mockito.Mockito.never;
21 import static org.mockito.Mockito.verify;
22 import static org.mockito.Mockito.when;
23
24 import java.sql.Timestamp;
25 import java.time.Instant;
26
27 import org.junit.jupiter.api.Test;
28
29 class InstantTypeHandlerTest extends BaseTypeHandlerTest {
30
31 private static final TypeHandler<Instant> TYPE_HANDLER = new InstantTypeHandler();
32 private static final Instant INSTANT = Instant.now();
33 private static final Timestamp TIMESTAMP = Timestamp.from(INSTANT);
34
35 @Override
36 @Test
37 public void shouldSetParameter() throws Exception {
38 TYPE_HANDLER.setParameter(ps, 1, INSTANT, null);
39 verify(ps).setTimestamp(1, TIMESTAMP);
40 }
41
42 @Override
43 @Test
44 public void shouldGetResultFromResultSetByName() throws Exception {
45 when(rs.getTimestamp("column")).thenReturn(TIMESTAMP);
46 assertEquals(INSTANT, TYPE_HANDLER.getResult(rs, "column"));
47 verify(rs, never()).wasNull();
48 }
49
50 @Override
51 @Test
52 public void shouldGetResultNullFromResultSetByName() throws Exception {
53 when(rs.getTimestamp("column")).thenReturn(null);
54 assertNull(TYPE_HANDLER.getResult(rs, "column"));
55 verify(rs, never()).wasNull();
56 }
57
58 @Override
59 @Test
60 public void shouldGetResultFromResultSetByPosition() throws Exception {
61 when(rs.getTimestamp(1)).thenReturn(TIMESTAMP);
62 assertEquals(INSTANT, TYPE_HANDLER.getResult(rs, 1));
63 verify(rs, never()).wasNull();
64 }
65
66 @Override
67 @Test
68 public void shouldGetResultNullFromResultSetByPosition() throws Exception {
69 when(rs.getTimestamp(1)).thenReturn(null);
70 assertNull(TYPE_HANDLER.getResult(rs, 1));
71 verify(rs, never()).wasNull();
72 }
73
74 @Override
75 @Test
76 public void shouldGetResultFromCallableStatement() throws Exception {
77 when(cs.getTimestamp(1)).thenReturn(TIMESTAMP);
78 assertEquals(INSTANT, TYPE_HANDLER.getResult(cs, 1));
79 verify(cs, never()).wasNull();
80 }
81
82 @Override
83 @Test
84 public void shouldGetResultNullFromCallableStatement() throws Exception {
85 when(cs.getTimestamp(1)).thenReturn(null);
86 assertNull(TYPE_HANDLER.getResult(cs, 1));
87 verify(cs, never()).wasNull();
88 }
89 }