Skip to content

Commit a803206

Browse files
committed
Polishing
1 parent e57b942 commit a803206

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertIntegrationTests.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
*
3737
* @author Sam Brannen
3838
* @since 6.1
39+
* @see SimpleJdbcInsertTests
3940
*/
4041
class SimpleJdbcInsertIntegrationTests {
4142

@@ -81,7 +82,7 @@ void usingColumns() {
8182
insertJaneSmith(insert);
8283
}
8384

84-
@Test // gh-24013
85+
@Test // gh-24013
8586
void usingColumnsAndQuotedIdentifiers() throws Exception {
8687
SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase)
8788
.withTableName("users")
@@ -90,7 +91,9 @@ void usingColumnsAndQuotedIdentifiers() throws Exception {
9091

9192
insert.compile();
9293
// NOTE: quoted identifiers in H2/HSQL will be UPPERCASE!
93-
assertThat(insert.getInsertString()).isEqualTo("INSERT INTO \"USERS\" (\"FIRST_NAME\", \"LAST_NAME\") VALUES(?, ?)");
94+
assertThat(insert.getInsertString()).isEqualToIgnoringNewLines("""
95+
INSERT INTO "USERS" ("FIRST_NAME", "LAST_NAME") VALUES(?, ?)
96+
""");
9497

9598
insertJaneSmith(insert);
9699
}
@@ -123,7 +126,7 @@ void usingColumnsWithSchemaName() {
123126
insertJaneSmith(insert);
124127
}
125128

126-
@Test // gh-24013
129+
@Test // gh-24013
127130
void usingColumnsAndQuotedIdentifiersWithSchemaName() throws Exception {
128131
SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase)
129132
.withSchemaName("my_schema")
@@ -133,7 +136,9 @@ void usingColumnsAndQuotedIdentifiersWithSchemaName() throws Exception {
133136

134137
insert.compile();
135138
// NOTE: quoted identifiers in H2/HSQL will be UPPERCASE!
136-
assertThat(insert.getInsertString()).isEqualTo("INSERT INTO \"MY_SCHEMA\".\"USERS\" (\"FIRST_NAME\", \"LAST_NAME\") VALUES(?, ?)");
139+
assertThat(insert.getInsertString()).isEqualToIgnoringNewLines("""
140+
INSERT INTO "MY_SCHEMA"."USERS" ("FIRST_NAME", "LAST_NAME") VALUES(?, ?)
141+
""");
137142

138143
insertJaneSmith(insert);
139144
}

spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertTests.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
import static org.mockito.Mockito.verify;
3939

4040
/**
41-
* Mock object based tests for {@link SimpleJdbcInsert}.
41+
* Mock-based tests for {@link SimpleJdbcInsert}.
4242
*
4343
* @author Thomas Risberg
4444
* @author Sam Brannen
45+
* @see SimpleJdbcInsertIntegrationTests
4546
*/
4647
class SimpleJdbcInsertTests {
4748

@@ -64,6 +65,18 @@ void verifyClosed() throws Exception {
6465
}
6566

6667

68+
@Test
69+
void missingTableName() throws Exception {
70+
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource);
71+
72+
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
73+
.isThrownBy(insert::compile)
74+
.withMessage("Table name is required");
75+
76+
// Appease the @AfterEach checks.
77+
connection.close();
78+
}
79+
6780
/**
6881
* This method does not test any functionality but rather only that
6982
* configuration methods can be chained without compiler errors.
@@ -100,8 +113,8 @@ void noSuchTable() throws Exception {
100113
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource).withTableName("x");
101114
// Shouldn't succeed in inserting into table which doesn't exist
102115
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
103-
.isThrownBy(() -> insert.execute(Collections.emptyMap()))
104-
.withMessageStartingWith("Unable to locate columns for table 'x' so an insert statement can't be generated");
116+
.isThrownBy(() -> insert.execute(Collections.emptyMap()))
117+
.withMessageStartingWith("Unable to locate columns for table 'x' so an insert statement can't be generated");
105118

106119
verify(resultSet).close();
107120
}
@@ -152,9 +165,9 @@ void exceptionThrownWhileRetrievingColumnNamesFromMetadata() throws Exception {
152165
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource).withTableName("me");
153166

154167
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
155-
.isThrownBy(insert::compile)
156-
.withMessage("Unable to locate columns for table 'me' so an insert statement can't be generated. " +
157-
"Consider specifying explicit column names -- for example, via SimpleJdbcInsert#usingColumns().");
168+
.isThrownBy(insert::compile)
169+
.withMessage("Unable to locate columns for table 'me' so an insert statement can't be generated. " +
170+
"Consider specifying explicit column names -- for example, via SimpleJdbcInsert#usingColumns().");
158171

159172
verify(columnResultSet).close();
160173
verify(tableResultSet).close();

0 commit comments

Comments
 (0)