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.LocalDate;
25
26 import org.junit.jupiter.api.Test;
27
28 class LocalDateTypeHandlerTest extends BaseTypeHandlerTest {
29
30 private static final TypeHandler<LocalDate> TYPE_HANDLER = new LocalDateTypeHandler();
31 private static final LocalDate LOCAL_DATE = LocalDate.now();
32
33 @Override
34 @Test
35 public void shouldSetParameter() throws Exception {
36 TYPE_HANDLER.setParameter(ps, 1, LOCAL_DATE, null);
37 verify(ps).setObject(1, LOCAL_DATE);
38 }
39
40 @Override
41 @Test
42 public void shouldGetResultFromResultSetByName() throws Exception {
43 when(rs.getObject("column", LocalDate.class)).thenReturn(LOCAL_DATE);
44 assertEquals(LOCAL_DATE, 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", LocalDate.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, LocalDate.class)).thenReturn(LOCAL_DATE);
60 assertEquals(LOCAL_DATE, 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, LocalDate.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, LocalDate.class)).thenReturn(LOCAL_DATE);
76 assertEquals(LOCAL_DATE, 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, LocalDate.class)).thenReturn(null);
84 assertNull(TYPE_HANDLER.getResult(cs, 1));
85 verify(cs, never()).wasNull();
86 }
87 }