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.submitted.primitive_result_type;
17  
18  import static org.junit.jupiter.api.Assertions.assertEquals;
19  import static org.junit.jupiter.api.Assertions.assertTrue;
20  
21  import java.math.BigDecimal;
22  import java.util.List;
23  
24  import org.apache.ibatis.BaseDataTest;
25  import org.junit.jupiter.api.BeforeAll;
26  import org.junit.jupiter.api.Test;
27  
28  class PrimitiveResultTypeTest {
29  
30    @BeforeAll
31    static void setup() throws Exception {
32      BaseDataTest.runScript(IbatisConfig.getSqlSessionFactory().getConfiguration().getEnvironment().getDataSource(),
33          "org/apache/ibatis/submitted/primitive_result_type/create.sql");
34    }
35  
36    @Test
37    void shouldReturnProperPrimitiveType() {
38      List<Integer> codes = ProductDAO.selectProductCodes();
39      for (Object code : codes) {
40        assertTrue(code instanceof Integer);
41      }
42      List<Long> lcodes = ProductDAO.selectProductCodesL();
43      for (Object lcode : lcodes) {
44        assertTrue(!(lcode instanceof Integer));
45      }
46      List<BigDecimal> bcodes = ProductDAO.selectProductCodesB();
47      for (Object bcode : bcodes) {
48        assertTrue(bcode instanceof BigDecimal);
49      }
50    }
51  
52    @Test
53    void noErrorThrowOut() {
54      List<Product> products = ProductDAO.selectAllProducts();
55      assertEquals(4, products.size(), "should return 4 results");
56    }
57  }