|
|
|
|
@ -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. |
|
|
|
|
@ -100,8 +113,8 @@ class SimpleJdbcInsertTests {
@@ -100,8 +113,8 @@ class SimpleJdbcInsertTests {
|
|
|
|
|
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource).withTableName("x"); |
|
|
|
|
// Shouldn't succeed in inserting into table which doesn't exist
|
|
|
|
|
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class) |
|
|
|
|
.isThrownBy(() -> insert.execute(Collections.emptyMap())) |
|
|
|
|
.withMessageStartingWith("Unable to locate columns for table 'x' so an insert statement can't be generated"); |
|
|
|
|
.isThrownBy(() -> insert.execute(Collections.emptyMap())) |
|
|
|
|
.withMessageStartingWith("Unable to locate columns for table 'x' so an insert statement can't be generated"); |
|
|
|
|
|
|
|
|
|
verify(resultSet).close(); |
|
|
|
|
} |
|
|
|
|
@ -152,9 +165,9 @@ class SimpleJdbcInsertTests {
@@ -152,9 +165,9 @@ class SimpleJdbcInsertTests {
|
|
|
|
|
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource).withTableName("me"); |
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class) |
|
|
|
|
.isThrownBy(insert::compile) |
|
|
|
|
.withMessage("Unable to locate columns for table 'me' so an insert statement can't be generated. " + |
|
|
|
|
"Consider specifying explicit column names -- for example, via SimpleJdbcInsert#usingColumns()."); |
|
|
|
|
.isThrownBy(insert::compile) |
|
|
|
|
.withMessage("Unable to locate columns for table 'me' so an insert statement can't be generated. " + |
|
|
|
|
"Consider specifying explicit column names -- for example, via SimpleJdbcInsert#usingColumns()."); |
|
|
|
|
|
|
|
|
|
verify(columnResultSet).close(); |
|
|
|
|
verify(tableResultSet).close(); |
|
|
|
|
|