Improve test coverage of RdbmsOperation

See gh-28472
This commit is contained in:
Jiayi Li 2022-05-17 19:49:28 -07:00 committed by Stephane Nicoll
parent 1bdb67cda9
commit 608be54a58
1 changed files with 18 additions and 0 deletions

View File

@ -31,6 +31,7 @@ import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import static java.util.Map.entry;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@ -50,6 +51,14 @@ public class RdbmsOperationTests {
operation::compile);
}
@Test
public void getSql() {
String sql = "select * from mytable";
operation.setDataSource(new DriverManagerDataSource());
operation.setSql(sql);
String strGotten = operation.getSql();
assertThat(strGotten.equals(sql));
}
@Test
public void setTypeAfterCompile() {
operation.setDataSource(new DriverManagerDataSource());
@ -98,6 +107,15 @@ public class RdbmsOperationTests {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
operation.validateParameters(new Object[] { 1, 2 }));
}
@Test
public void tooManyMapParameters() {
operation.setSql("select * from mytable");
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
operation.validateNamedParameters(Map.ofEntries(
entry("a", "b"),
entry("c", "d")
) ));
}
@Test
public void unspecifiedMapParameters() {