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