75
75
*/
76
76
public class JdbcTemplateTests {
77
77
78
- private Connection connection = mock ();
79
-
80
78
private DataSource dataSource = mock ();
81
79
80
+ private Connection connection = mock ();
81
+
82
82
private Statement statement = mock ();
83
83
84
84
private PreparedStatement preparedStatement = mock ();
85
85
86
- private ResultSet resultSet = mock ();
87
-
88
86
private CallableStatement callableStatement = mock ();
89
87
88
+ private ResultSet resultSet = mock ();
89
+
90
90
private JdbcTemplate template = new JdbcTemplate (this .dataSource );
91
91
92
92
@@ -136,9 +136,9 @@ public void testBogusUpdate() throws Exception {
136
136
given (this .preparedStatement .executeUpdate ()).willThrow (sqlException );
137
137
138
138
Dispatcher d = new Dispatcher (idParam , sql );
139
- assertThatExceptionOfType (UncategorizedSQLException .class ). isThrownBy (() ->
140
- this .template .update (d ))
141
- .withCause (sqlException );
139
+ assertThatExceptionOfType (UncategorizedSQLException .class )
140
+ . isThrownBy (() -> this .template .update (d ))
141
+ .withCause (sqlException );
142
142
verify (this .preparedStatement ).setInt (1 , idParam );
143
143
verify (this .preparedStatement ).close ();
144
144
verify (this .connection , atLeastOnce ()).close ();
@@ -371,9 +371,9 @@ public void testSqlUpdateEncountersSqlException() throws Exception {
371
371
given (this .statement .executeUpdate (sql )).willThrow (sqlException );
372
372
given (this .connection .createStatement ()).willReturn (this .statement );
373
373
374
- assertThatExceptionOfType (DataAccessException .class ). isThrownBy (() ->
375
- this .template .update (sql ))
376
- .withCause (sqlException );
374
+ assertThatExceptionOfType (DataAccessException .class )
375
+ . isThrownBy (() -> this .template .update (sql ))
376
+ .withCause (sqlException );
377
377
verify (this .statement ).close ();
378
378
verify (this .connection , atLeastOnce ()).close ();
379
379
}
@@ -672,9 +672,9 @@ public int getBatchSize() {
672
672
};
673
673
674
674
try {
675
- assertThatExceptionOfType (DataAccessException .class ). isThrownBy (() ->
676
- this .template .batchUpdate (sql , setter ))
677
- .withCause (sqlException );
675
+ assertThatExceptionOfType (DataAccessException .class )
676
+ . isThrownBy (() -> this .template .batchUpdate (sql , setter ))
677
+ .withCause (sqlException );
678
678
}
679
679
finally {
680
680
verify (this .preparedStatement , times (2 )).addBatch ();
@@ -776,9 +776,9 @@ public void testCouldNotGetConnectionForOperationOrExceptionTranslator() throws
776
776
JdbcTemplate template = new JdbcTemplate (this .dataSource , false );
777
777
RowCountCallbackHandler rcch = new RowCountCallbackHandler ();
778
778
779
- assertThatExceptionOfType (CannotGetJdbcConnectionException .class ). isThrownBy (() ->
780
- template .query ("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3" , rcch ))
781
- .withCause (sqlException );
779
+ assertThatExceptionOfType (CannotGetJdbcConnectionException .class )
780
+ . isThrownBy (() -> template .query ("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3" , rcch ))
781
+ .withCause (sqlException );
782
782
}
783
783
784
784
@ Test
@@ -790,9 +790,9 @@ public void testCouldNotGetConnectionForOperationWithLazyExceptionTranslator() t
790
790
this .template .afterPropertiesSet ();
791
791
RowCountCallbackHandler rcch = new RowCountCallbackHandler ();
792
792
793
- assertThatExceptionOfType (CannotGetJdbcConnectionException .class ). isThrownBy (() ->
794
- this .template .query ("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3" , rcch ))
795
- .withCause (sqlException );
793
+ assertThatExceptionOfType (CannotGetJdbcConnectionException .class )
794
+ . isThrownBy (() -> this .template .query ("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3" , rcch ))
795
+ .withCause (sqlException );
796
796
}
797
797
798
798
@ Test
@@ -830,9 +830,9 @@ private void doTestCouldNotGetConnectionInOperationWithExceptionTranslatorInitia
830
830
this .template .afterPropertiesSet ();
831
831
}
832
832
RowCountCallbackHandler rcch = new RowCountCallbackHandler ();
833
- assertThatExceptionOfType (CannotGetJdbcConnectionException .class ). isThrownBy (() ->
834
- this .template .query ("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3" , rcch ))
835
- .withCause (sqlException );
833
+ assertThatExceptionOfType (CannotGetJdbcConnectionException .class )
834
+ . isThrownBy (() -> this .template .query ("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3" , rcch ))
835
+ .withCause (sqlException );
836
836
}
837
837
838
838
@ Test
@@ -859,9 +859,9 @@ public void testPreparedStatementSetterFails() throws Exception {
859
859
given (this .preparedStatement .executeUpdate ()).willThrow (sqlException );
860
860
861
861
PreparedStatementSetter pss = ps -> ps .setString (1 , name );
862
- assertThatExceptionOfType (DataAccessException .class ). isThrownBy (() ->
863
- new JdbcTemplate (this .dataSource ).update (sql , pss ))
864
- .withCause (sqlException );
862
+ assertThatExceptionOfType (DataAccessException .class )
863
+ . isThrownBy (() -> new JdbcTemplate (this .dataSource ).update (sql , pss ))
864
+ .withCause (sqlException );
865
865
verify (this .preparedStatement ).setString (1 , name );
866
866
verify (this .preparedStatement ).close ();
867
867
verify (this .connection , atLeastOnce ()).close ();
@@ -897,9 +897,9 @@ public void testFatalWarning() throws Exception {
897
897
t .setIgnoreWarnings (false );
898
898
899
899
ResultSetExtractor <Byte > extractor = rs -> rs .getByte (1 );
900
- assertThatExceptionOfType (SQLWarningException .class ). isThrownBy (() ->
901
- t .query (sql , extractor ))
902
- .withCause (warnings );
900
+ assertThatExceptionOfType (SQLWarningException .class )
901
+ . isThrownBy (() -> t .query (sql , extractor ))
902
+ .withCause (warnings );
903
903
verify (this .resultSet ).close ();
904
904
verify (this .preparedStatement ).close ();
905
905
verify (this .connection ).close ();
@@ -940,7 +940,7 @@ public void testSQLErrorCodeTranslation() throws Exception {
940
940
this .template .query (sql , (RowCallbackHandler ) rs -> {
941
941
throw sqlException ;
942
942
}))
943
- .withCause (sqlException );
943
+ .withCause (sqlException );
944
944
verify (this .resultSet ).close ();
945
945
verify (this .preparedStatement ).close ();
946
946
verify (this .connection , atLeastOnce ()).close ();
@@ -960,7 +960,7 @@ public void testSQLErrorCodeTranslationWithSpecifiedDatabaseName() throws Except
960
960
this .template .query (sql , (RowCallbackHandler ) rs -> {
961
961
throw sqlException ;
962
962
}))
963
- .withCause (sqlException );
963
+ .withCause (sqlException );
964
964
verify (this .resultSet ).close ();
965
965
verify (this .preparedStatement ).close ();
966
966
verify (this .connection ).close ();
@@ -990,7 +990,7 @@ public void testUseCustomExceptionTranslator() throws Exception {
990
990
template .query (sql , (RowCallbackHandler ) rs -> {
991
991
throw sqlException ;
992
992
}))
993
- .withCause (sqlException );
993
+ .withCause (sqlException );
994
994
verify (this .resultSet ).close ();
995
995
verify (this .preparedStatement ).close ();
996
996
verify (this .connection ).close ();
0 commit comments