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