View Javadoc
1   /*
2    *    Copyright 2009-2022 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.mockito.Mockito.never;
20  import static org.mockito.Mockito.verify;
21  import static org.mockito.Mockito.when;
22  
23  import java.util.Date;
24  
25  import org.junit.jupiter.api.Test;
26  
27  class SqlTimeTypeHandlerTest extends BaseTypeHandlerTest {
28  
29    private static final TypeHandler<java.sql.Time> TYPE_HANDLER = new SqlTimeTypeHandler();
30    private static final java.sql.Time SQL_TIME = new java.sql.Time(new Date().getTime());
31  
32    @Override
33    @Test
34    public void shouldSetParameter() throws Exception {
35      TYPE_HANDLER.setParameter(ps, 1, SQL_TIME, null);
36      verify(ps).setTime(1, SQL_TIME);
37    }
38  
39    @Override
40    @Test
41    public void shouldGetResultFromResultSetByName() throws Exception {
42      when(rs.getTime("column")).thenReturn(SQL_TIME);
43      assertEquals(SQL_TIME, TYPE_HANDLER.getResult(rs, "column"));
44      verify(rs, never()).wasNull();
45    }
46  
47    @Override
48    public void shouldGetResultNullFromResultSetByName() throws Exception {
49      // Unnecessary
50    }
51  
52    @Override
53    @Test
54    public void shouldGetResultFromResultSetByPosition() throws Exception {
55      when(rs.getTime(1)).thenReturn(SQL_TIME);
56      assertEquals(SQL_TIME, TYPE_HANDLER.getResult(rs, 1));
57      verify(rs, never()).wasNull();
58    }
59  
60    @Override
61    public void shouldGetResultNullFromResultSetByPosition() throws Exception {
62      // Unnecessary
63    }
64  
65    @Override
66    @Test
67    public void shouldGetResultFromCallableStatement() throws Exception {
68      when(cs.getTime(1)).thenReturn(SQL_TIME);
69      assertEquals(SQL_TIME, TYPE_HANDLER.getResult(cs, 1));
70      verify(cs, never()).wasNull();
71    }
72  
73    @Override
74    public void shouldGetResultNullFromCallableStatement() throws Exception {
75      // Unnecessary
76    }
77  
78  }