Skip to content

Commit f9ee8a9

Browse files
committed
Polish "Improve test coverage of RdbmsOperation"
See gh-28472
1 parent 608be54 commit f9ee8a9

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

spring-jdbc/src/test/java/org/springframework/jdbc/object/RdbmsOperationTests.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@
3131
import org.springframework.jdbc.core.SqlParameter;
3232
import org.springframework.jdbc.datasource.DriverManagerDataSource;
3333

34-
import static java.util.Map.entry;
3534
import static org.assertj.core.api.Assertions.assertThat;
3635
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3736

@@ -51,14 +50,6 @@ public void emptySql() {
5150
operation::compile);
5251
}
5352

54-
@Test
55-
public void getSql() {
56-
String sql = "select * from mytable";
57-
operation.setDataSource(new DriverManagerDataSource());
58-
operation.setSql(sql);
59-
String strGotten = operation.getSql();
60-
assertThat(strGotten.equals(sql));
61-
}
6253
@Test
6354
public void setTypeAfterCompile() {
6455
operation.setDataSource(new DriverManagerDataSource());
@@ -87,38 +78,39 @@ public void tooFewParameters() {
8778

8879
@Test
8980
public void tooFewMapParameters() {
81+
operation.setDataSource(new DriverManagerDataSource());
9082
operation.setSql("select * from mytable");
9183
operation.setTypes(new int[] { Types.INTEGER });
9284
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
9385
operation.validateNamedParameters((Map<String, String>) null));
9486
}
9587

9688
@Test
97-
public void operationConfiguredViaJdbcTemplateMustGetDataSource() throws Exception {
89+
public void operationConfiguredViaJdbcTemplateMustGetDataSource() {
9890
operation.setSql("foo");
9991
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
10092
operation.compile())
101-
.withMessageContaining("ataSource");
93+
.withMessageContaining("'dataSource'");
10294
}
10395

10496
@Test
10597
public void tooManyParameters() {
98+
operation.setDataSource(new DriverManagerDataSource());
10699
operation.setSql("select * from mytable");
107100
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
108101
operation.validateParameters(new Object[] { 1, 2 }));
109102
}
110103
@Test
111104
public void tooManyMapParameters() {
105+
operation.setDataSource(new DriverManagerDataSource());
112106
operation.setSql("select * from mytable");
113107
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
114-
operation.validateNamedParameters(Map.ofEntries(
115-
entry("a", "b"),
116-
entry("c", "d")
117-
) ));
108+
operation.validateNamedParameters(Map.of("a", "b", "c", "d")));
118109
}
119110

120111
@Test
121112
public void unspecifiedMapParameters() {
113+
operation.setDataSource(new DriverManagerDataSource());
122114
operation.setSql("select * from mytable");
123115
Map<String, String> params = new HashMap<>();
124116
params.put("col1", "value");

0 commit comments

Comments
 (0)