1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.collectionparameters;
17
18 import java.io.Reader;
19 import java.util.ArrayList;
20 import java.util.HashSet;
21 import java.util.List;
22 import java.util.Set;
23
24 import org.apache.ibatis.BaseDataTest;
25 import org.apache.ibatis.io.Resources;
26 import org.apache.ibatis.session.SqlSession;
27 import org.apache.ibatis.session.SqlSessionFactory;
28 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
29 import org.junit.jupiter.api.Assertions;
30 import org.junit.jupiter.api.BeforeAll;
31 import org.junit.jupiter.api.Test;
32
33 class CollectionParametersTest {
34
35 private static SqlSessionFactory sqlSessionFactory;
36
37 @BeforeAll
38 static void setUp() throws Exception {
39
40 try (Reader reader = Resources
41 .getResourceAsReader("org/apache/ibatis/submitted/collectionparameters/mybatis-config.xml")) {
42 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
43 }
44
45
46 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
47 "org/apache/ibatis/submitted/collectionparameters/CreateDB.sql");
48 }
49
50 @Test
51 void shouldGetTwoUsersPassingAList() {
52 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
53 Mapper mapper = sqlSession.getMapper(Mapper.class);
54 ArrayList<Integer> list = new ArrayList<>();
55 list.add(1);
56 list.add(2);
57 List<User> users = mapper.getUsersFromList(list);
58 Assertions.assertEquals(2, users.size());
59 }
60 }
61
62 @Test
63 void shouldGetTwoUsersPassingAnArray() {
64 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
65 Mapper mapper = sqlSession.getMapper(Mapper.class);
66 Integer[] list = new Integer[2];
67 list[0] = 1;
68 list[1] = 2;
69 List<User> users = mapper.getUsersFromArray(list);
70 Assertions.assertEquals(2, users.size());
71 }
72 }
73
74 @Test
75 void shouldGetTwoUsersPassingACollection() {
76 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
77 Mapper mapper = sqlSession.getMapper(Mapper.class);
78 Set<Integer> list = new HashSet<>();
79 list.add(1);
80 list.add(2);
81 List<User> users = mapper.getUsersFromCollection(list);
82 Assertions.assertEquals(2, users.size());
83 }
84 }
85
86 }