1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.mapping;
17
18 import static org.junit.jupiter.api.Assertions.assertFalse;
19 import static org.junit.jupiter.api.Assertions.assertTrue;
20
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.ibatis.session.Configuration;
27 import org.junit.jupiter.api.Test;
28
29 class BoundSqlTest {
30
31 @Test
32 void testHasAdditionalParameter() {
33 List<ParameterMapping> params = Collections.emptyList();
34 BoundSql boundSql = new BoundSql(new Configuration(), "some sql", params, new Object());
35
36 Map<String, String> map = new HashMap<>();
37 map.put("key1", "value1");
38 boundSql.setAdditionalParameter("map", map);
39
40 Person bean = new Person();
41 bean.id = 1;
42 boundSql.setAdditionalParameter("person", bean);
43
44 String[] array = { "User1", "User2" };
45 boundSql.setAdditionalParameter("array", array);
46
47 assertFalse(boundSql.hasAdditionalParameter("pet"));
48 assertFalse(boundSql.hasAdditionalParameter("pet.name"));
49
50 assertTrue(boundSql.hasAdditionalParameter("map"));
51 assertTrue(boundSql.hasAdditionalParameter("map.key1"));
52 assertTrue(boundSql.hasAdditionalParameter("map.key2"),
53 "should return true even if the child property does not exists.");
54
55 assertTrue(boundSql.hasAdditionalParameter("person"));
56 assertTrue(boundSql.hasAdditionalParameter("person.id"));
57 assertTrue(boundSql.hasAdditionalParameter("person.name"),
58 "should return true even if the child property does not exists.");
59
60 assertTrue(boundSql.hasAdditionalParameter("array[0]"));
61 assertTrue(boundSql.hasAdditionalParameter("array[99]"), "should return true even if the element does not exists.");
62 }
63
64 public static class Person {
65 public Integer id;
66 }
67
68 }