View Javadoc
1   /*
2    *    Copyright 2009-2023 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
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 ObjectTypeHandlerTest extends BaseTypeHandlerTest {
26  
27    private static final TypeHandler<Object> TYPE_HANDLER = new ObjectTypeHandler();
28  
29    @Override
30    @Test
31    public void shouldSetParameter() throws Exception {
32      TYPE_HANDLER.setParameter(ps, 1, "Hello", null);
33      verify(ps).setObject(1, "Hello");
34    }
35  
36    @Override
37    @Test
38    public void shouldGetResultFromResultSetByName() throws Exception {
39      when(rs.getObject("column")).thenReturn("Hello");
40      assertEquals("Hello", TYPE_HANDLER.getResult(rs, "column"));
41    }
42  
43    @Override
44    @Test
45    public void shouldGetResultNullFromResultSetByName() throws Exception {
46      when(rs.getObject("column")).thenReturn(null);
47      assertNull(TYPE_HANDLER.getResult(rs, "column"));
48    }
49  
50    @Override
51    @Test
52    public void shouldGetResultFromResultSetByPosition() throws Exception {
53      when(rs.getObject(1)).thenReturn("Hello");
54      assertEquals("Hello", TYPE_HANDLER.getResult(rs, 1));
55    }
56  
57    @Override
58    @Test
59    public void shouldGetResultNullFromResultSetByPosition() throws Exception {
60      when(rs.getObject(1)).thenReturn(null);
61      assertNull(TYPE_HANDLER.getResult(rs, 1));
62    }
63  
64    @Override
65    @Test
66    public void shouldGetResultFromCallableStatement() throws Exception {
67      when(cs.getObject(1)).thenReturn("Hello");
68      assertEquals("Hello", TYPE_HANDLER.getResult(cs, 1));
69    }
70  
71    @Override
72    @Test
73    public void shouldGetResultNullFromCallableStatement() throws Exception {
74      when(cs.getObject(1)).thenReturn(null);
75      assertNull(TYPE_HANDLER.getResult(cs, 1));
76    }
77  
78  }