@@ -192,7 +192,7 @@ private void doTestStrings(Integer fetchSize, Integer maxRows, Integer queryTime
192
192
Object argument , JdbcTemplateCallback jdbcTemplateCallback ) throws Exception {
193
193
194
194
String sql = "SELECT FORENAME FROM CUSTMR" ;
195
- String [] results = { "rod" , "gary" , " portia" };
195
+ String [] results = {"rod" , "gary" , " portia" };
196
196
197
197
class StringHandler implements RowCallbackHandler {
198
198
private List <String > list = new LinkedList <>();
@@ -491,8 +491,8 @@ public void testBatchUpdateWithNoBatchSupportAndSelect() throws Exception {
491
491
@ Test
492
492
public void testBatchUpdateWithPreparedStatement () throws Exception {
493
493
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?" ;
494
- final int [] ids = new int [] { 100 , 200 };
495
- final int [] rowsAffected = new int [] { 1 , 2 };
494
+ final int [] ids = new int [] {100 , 200 };
495
+ final int [] rowsAffected = new int [] {1 , 2 };
496
496
497
497
given (this .preparedStatement .executeBatch ()).willReturn (rowsAffected );
498
498
mockDatabaseMetaData (true );
@@ -525,8 +525,8 @@ public int getBatchSize() {
525
525
@ Test
526
526
public void testInterruptibleBatchUpdate () throws Exception {
527
527
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?" ;
528
- final int [] ids = new int [] { 100 , 200 };
529
- final int [] rowsAffected = new int [] { 1 , 2 };
528
+ final int [] ids = new int [] {100 , 200 };
529
+ final int [] rowsAffected = new int [] {1 , 2 };
530
530
531
531
given (this .preparedStatement .executeBatch ()).willReturn (rowsAffected );
532
532
mockDatabaseMetaData (true );
@@ -566,8 +566,8 @@ public boolean isBatchExhausted(int i) {
566
566
@ Test
567
567
public void testInterruptibleBatchUpdateWithBaseClass () throws Exception {
568
568
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?" ;
569
- final int [] ids = new int [] { 100 , 200 };
570
- final int [] rowsAffected = new int [] { 1 , 2 };
569
+ final int [] ids = new int [] {100 , 200 };
570
+ final int [] rowsAffected = new int [] {1 , 2 };
571
571
572
572
given (this .preparedStatement .executeBatch ()).willReturn (rowsAffected );
573
573
mockDatabaseMetaData (true );
@@ -603,8 +603,8 @@ protected boolean setValuesIfAvailable(PreparedStatement ps, int i) throws SQLEx
603
603
@ Test
604
604
public void testInterruptibleBatchUpdateWithBaseClassAndNoBatchSupport () throws Exception {
605
605
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?" ;
606
- final int [] ids = new int [] { 100 , 200 };
607
- final int [] rowsAffected = new int [] { 1 , 2 };
606
+ final int [] ids = new int [] {100 , 200 };
607
+ final int [] rowsAffected = new int [] {1 , 2 };
608
608
609
609
given (this .preparedStatement .executeUpdate ()).willReturn (rowsAffected [0 ], rowsAffected [1 ]);
610
610
mockDatabaseMetaData (false );
@@ -640,8 +640,8 @@ protected boolean setValuesIfAvailable(PreparedStatement ps, int i) throws SQLEx
640
640
@ Test
641
641
public void testBatchUpdateWithPreparedStatementAndNoBatchSupport () throws Exception {
642
642
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?" ;
643
- final int [] ids = new int [] { 100 , 200 };
644
- final int [] rowsAffected = new int [] { 1 , 2 };
643
+ final int [] ids = new int [] {100 , 200 };
644
+ final int [] rowsAffected = new int [] {1 , 2 };
645
645
646
646
given (this .preparedStatement .executeUpdate ()).willReturn (rowsAffected [0 ], rowsAffected [1 ]);
647
647
@@ -671,7 +671,7 @@ public int getBatchSize() {
671
671
@ Test
672
672
public void testBatchUpdateFails () throws Exception {
673
673
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?" ;
674
- final int [] ids = new int [] { 100 , 200 };
674
+ final int [] ids = new int [] {100 , 200 };
675
675
SQLException sqlException = new SQLException ();
676
676
677
677
given (this .preparedStatement .executeBatch ()).willThrow (sqlException );
@@ -702,6 +702,15 @@ public int getBatchSize() {
702
702
}
703
703
}
704
704
705
+ @ Test
706
+ public void testBatchUpdateWithEmptyList () throws Exception {
707
+ final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?" ;
708
+ JdbcTemplate template = new JdbcTemplate (this .dataSource , false );
709
+
710
+ int [] actualRowsAffected = template .batchUpdate (sql , Collections .emptyList ());
711
+ assertTrue ("executed 0 updates" , actualRowsAffected .length == 0 );
712
+ }
713
+
705
714
@ Test
706
715
public void testBatchUpdateWithListOfObjectArrays () throws Exception {
707
716
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?" ;
@@ -712,11 +721,9 @@ public void testBatchUpdateWithListOfObjectArrays() throws Exception {
712
721
713
722
given (this .preparedStatement .executeBatch ()).willReturn (rowsAffected );
714
723
mockDatabaseMetaData (true );
715
-
716
724
JdbcTemplate template = new JdbcTemplate (this .dataSource , false );
717
725
718
726
int [] actualRowsAffected = template .batchUpdate (sql , ids );
719
-
720
727
assertTrue ("executed 2 updates" , actualRowsAffected .length == 2 );
721
728
assertEquals (rowsAffected [0 ], actualRowsAffected [0 ]);
722
729
assertEquals (rowsAffected [1 ], actualRowsAffected [1 ]);
@@ -739,10 +746,9 @@ public void testBatchUpdateWithListOfObjectArraysPlusTypeInfo() throws Exception
739
746
740
747
given (this .preparedStatement .executeBatch ()).willReturn (rowsAffected );
741
748
mockDatabaseMetaData (true );
742
-
743
749
this .template = new JdbcTemplate (this .dataSource , false );
744
- int [] actualRowsAffected = this .template .batchUpdate (sql , ids , sqlTypes );
745
750
751
+ int [] actualRowsAffected = this .template .batchUpdate (sql , ids , sqlTypes );
746
752
assertTrue ("executed 2 updates" , actualRowsAffected .length == 2 );
747
753
assertEquals (rowsAffected [0 ], actualRowsAffected [0 ]);
748
754
assertEquals (rowsAffected [1 ], actualRowsAffected [1 ]);
@@ -757,8 +763,8 @@ public void testBatchUpdateWithListOfObjectArraysPlusTypeInfo() throws Exception
757
763
public void testBatchUpdateWithCollectionOfObjects () throws Exception {
758
764
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?" ;
759
765
final List <Integer > ids = Arrays .asList (100 , 200 , 300 );
760
- final int [] rowsAffected1 = new int [] { 1 , 2 };
761
- final int [] rowsAffected2 = new int [] { 3 };
766
+ final int [] rowsAffected1 = new int [] {1 , 2 };
767
+ final int [] rowsAffected2 = new int [] {3 };
762
768
763
769
given (this .preparedStatement .executeBatch ()).willReturn (rowsAffected1 , rowsAffected2 );
764
770
mockDatabaseMetaData (true );
@@ -781,50 +787,52 @@ public void testBatchUpdateWithCollectionOfObjects() throws Exception {
781
787
}
782
788
783
789
@ Test
784
- public void testCouldntGetConnectionForOperationOrExceptionTranslator () throws SQLException {
790
+ public void testCouldNotGetConnectionForOperationOrExceptionTranslator () throws SQLException {
785
791
SQLException sqlException = new SQLException ("foo" , "07xxx" );
786
792
this .dataSource = mock (DataSource .class );
787
793
given (this .dataSource .getConnection ()).willThrow (sqlException );
788
794
JdbcTemplate template = new JdbcTemplate (this .dataSource , false );
789
795
RowCountCallbackHandler rcch = new RowCountCallbackHandler ();
796
+
790
797
this .thrown .expect (CannotGetJdbcConnectionException .class );
791
798
this .thrown .expect (exceptionCause (sameInstance (sqlException )));
792
799
template .query ("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3" , rcch );
793
800
}
794
801
795
802
@ Test
796
- public void testCouldntGetConnectionForOperationWithLazyExceptionTranslator () throws SQLException {
803
+ public void testCouldNotGetConnectionForOperationWithLazyExceptionTranslator () throws SQLException {
797
804
SQLException sqlException = new SQLException ("foo" , "07xxx" );
798
805
this .dataSource = mock (DataSource .class );
799
806
given (this .dataSource .getConnection ()).willThrow (sqlException );
800
807
this .template = new JdbcTemplate ();
801
808
this .template .setDataSource (this .dataSource );
802
809
this .template .afterPropertiesSet ();
803
810
RowCountCallbackHandler rcch = new RowCountCallbackHandler ();
811
+
804
812
this .thrown .expect (CannotGetJdbcConnectionException .class );
805
813
this .thrown .expect (exceptionCause (sameInstance (sqlException )));
806
814
this .template .query ("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3" , rcch );
807
815
}
808
816
809
817
@ Test
810
- public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedViaBeanProperty ()
818
+ public void testCouldNotGetConnectionInOperationWithExceptionTranslatorInitializedViaBeanProperty ()
811
819
throws SQLException {
812
820
813
- doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized (true );
821
+ doTestCouldNotGetConnectionInOperationWithExceptionTranslatorInitialized (true );
814
822
}
815
823
816
824
@ Test
817
- public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedInAfterPropertiesSet ()
825
+ public void testCouldNotGetConnectionInOperationWithExceptionTranslatorInitializedInAfterPropertiesSet ()
818
826
throws SQLException {
819
827
820
- doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized (false );
828
+ doTestCouldNotGetConnectionInOperationWithExceptionTranslatorInitialized (false );
821
829
}
822
830
823
831
/**
824
832
* If beanProperty is true, initialize via exception translator bean property;
825
833
* if false, use afterPropertiesSet().
826
834
*/
827
- private void doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized (boolean beanProperty )
835
+ private void doTestCouldNotGetConnectionInOperationWithExceptionTranslatorInitialized (boolean beanProperty )
828
836
throws SQLException {
829
837
830
838
SQLException sqlException = new SQLException ("foo" , "07xxx" );
@@ -884,7 +892,7 @@ public void testPreparedStatementSetterFails() throws Exception {
884
892
}
885
893
886
894
@ Test
887
- public void testCouldntClose () throws Exception {
895
+ public void testCouldNotClose () throws Exception {
888
896
SQLException sqlException = new SQLException ("bar" );
889
897
given (this .connection .createStatement ()).willReturn (this .statement );
890
898
given (this .resultSet .next ()).willReturn (false );
0 commit comments