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