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