|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
23 | 23 | import org.junit.jupiter.api.Test;
|
24 | 24 |
|
25 | 25 | import org.springframework.dao.InvalidDataAccessApiUsageException;
|
| 26 | +import org.springframework.jdbc.core.SqlParameterValue; |
26 | 27 |
|
27 | 28 | import static org.assertj.core.api.Assertions.assertThat;
|
28 | 29 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
32 | 33 | * @author Juergen Hoeller
|
33 | 34 | * @author Rick Evans
|
34 | 35 | * @author Artur Geraschenko
|
| 36 | + * @author Yanming Zhou |
35 | 37 | */
|
36 | 38 | public class NamedParameterUtilsTests {
|
37 | 39 |
|
@@ -96,6 +98,20 @@ public void convertTypeMapToArray() {
|
96 | 98 | .buildSqlTypeArray(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams)[4]).isEqualTo(2);
|
97 | 99 | }
|
98 | 100 |
|
| 101 | + @Test |
| 102 | + public void convertSqlParameterValueToArray() { |
| 103 | + SqlParameterValue sqlParameterValue = new SqlParameterValue(2, "b"); |
| 104 | + Map<String, Object> paramMap = new HashMap<>(); |
| 105 | + paramMap.put("a", "a"); |
| 106 | + paramMap.put("b", sqlParameterValue); |
| 107 | + paramMap.put("c", "c"); |
| 108 | + assertThat(NamedParameterUtils.buildValueArray("xxx :a :b :c xx :a :b", paramMap)[4]).isSameAs(sqlParameterValue); |
| 109 | + MapSqlParameterSource namedParams = new MapSqlParameterSource(); |
| 110 | + namedParams.addValue("a", "a", 1).addValue("b", sqlParameterValue).addValue("c", "c", 3); |
| 111 | + assertThat(NamedParameterUtils |
| 112 | + .buildValueArray(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams, null)[4]).isSameAs(sqlParameterValue); |
| 113 | + } |
| 114 | + |
99 | 115 | @Test
|
100 | 116 | public void convertTypeMapToSqlParameterList() {
|
101 | 117 | MapSqlParameterSource namedParams = new MapSqlParameterSource();
|
|
0 commit comments