|
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.
|
@@ -431,24 +431,27 @@ public void testBatchUpdateWithSqlParameterSource() throws Exception {
|
431 | 431 |
|
432 | 432 | @Test
|
433 | 433 | public void testBatchUpdateWithSqlParameterSourcePlusTypeInfo() throws Exception {
|
434 |
| - SqlParameterSource[] ids = new SqlParameterSource[2]; |
435 |
| - ids[0] = new MapSqlParameterSource().addValue("id", 100, Types.NUMERIC); |
436 |
| - ids[1] = new MapSqlParameterSource().addValue("id", 200, Types.NUMERIC); |
437 |
| - final int[] rowsAffected = new int[] {1, 2}; |
| 434 | + SqlParameterSource[] ids = new SqlParameterSource[3]; |
| 435 | + ids[0] = new MapSqlParameterSource().addValue("id", null, Types.NULL); |
| 436 | + ids[1] = new MapSqlParameterSource().addValue("id", 100, Types.NUMERIC); |
| 437 | + ids[2] = new MapSqlParameterSource().addValue("id", 200, Types.NUMERIC); |
| 438 | + final int[] rowsAffected = new int[] {1, 2, 3}; |
438 | 439 |
|
439 | 440 | given(preparedStatement.executeBatch()).willReturn(rowsAffected);
|
440 | 441 | given(connection.getMetaData()).willReturn(databaseMetaData);
|
441 | 442 | namedParameterTemplate = new NamedParameterJdbcTemplate(new JdbcTemplate(dataSource, false));
|
442 | 443 |
|
443 | 444 | int[] actualRowsAffected = namedParameterTemplate.batchUpdate(
|
444 | 445 | "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = :id", ids);
|
445 |
| - assertTrue("executed 2 updates", actualRowsAffected.length == 2); |
| 446 | + assertTrue("executed 3 updates", actualRowsAffected.length == 3); |
446 | 447 | assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
447 | 448 | assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
| 449 | + assertEquals(rowsAffected[2], actualRowsAffected[2]); |
448 | 450 | verify(connection).prepareStatement("UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?");
|
| 451 | + verify(preparedStatement).setNull(1, Types.NULL); |
449 | 452 | verify(preparedStatement).setObject(1, 100, Types.NUMERIC);
|
450 | 453 | verify(preparedStatement).setObject(1, 200, Types.NUMERIC);
|
451 |
| - verify(preparedStatement, times(2)).addBatch(); |
| 454 | + verify(preparedStatement, times(3)).addBatch(); |
452 | 455 | verify(preparedStatement, atLeastOnce()).close();
|
453 | 456 | verify(connection, atLeastOnce()).close();
|
454 | 457 | }
|
|
0 commit comments