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