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.YearMonth;
25
26 import org.junit.jupiter.api.Test;
27
28
29
30
31 class YearMonthTypeHandlerTest extends BaseTypeHandlerTest {
32
33 private static final TypeHandler<YearMonth> TYPE_HANDLER = new YearMonthTypeHandler();
34 private static final YearMonth INSTANT = YearMonth.now();
35
36 @Override
37 @Test
38 public void shouldSetParameter() throws Exception {
39 TYPE_HANDLER.setParameter(ps, 1, INSTANT, null);
40 verify(ps).setString(1, INSTANT.toString());
41 }
42
43 @Override
44 @Test
45 public void shouldGetResultFromResultSetByName() throws Exception {
46 when(rs.getString("column")).thenReturn(INSTANT.toString());
47 assertEquals(INSTANT, TYPE_HANDLER.getResult(rs, "column"));
48 verify(rs, never()).wasNull();
49 }
50
51 @Override
52 @Test
53 public void shouldGetResultNullFromResultSetByName() throws Exception {
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.getString(1)).thenReturn(INSTANT.toString());
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 assertNull(TYPE_HANDLER.getResult(rs, 1));
70 verify(rs, never()).wasNull();
71 }
72
73 @Override
74 @Test
75 public void shouldGetResultFromCallableStatement() throws Exception {
76 when(cs.getString(1)).thenReturn(INSTANT.toString());
77 assertEquals(INSTANT, TYPE_HANDLER.getResult(cs, 1));
78 verify(cs, never()).wasNull();
79 }
80
81 @Override
82 @Test
83 public void shouldGetResultNullFromCallableStatement() throws Exception {
84 assertNull(TYPE_HANDLER.getResult(cs, 1));
85 verify(cs, never()).wasNull();
86 }
87
88 }