Browse Source

Polishing

pull/31518/head
Sam Brannen 2 years ago
parent
commit
a803206d5f
  1. 9
      spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertIntegrationTests.java
  2. 15
      spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertTests.java

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

@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; @@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Sam Brannen
* @since 6.1
* @see SimpleJdbcInsertTests
*/
class SimpleJdbcInsertIntegrationTests {
@ -90,7 +91,9 @@ class SimpleJdbcInsertIntegrationTests { @@ -90,7 +91,9 @@ class SimpleJdbcInsertIntegrationTests {
insert.compile();
// NOTE: quoted identifiers in H2/HSQL will be UPPERCASE!
assertThat(insert.getInsertString()).isEqualTo("INSERT INTO \"USERS\" (\"FIRST_NAME\", \"LAST_NAME\") VALUES(?, ?)");
assertThat(insert.getInsertString()).isEqualToIgnoringNewLines("""
INSERT INTO "USERS" ("FIRST_NAME", "LAST_NAME") VALUES(?, ?)
""");
insertJaneSmith(insert);
}
@ -133,7 +136,9 @@ class SimpleJdbcInsertIntegrationTests { @@ -133,7 +136,9 @@ class SimpleJdbcInsertIntegrationTests {
insert.compile();
// NOTE: quoted identifiers in H2/HSQL will be UPPERCASE!
assertThat(insert.getInsertString()).isEqualTo("INSERT INTO \"MY_SCHEMA\".\"USERS\" (\"FIRST_NAME\", \"LAST_NAME\") VALUES(?, ?)");
assertThat(insert.getInsertString()).isEqualToIgnoringNewLines("""
INSERT INTO "MY_SCHEMA"."USERS" ("FIRST_NAME", "LAST_NAME") VALUES(?, ?)
""");
insertJaneSmith(insert);
}

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

@ -38,10 +38,11 @@ import static org.mockito.Mockito.mock; @@ -38,10 +38,11 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Mock object based tests for {@link SimpleJdbcInsert}.
* Mock-based tests for {@link SimpleJdbcInsert}.
*
* @author Thomas Risberg
* @author Sam Brannen
* @see SimpleJdbcInsertIntegrationTests
*/
class SimpleJdbcInsertTests {
@ -64,6 +65,18 @@ class SimpleJdbcInsertTests { @@ -64,6 +65,18 @@ class SimpleJdbcInsertTests {
}
@Test
void missingTableName() throws Exception {
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource);
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(insert::compile)
.withMessage("Table name is required");
// Appease the @AfterEach checks.
connection.close();
}
/**
* This method does not test any functionality but rather only that
* configuration methods can be chained without compiler errors.

Loading…
Cancel
Save