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