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