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