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