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.time.OffsetDateTime;
25
26 import org.junit.jupiter.api.Test;
27
28 class OffsetDateTimeTypeHandlerTest extends BaseTypeHandlerTest {
29
30 private static final TypeHandler<OffsetDateTime> TYPE_HANDLER = new OffsetDateTimeTypeHandler();
31 private static final OffsetDateTime OFFSET_DATE_TIME = OffsetDateTime.now();
32
33 @Override
34 @Test
35 public void shouldSetParameter() throws Exception {
36 TYPE_HANDLER.setParameter(ps, 1, OFFSET_DATE_TIME, null);
37 verify(ps).setObject(1, OFFSET_DATE_TIME);
38 }
39
40 @Override
41 @Test
42 public void shouldGetResultFromResultSetByName() throws Exception {
43 when(rs.getObject("column", OffsetDateTime.class)).thenReturn(OFFSET_DATE_TIME);
44 assertEquals(OFFSET_DATE_TIME, TYPE_HANDLER.getResult(rs, "column"));
45 verify(rs, never()).wasNull();
46 }
47
48 @Override
49 @Test
50 public void shouldGetResultNullFromResultSetByName() throws Exception {
51 when(rs.getObject("column", OffsetDateTime.class)).thenReturn(null);
52 assertNull(TYPE_HANDLER.getResult(rs, "column"));
53 verify(rs, never()).wasNull();
54 }
55
56 @Override
57 @Test
58 public void shouldGetResultFromResultSetByPosition() throws Exception {
59 when(rs.getObject(1, OffsetDateTime.class)).thenReturn(OFFSET_DATE_TIME);
60 assertEquals(OFFSET_DATE_TIME, TYPE_HANDLER.getResult(rs, 1));
61 verify(rs, never()).wasNull();
62 }
63
64 @Override
65 @Test
66 public void shouldGetResultNullFromResultSetByPosition() throws Exception {
67 when(rs.getObject(1, OffsetDateTime.class)).thenReturn(null);
68 assertNull(TYPE_HANDLER.getResult(rs, 1));
69 verify(rs, never()).wasNull();
70 }
71
72 @Override
73 @Test
74 public void shouldGetResultFromCallableStatement() throws Exception {
75 when(cs.getObject(1, OffsetDateTime.class)).thenReturn(OFFSET_DATE_TIME);
76 assertEquals(OFFSET_DATE_TIME, TYPE_HANDLER.getResult(cs, 1));
77 verify(cs, never()).wasNull();
78 }
79
80 @Override
81 @Test
82 public void shouldGetResultNullFromCallableStatement() throws Exception {
83 when(cs.getObject(1, OffsetDateTime.class)).thenReturn(null);
84 assertNull(TYPE_HANDLER.getResult(cs, 1));
85 verify(cs, never()).wasNull();
86 }
87
88 }