38
38
import static org .mockito .Mockito .verify ;
39
39
40
40
/**
41
- * Mock object based tests for {@link SimpleJdbcInsert}.
41
+ * Mock- based tests for {@link SimpleJdbcInsert}.
42
42
*
43
43
* @author Thomas Risberg
44
44
* @author Sam Brannen
45
+ * @see SimpleJdbcInsertIntegrationTests
45
46
*/
46
47
class SimpleJdbcInsertTests {
47
48
@@ -64,6 +65,18 @@ void verifyClosed() throws Exception {
64
65
}
65
66
66
67
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
+
67
80
/**
68
81
* This method does not test any functionality but rather only that
69
82
* configuration methods can be chained without compiler errors.
@@ -100,8 +113,8 @@ void noSuchTable() throws Exception {
100
113
SimpleJdbcInsert insert = new SimpleJdbcInsert (dataSource ).withTableName ("x" );
101
114
// Shouldn't succeed in inserting into table which doesn't exist
102
115
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" );
105
118
106
119
verify (resultSet ).close ();
107
120
}
@@ -152,9 +165,9 @@ void exceptionThrownWhileRetrievingColumnNamesFromMetadata() throws Exception {
152
165
SimpleJdbcInsert insert = new SimpleJdbcInsert (dataSource ).withTableName ("me" );
153
166
154
167
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()." );
158
171
159
172
verify (columnResultSet ).close ();
160
173
verify (tableResultSet ).close ();
0 commit comments