|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -470,24 +470,27 @@ public void testBatchUpdateWithSqlParameterSource() throws Exception {
|
470 | 470 |
|
471 | 471 | @Test
|
472 | 472 | public void testBatchUpdateWithSqlParameterSourcePlusTypeInfo() throws Exception {
|
473 |
| - SqlParameterSource[] ids = new SqlParameterSource[2]; |
474 |
| - ids[0] = new MapSqlParameterSource().addValue("id", 100, Types.NUMERIC); |
475 |
| - ids[1] = new MapSqlParameterSource().addValue("id", 200, Types.NUMERIC); |
476 |
| - final int[] rowsAffected = new int[] {1, 2}; |
| 473 | + SqlParameterSource[] ids = new SqlParameterSource[3]; |
| 474 | + ids[0] = new MapSqlParameterSource().addValue("id", null, Types.NULL); |
| 475 | + ids[1] = new MapSqlParameterSource().addValue("id", 100, Types.NUMERIC); |
| 476 | + ids[2] = new MapSqlParameterSource().addValue("id", 200, Types.NUMERIC); |
| 477 | + final int[] rowsAffected = new int[] {1, 2, 3}; |
477 | 478 |
|
478 | 479 | given(preparedStatement.executeBatch()).willReturn(rowsAffected);
|
479 | 480 | given(connection.getMetaData()).willReturn(databaseMetaData);
|
480 | 481 | namedParameterTemplate = new NamedParameterJdbcTemplate(new JdbcTemplate(dataSource, false));
|
481 | 482 |
|
482 | 483 | int[] actualRowsAffected = namedParameterTemplate.batchUpdate(
|
483 | 484 | "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = :id", ids);
|
484 |
| - assertTrue("executed 2 updates", actualRowsAffected.length == 2); |
| 485 | + assertTrue("executed 3 updates", actualRowsAffected.length == 3); |
485 | 486 | assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
486 | 487 | assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
| 488 | + assertEquals(rowsAffected[2], actualRowsAffected[2]); |
487 | 489 | verify(connection).prepareStatement("UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?");
|
| 490 | + verify(preparedStatement).setNull(1, Types.NULL); |
488 | 491 | verify(preparedStatement).setObject(1, 100, Types.NUMERIC);
|
489 | 492 | verify(preparedStatement).setObject(1, 200, Types.NUMERIC);
|
490 |
| - verify(preparedStatement, times(2)).addBatch(); |
| 493 | + verify(preparedStatement, times(3)).addBatch(); |
491 | 494 | verify(preparedStatement, atLeastOnce()).close();
|
492 | 495 | verify(connection, atLeastOnce()).close();
|
493 | 496 | }
|
|
0 commit comments