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.simplelistparameter;
17  
18  import java.io.Reader;
19  import java.util.Arrays;
20  import java.util.List;
21  
22  import org.apache.ibatis.BaseDataTest;
23  import org.apache.ibatis.io.Resources;
24  import org.apache.ibatis.session.SqlSession;
25  import org.apache.ibatis.session.SqlSessionFactory;
26  import org.apache.ibatis.session.SqlSessionFactoryBuilder;
27  import org.junit.jupiter.api.Assertions;
28  import org.junit.jupiter.api.BeforeAll;
29  import org.junit.jupiter.api.Test;
30  
31  class SimpleListParameterTest {
32  
33    private static SqlSessionFactory sqlSessionFactory;
34  
35    @BeforeAll
36    static void setUp() throws Exception {
37      // create a SqlSessionFactory
38      try (Reader reader = Resources
39          .getResourceAsReader("org/apache/ibatis/submitted/simplelistparameter/mybatis-config.xml")) {
40        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
41      }
42  
43      // populate in-memory database
44      BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
45          "org/apache/ibatis/submitted/simplelistparameter/CreateDB.sql");
46    }
47  
48    @Test
49    void shouldGetACar() {
50      try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
51        CarMapper carMapper = sqlSession.getMapper(CarMapper.class);
52        Car car = new Car();
53        car.setDoors(Arrays.asList("2", "4"));
54        List<Car> cars = carMapper.getCar(car);
55        Assertions.assertNotNull(cars);
56      }
57    }
58  
59    @Test
60    void shouldResolveGenericFieldGetterType() {
61      try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
62        CarMapper carMapper = sqlSession.getMapper(CarMapper.class);
63        Rv rv = new Rv();
64        rv.doors1 = Arrays.asList("2", "4");
65        List<Rv> rvs = carMapper.getRv1(rv);
66        Assertions.assertNotNull(rvs);
67      }
68    }
69  
70    @Test
71    void shouldResolveGenericMethodGetterType() {
72      try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
73        CarMapper carMapper = sqlSession.getMapper(CarMapper.class);
74        Rv rv = new Rv();
75        rv.setDoors2(Arrays.asList("2", "4"));
76        List<Rv> rvs = carMapper.getRv2(rv);
77        Assertions.assertNotNull(rvs);
78      }
79    }
80  }