diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/config/InitializeDatabaseIntegrationTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/config/InitializeDatabaseIntegrationTests.java index 7fef1c846f8a..42936a7bd10e 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/config/InitializeDatabaseIntegrationTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/config/InitializeDatabaseIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ /** * @author Dave Syer */ -public class InitializeDatabaseIntegrationTests { +class InitializeDatabaseIntegrationTests { private String enabled; @@ -44,12 +44,12 @@ public class InitializeDatabaseIntegrationTests { @BeforeEach - public void init() { + void init() { enabled = System.setProperty("ENABLED", "true"); } @AfterEach - public void after() { + void after() { if (enabled != null) { System.setProperty("ENABLED", enabled); } @@ -63,13 +63,13 @@ public void after() { @Test - public void testCreateEmbeddedDatabase() throws Exception { + void testCreateEmbeddedDatabase() { context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-config.xml"); assertCorrectSetup(context.getBean("dataSource", DataSource.class)); } @Test - public void testDisableCreateEmbeddedDatabase() throws Exception { + void testDisableCreateEmbeddedDatabase() { System.setProperty("ENABLED", "false"); context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-config.xml"); assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(() -> @@ -77,13 +77,13 @@ public void testDisableCreateEmbeddedDatabase() throws Exception { } @Test - public void testIgnoreFailedDrops() throws Exception { + void testIgnoreFailedDrops() { context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-fail-config.xml"); assertCorrectSetup(context.getBean("dataSource", DataSource.class)); } @Test - public void testScriptNameWithPattern() throws Exception { + void testScriptNameWithPattern() { context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-pattern-config.xml"); DataSource dataSource = context.getBean("dataSource", DataSource.class); assertCorrectSetup(dataSource); @@ -92,21 +92,21 @@ public void testScriptNameWithPattern() throws Exception { } @Test - public void testScriptNameWithPlaceholder() throws Exception { + void testScriptNameWithPlaceholder() { context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-placeholder-config.xml"); DataSource dataSource = context.getBean("dataSource", DataSource.class); assertCorrectSetup(dataSource); } @Test - public void testScriptNameWithExpressions() throws Exception { + void testScriptNameWithExpressions() { context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-expression-config.xml"); DataSource dataSource = context.getBean("dataSource", DataSource.class); assertCorrectSetup(dataSource); } @Test - public void testCacheInitialization() throws Exception { + void testCacheInitialization() { context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-cache-config.xml"); assertCorrectSetup(context.getBean("dataSource", DataSource.class)); CacheData cache = context.getBean(CacheData.class); @@ -134,7 +134,7 @@ public List> getCachedData() { } @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { cache = jdbcTemplate.queryForList("SELECT * FROM T_TEST"); } } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java index c44760fd98ec..c85a1f3cff01 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,40 +52,40 @@ class JdbcNamespaceIntegrationTests { @Test @EnabledForTestGroups(LONG_RUNNING) - void createEmbeddedDatabase() throws Exception { + void createEmbeddedDatabase() { assertCorrectSetup("jdbc-config.xml", "dataSource", "h2DataSource", "derbyDataSource"); } @Test @EnabledForTestGroups(LONG_RUNNING) - void createEmbeddedDatabaseAgain() throws Exception { + void createEmbeddedDatabaseAgain() { // If Derby isn't cleaned up properly this will fail... assertCorrectSetup("jdbc-config.xml", "derbyDataSource"); } @Test - void createWithResourcePattern() throws Exception { + void createWithResourcePattern() { assertCorrectSetup("jdbc-config-pattern.xml", "dataSource"); } @Test - void createWithAnonymousDataSourceAndDefaultDatabaseName() throws Exception { + void createWithAnonymousDataSourceAndDefaultDatabaseName() { assertCorrectSetupForSingleDataSource("jdbc-config-db-name-default-and-anonymous-datasource.xml", url -> url.endsWith(DEFAULT_DATABASE_NAME)); } @Test - void createWithImplicitDatabaseName() throws Exception { + void createWithImplicitDatabaseName() { assertCorrectSetupForSingleDataSource("jdbc-config-db-name-implicit.xml", url -> url.endsWith("dataSource")); } @Test - void createWithExplicitDatabaseName() throws Exception { + void createWithExplicitDatabaseName() { assertCorrectSetupForSingleDataSource("jdbc-config-db-name-explicit.xml", url -> url.endsWith("customDbName")); } @Test - void createWithGeneratedDatabaseName() throws Exception { + void createWithGeneratedDatabaseName() { Predicate urlPredicate = url -> url.startsWith("jdbc:hsqldb:mem:"); urlPredicate.and(url -> !url.endsWith("dataSource")); urlPredicate.and(url -> !url.endsWith("shouldBeOverriddenByGeneratedName")); @@ -93,17 +93,17 @@ void createWithGeneratedDatabaseName() throws Exception { } @Test - void createWithEndings() throws Exception { + void createWithEndings() { assertCorrectSetupAndCloseContext("jdbc-initialize-endings-config.xml", 2, "dataSource"); } @Test - void createWithEndingsNested() throws Exception { + void createWithEndingsNested() { assertCorrectSetupAndCloseContext("jdbc-initialize-endings-nested-config.xml", 2, "dataSource"); } @Test - void createAndDestroy() throws Exception { + void createAndDestroy() { try (ClassPathXmlApplicationContext context = context("jdbc-destroy-config.xml")) { DataSource dataSource = context.getBean(DataSource.class); JdbcTemplate template = new JdbcTemplate(dataSource); @@ -116,7 +116,7 @@ void createAndDestroy() throws Exception { } @Test - void createAndDestroyNestedWithHsql() throws Exception { + void createAndDestroyNestedWithHsql() { try (ClassPathXmlApplicationContext context = context("jdbc-destroy-nested-config.xml")) { DataSource dataSource = context.getBean(DataSource.class); JdbcTemplate template = new JdbcTemplate(dataSource); @@ -129,7 +129,7 @@ void createAndDestroyNestedWithHsql() throws Exception { } @Test - void createAndDestroyNestedWithH2() throws Exception { + void createAndDestroyNestedWithH2() { try (ClassPathXmlApplicationContext context = context("jdbc-destroy-nested-config-h2.xml")) { DataSource dataSource = context.getBean(DataSource.class); JdbcTemplate template = new JdbcTemplate(dataSource); @@ -142,7 +142,7 @@ void createAndDestroyNestedWithH2() throws Exception { } @Test - void multipleDataSourcesHaveDifferentDatabaseNames() throws Exception { + void multipleDataSourcesHaveDifferentDatabaseNames() { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(factory).loadBeanDefinitions(new ClassPathResource( "jdbc-config-multiple-datasources.xml", getClass())); @@ -151,12 +151,12 @@ void multipleDataSourcesHaveDifferentDatabaseNames() throws Exception { } @Test - void initializeWithCustomSeparator() throws Exception { + void initializeWithCustomSeparator() { assertCorrectSetupAndCloseContext("jdbc-initialize-custom-separator.xml", 2, "dataSource"); } @Test - void embeddedWithCustomSeparator() throws Exception { + void embeddedWithCustomSeparator() { assertCorrectSetupAndCloseContext("jdbc-config-custom-separator.xml", 2, "dataSource"); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java index a157f166fa39..80bba2a0870e 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ * @author Rob Winch * @since 19.12.2004 */ -public class JdbcTemplateQueryTests { +class JdbcTemplateQueryTests { private DataSource dataSource = mock(); @@ -66,7 +66,7 @@ public class JdbcTemplateQueryTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { given(this.dataSource.getConnection()).willReturn(this.connection); given(this.connection.createStatement()).willReturn(this.statement); given(this.connection.prepareStatement(anyString())).willReturn(this.preparedStatement); @@ -81,7 +81,7 @@ public void setup() throws Exception { @Test - public void testQueryForList() throws Exception { + void testQueryForList() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID < 3"; given(this.resultSet.next()).willReturn(true, true, false); given(this.resultSet.getObject(1)).willReturn(11, 12); @@ -95,7 +95,7 @@ public void testQueryForList() throws Exception { } @Test - public void testQueryForListWithEmptyResult() throws Exception { + void testQueryForListWithEmptyResult() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID < 3"; given(this.resultSet.next()).willReturn(false); List> li = this.template.queryForList(sql); @@ -106,7 +106,7 @@ public void testQueryForListWithEmptyResult() throws Exception { } @Test - public void testQueryForListWithSingleRowAndColumn() throws Exception { + void testQueryForListWithSingleRowAndColumn() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID < 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getObject(1)).willReturn(11); @@ -119,20 +119,19 @@ public void testQueryForListWithSingleRowAndColumn() throws Exception { } @Test - public void testQueryForListWithIntegerElement() throws Exception { + void testQueryForListWithIntegerElement() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID < 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(11); List li = this.template.queryForList(sql, Integer.class); - assertThat(li).as("All rows returned").hasSize(1); - assertThat(li).element(0).as("Element is Integer").isEqualTo(11); + assertThat(li).containsExactly(11); verify(this.resultSet).close(); verify(this.statement).close(); verify(this.connection).close(); } @Test - public void testQueryForMapWithSingleRowAndColumn() throws Exception { + void testQueryForMapWithSingleRowAndColumn() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID < 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getObject(1)).willReturn(11); @@ -144,7 +143,7 @@ public void testQueryForMapWithSingleRowAndColumn() throws Exception { } @Test - public void testQueryForObjectThrowsIncorrectResultSizeForMoreThanOneRow() throws Exception { + void testQueryForObjectThrowsIncorrectResultSizeForMoreThanOneRow() throws Exception { String sql = "select pass from t_account where first_name='Alef'"; given(this.resultSet.next()).willReturn(true, true, false); given(this.resultSet.getString(1)).willReturn("pass"); @@ -156,11 +155,11 @@ public void testQueryForObjectThrowsIncorrectResultSizeForMoreThanOneRow() throw } @Test - public void testQueryForObjectWithRowMapper() throws Exception { + void testQueryForObjectWithRowMapper() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(22); - Object o = this.template.queryForObject(sql, (RowMapper) (rs, rowNum) -> rs.getInt(1)); + Object o = this.template.queryForObject(sql, (rs, rowNum) -> rs.getInt(1)); assertThat(o).as("Correct result type").isInstanceOf(Integer.class); verify(this.resultSet).close(); verify(this.statement).close(); @@ -168,7 +167,7 @@ public void testQueryForObjectWithRowMapper() throws Exception { } @Test - public void testQueryForStreamWithRowMapper() throws Exception { + void testQueryForStreamWithRowMapper() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(22); @@ -186,7 +185,7 @@ public void testQueryForStreamWithRowMapper() throws Exception { } @Test - public void testQueryForObjectWithString() throws Exception { + void testQueryForObjectWithString() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getString(1)).willReturn("myvalue"); @@ -197,7 +196,7 @@ public void testQueryForObjectWithString() throws Exception { } @Test - public void testQueryForObjectWithBigInteger() throws Exception { + void testQueryForObjectWithBigInteger() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getObject(1, BigInteger.class)).willReturn(new BigInteger("22")); @@ -208,7 +207,7 @@ public void testQueryForObjectWithBigInteger() throws Exception { } @Test - public void testQueryForObjectWithBigDecimal() throws Exception { + void testQueryForObjectWithBigDecimal() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getBigDecimal(1)).willReturn(new BigDecimal("22.5")); @@ -219,7 +218,7 @@ public void testQueryForObjectWithBigDecimal() throws Exception { } @Test - public void testQueryForObjectWithInteger() throws Exception { + void testQueryForObjectWithInteger() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(22); @@ -230,7 +229,7 @@ public void testQueryForObjectWithInteger() throws Exception { } @Test - public void testQueryForObjectWithIntegerAndNull() throws Exception { + void testQueryForObjectWithIntegerAndNull() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(0); @@ -242,7 +241,7 @@ public void testQueryForObjectWithIntegerAndNull() throws Exception { } @Test - public void testQueryForInt() throws Exception { + void testQueryForInt() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(22); @@ -254,7 +253,7 @@ public void testQueryForInt() throws Exception { } @Test - public void testQueryForIntPrimitive() throws Exception { + void testQueryForIntPrimitive() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(22); @@ -266,7 +265,7 @@ public void testQueryForIntPrimitive() throws Exception { } @Test - public void testQueryForLong() throws Exception { + void testQueryForLong() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getLong(1)).willReturn(87L); @@ -278,7 +277,7 @@ public void testQueryForLong() throws Exception { } @Test - public void testQueryForLongPrimitive() throws Exception { + void testQueryForLongPrimitive() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getLong(1)).willReturn(87L); @@ -290,12 +289,12 @@ public void testQueryForLongPrimitive() throws Exception { } @Test - public void testQueryForListWithArgs() throws Exception { + void testQueryForListWithArgs() throws Exception { doTestQueryForListWithArgs("SELECT AGE FROM CUSTMR WHERE ID < ?"); } @Test - public void testQueryForListIsNotConfusedByNamedParameterPrefix() throws Exception { + void testQueryForListIsNotConfusedByNamedParameterPrefix() throws Exception { doTestQueryForListWithArgs("SELECT AGE FROM PREFIX:CUSTMR WHERE ID < ?"); } @@ -313,7 +312,7 @@ private void doTestQueryForListWithArgs(String sql) throws Exception { } @Test - public void testQueryForListWithArgsAndEmptyResult() throws Exception { + void testQueryForListWithArgsAndEmptyResult() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID < ?"; given(this.resultSet.next()).willReturn(false); List> li = this.template.queryForList(sql, 3); @@ -325,7 +324,7 @@ public void testQueryForListWithArgsAndEmptyResult() throws Exception { } @Test - public void testQueryForListWithArgsAndSingleRowAndColumn() throws Exception { + void testQueryForListWithArgsAndSingleRowAndColumn() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID < ?"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getObject(1)).willReturn(11); @@ -339,13 +338,12 @@ public void testQueryForListWithArgsAndSingleRowAndColumn() throws Exception { } @Test - public void testQueryForListWithArgsAndIntegerElementAndSingleRowAndColumn() throws Exception { + void testQueryForListWithArgsAndIntegerElementAndSingleRowAndColumn() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID < ?"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(11); List li = this.template.queryForList(sql, Integer.class, 3); - assertThat(li).as("All rows returned").hasSize(1); - assertThat(li).element(0).as("First row is Integer").isEqualTo(11); + assertThat(li).containsExactly(11); verify(this.preparedStatement).setObject(1, 3); verify(this.resultSet).close(); verify(this.preparedStatement).close(); @@ -353,7 +351,7 @@ public void testQueryForListWithArgsAndIntegerElementAndSingleRowAndColumn() thr } @Test - public void testQueryForMapWithArgsAndSingleRowAndColumn() throws Exception { + void testQueryForMapWithArgsAndSingleRowAndColumn() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID < ?"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getObject(1)).willReturn(11); @@ -366,7 +364,7 @@ public void testQueryForMapWithArgsAndSingleRowAndColumn() throws Exception { } @Test - public void testQueryForObjectWithArgsAndRowMapper() throws Exception { + void testQueryForObjectWithArgsAndRowMapper() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = ?"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(22); @@ -379,7 +377,7 @@ public void testQueryForObjectWithArgsAndRowMapper() throws Exception { } @Test - public void testQueryForStreamWithArgsAndRowMapper() throws Exception { + void testQueryForStreamWithArgsAndRowMapper() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = ?"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(22); @@ -398,7 +396,7 @@ public void testQueryForStreamWithArgsAndRowMapper() throws Exception { } @Test - public void testQueryForObjectWithArgsAndInteger() throws Exception { + void testQueryForObjectWithArgsAndInteger() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = ?"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(22); @@ -411,7 +409,7 @@ public void testQueryForObjectWithArgsAndInteger() throws Exception { } @Test - public void testQueryForIntWithArgs() throws Exception { + void testQueryForIntWithArgs() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = ?"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getInt(1)).willReturn(22); @@ -424,7 +422,7 @@ public void testQueryForIntWithArgs() throws Exception { } @Test - public void testQueryForLongWithArgs() throws Exception { + void testQueryForLongWithArgs() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = ?"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getLong(1)).willReturn(87L); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java index 2d2de3998d63..70e15f553168 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,7 +75,7 @@ * @author Juergen Hoeller * @author Phillip Webb */ -public class JdbcTemplateTests { +class JdbcTemplateTests { private DataSource dataSource = mock(); @@ -93,7 +93,7 @@ public class JdbcTemplateTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { given(this.dataSource.getConnection()).willReturn(this.connection); given(this.connection.prepareStatement(anyString())).willReturn(this.preparedStatement); given(this.connection.prepareCall(anyString())).willReturn(this.callableStatement); @@ -107,7 +107,7 @@ public void setup() throws Exception { @Test - public void testBeanProperties() throws Exception { + void testBeanProperties() { assertThat(this.template.getDataSource()).as("datasource ok").isSameAs(this.dataSource); assertThat(this.template.isIgnoreWarnings()).as("ignores warnings by default").isTrue(); this.template.setIgnoreWarnings(false); @@ -116,7 +116,7 @@ public void testBeanProperties() throws Exception { } @Test - public void testUpdateCount() throws Exception { + void testUpdateCount() throws Exception { final String sql = "UPDATE INVOICE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; int idParam = 11111; given(this.preparedStatement.executeUpdate()).willReturn(1); @@ -129,7 +129,7 @@ public void testUpdateCount() throws Exception { } @Test - public void testBogusUpdate() throws Exception { + void testBogusUpdate() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int idParam = 6666; @@ -147,23 +147,23 @@ public void testBogusUpdate() throws Exception { } @Test - public void testStringsWithStaticSql() throws Exception { + void testStringsWithStaticSql() throws Exception { doTestStrings(null, null, null, null, JdbcTemplate::query); } @Test - public void testStringsWithStaticSqlAndFetchSizeAndMaxRows() throws Exception { + void testStringsWithStaticSqlAndFetchSizeAndMaxRows() throws Exception { doTestStrings(10, 20, 30, null, JdbcTemplate::query); } @Test - public void testStringsWithEmptyPreparedStatementSetter() throws Exception { + void testStringsWithEmptyPreparedStatementSetter() throws Exception { doTestStrings(null, null, null, null, (template, sql, rch) -> template.query(sql, (PreparedStatementSetter) null, rch)); } @Test - public void testStringsWithPreparedStatementSetter() throws Exception { + void testStringsWithPreparedStatementSetter() throws Exception { final Integer argument = 99; doTestStrings(null, null, null, argument, (template, sql, rch) -> template.query(sql, ps -> ps.setObject(1, argument), rch)); @@ -244,7 +244,7 @@ public String[] getStrings() { } @Test - public void testLeaveConnectionOpenOnRequest() throws Exception { + void testLeaveConnectionOpenOnRequest() throws Exception { String sql = "SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3"; given(this.resultSet.next()).willReturn(false); @@ -263,7 +263,7 @@ public void testLeaveConnectionOpenOnRequest() throws Exception { } @Test - public void testConnectionCallback() throws Exception { + void testConnectionCallback() { String result = this.template.execute((ConnectionCallback) con -> { assertThat(con).isInstanceOf(ConnectionProxy.class); assertThat(((ConnectionProxy) con).getTargetConnection()).isSameAs(JdbcTemplateTests.this.connection); @@ -273,7 +273,7 @@ public void testConnectionCallback() throws Exception { } @Test - public void testConnectionCallbackWithStatementSettings() throws Exception { + void testConnectionCallbackWithStatementSettings() throws Exception { String result = this.template.execute((ConnectionCallback) con -> { PreparedStatement ps = con.prepareStatement("some SQL"); ps.setFetchSize(10); @@ -290,7 +290,7 @@ public void testConnectionCallbackWithStatementSettings() throws Exception { } @Test - public void testCloseConnectionOnRequest() throws Exception { + void testCloseConnectionOnRequest() throws Exception { String sql = "SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3"; given(this.resultSet.next()).willReturn(false); @@ -308,7 +308,7 @@ public void testCloseConnectionOnRequest() throws Exception { * Test that we see a runtime exception come back. */ @Test - public void testExceptionComesBack() throws Exception { + void testExceptionComesBack() throws Exception { final String sql = "SELECT ID FROM CUSTMR"; final RuntimeException runtimeException = new RuntimeException("Expected"); @@ -334,7 +334,7 @@ public void testExceptionComesBack() throws Exception { * Test update with static SQL. */ @Test - public void testSqlUpdate() throws Exception { + void testSqlUpdate() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = 4"; int rowsAffected = 33; @@ -351,7 +351,7 @@ public void testSqlUpdate() throws Exception { * Test update with dynamic SQL. */ @Test - public void testSqlUpdateWithArguments() throws Exception { + void testSqlUpdateWithArguments() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ? and PR = ?"; int rowsAffected = 33; given(this.preparedStatement.executeUpdate()).willReturn(rowsAffected); @@ -366,7 +366,7 @@ public void testSqlUpdateWithArguments() throws Exception { } @Test - public void testSqlUpdateEncountersSqlException() throws Exception { + void testSqlUpdateEncountersSqlException() throws Exception { SQLException sqlException = new SQLException("bad update"); final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = 4"; @@ -381,7 +381,7 @@ public void testSqlUpdateEncountersSqlException() throws Exception { } @Test - public void testSqlUpdateWithThreadConnection() throws Exception { + void testSqlUpdateWithThreadConnection() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = 4"; int rowsAffected = 33; @@ -396,7 +396,7 @@ public void testSqlUpdateWithThreadConnection() throws Exception { } @Test - public void testBatchUpdate() throws Exception { + void testBatchUpdate() throws Exception { final String[] sql = {"UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = 1", "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = 2"}; @@ -416,7 +416,7 @@ public void testBatchUpdate() throws Exception { } @Test - public void testBatchUpdateWithBatchFailure() throws Exception { + void testBatchUpdateWithBatchFailure() throws Exception { final String[] sql = {"A", "B", "C", "D"}; given(this.statement.executeBatch()).willThrow( new BatchUpdateException(new int[] {1, Statement.EXECUTE_FAILED, 1, Statement.EXECUTE_FAILED})); @@ -433,7 +433,7 @@ public void testBatchUpdateWithBatchFailure() throws Exception { } @Test - public void testBatchUpdateWithNoBatchSupport() throws Exception { + void testBatchUpdateWithNoBatchSupport() throws Exception { final String[] sql = {"UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = 1", "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = 2"}; @@ -455,7 +455,7 @@ public void testBatchUpdateWithNoBatchSupport() throws Exception { } @Test - public void testBatchUpdateWithNoBatchSupportAndSelect() throws Exception { + void testBatchUpdateWithNoBatchSupportAndSelect() throws Exception { final String[] sql = {"UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = 1", "SELECT * FROM NOSUCHTABLE"}; @@ -474,7 +474,7 @@ public void testBatchUpdateWithNoBatchSupportAndSelect() throws Exception { } @Test - public void testBatchUpdateWithPreparedStatement() throws Exception { + void testBatchUpdateWithPreparedStatement() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] {100, 200}; final int[] rowsAffected = new int[] {1, 2}; @@ -508,7 +508,7 @@ public int getBatchSize() { } @Test - public void testBatchUpdateWithPreparedStatementWithEmptyData() throws Exception { + void testBatchUpdateWithPreparedStatementWithEmptyData() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] {}; final int[] rowsAffected = new int[] {}; @@ -536,7 +536,7 @@ public int getBatchSize() { } @Test - public void testInterruptibleBatchUpdate() throws Exception { + void testInterruptibleBatchUpdate() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] {100, 200}; final int[] rowsAffected = new int[] {1, 2}; @@ -577,7 +577,7 @@ public boolean isBatchExhausted(int i) { } @Test - public void testInterruptibleBatchUpdateWithBaseClass() throws Exception { + void testInterruptibleBatchUpdateWithBaseClass() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] {100, 200}; final int[] rowsAffected = new int[] {1, 2}; @@ -614,7 +614,7 @@ protected boolean setValuesIfAvailable(PreparedStatement ps, int i) throws SQLEx } @Test - public void testInterruptibleBatchUpdateWithBaseClassAndNoBatchSupport() throws Exception { + void testInterruptibleBatchUpdateWithBaseClassAndNoBatchSupport() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] {100, 200}; final int[] rowsAffected = new int[] {1, 2}; @@ -651,7 +651,7 @@ protected boolean setValuesIfAvailable(PreparedStatement ps, int i) throws SQLEx } @Test - public void testBatchUpdateWithPreparedStatementAndNoBatchSupport() throws Exception { + void testBatchUpdateWithPreparedStatementAndNoBatchSupport() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] {100, 200}; final int[] rowsAffected = new int[] {1, 2}; @@ -682,7 +682,7 @@ public int getBatchSize() { } @Test - public void testBatchUpdateFails() throws Exception { + void testBatchUpdateFails() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int[] ids = new int[] {100, 200}; SQLException sqlException = new SQLException(); @@ -716,7 +716,7 @@ public int getBatchSize() { } @Test - public void testBatchUpdateWithEmptyList() throws Exception { + void testBatchUpdateWithEmptyList() { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; JdbcTemplate template = new JdbcTemplate(this.dataSource, false); @@ -725,7 +725,7 @@ public void testBatchUpdateWithEmptyList() throws Exception { } @Test - public void testBatchUpdateWithListOfObjectArrays() throws Exception { + void testBatchUpdateWithListOfObjectArrays() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final List ids = new ArrayList<>(2); ids.add(new Object[] {100}); @@ -749,7 +749,7 @@ public void testBatchUpdateWithListOfObjectArrays() throws Exception { } @Test - public void testBatchUpdateWithListOfObjectArraysPlusTypeInfo() throws Exception { + void testBatchUpdateWithListOfObjectArraysPlusTypeInfo() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final List ids = new ArrayList<>(2); ids.add(new Object[] {100}); @@ -773,7 +773,7 @@ public void testBatchUpdateWithListOfObjectArraysPlusTypeInfo() throws Exception } @Test - public void testBatchUpdateWithCollectionOfObjects() throws Exception { + void testBatchUpdateWithCollectionOfObjects() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final List ids = Arrays.asList(100, 200, 300); final int[] rowsAffected1 = new int[] {1, 2}; @@ -800,7 +800,7 @@ public void testBatchUpdateWithCollectionOfObjects() throws Exception { } @Test - public void testCouldNotGetConnectionForOperationOrExceptionTranslator() throws SQLException { + void testCouldNotGetConnectionForOperationOrExceptionTranslator() throws SQLException { SQLException sqlException = new SQLException("foo", "07xxx"); given(this.dataSource.getConnection()).willThrow(sqlException); JdbcTemplate template = new JdbcTemplate(this.dataSource, false); @@ -812,7 +812,7 @@ public void testCouldNotGetConnectionForOperationOrExceptionTranslator() throws } @Test - public void testCouldNotGetConnectionForOperationWithLazyExceptionTranslator() throws SQLException { + void testCouldNotGetConnectionForOperationWithLazyExceptionTranslator() throws SQLException { SQLException sqlException = new SQLException("foo", "07xxx"); given(this.dataSource.getConnection()).willThrow(sqlException); this.template = new JdbcTemplate(); @@ -826,14 +826,14 @@ public void testCouldNotGetConnectionForOperationWithLazyExceptionTranslator() t } @Test - public void testCouldNotGetConnectionInOperationWithExceptionTranslatorInitializedViaBeanProperty() + void testCouldNotGetConnectionInOperationWithExceptionTranslatorInitializedViaBeanProperty() throws SQLException { doTestCouldNotGetConnectionInOperationWithExceptionTranslatorInitialized(true); } @Test - public void testCouldNotGetConnectionInOperationWithExceptionTranslatorInitializedInAfterPropertiesSet() + void testCouldNotGetConnectionInOperationWithExceptionTranslatorInitializedInAfterPropertiesSet() throws SQLException { doTestCouldNotGetConnectionInOperationWithExceptionTranslatorInitialized(false); @@ -866,7 +866,7 @@ private void doTestCouldNotGetConnectionInOperationWithExceptionTranslatorInitia } @Test - public void testPreparedStatementSetterSucceeds() throws Exception { + void testPreparedStatementSetterSucceeds() throws Exception { final String sql = "UPDATE FOO SET NAME=? WHERE ID = 1"; final String name = "Gary"; int expectedRowsUpdated = 1; @@ -882,7 +882,7 @@ public void testPreparedStatementSetterSucceeds() throws Exception { } @Test - public void testPreparedStatementSetterFails() throws Exception { + void testPreparedStatementSetterFails() throws Exception { final String sql = "UPDATE FOO SET NAME=? WHERE ID = 1"; final String name = "Gary"; SQLException sqlException = new SQLException(); @@ -898,7 +898,7 @@ public void testPreparedStatementSetterFails() throws Exception { } @Test - public void testCouldNotClose() throws Exception { + void testCouldNotClose() throws Exception { SQLException sqlException = new SQLException("bar"); given(this.connection.createStatement()).willReturn(this.statement); given(this.resultSet.next()).willReturn(false); @@ -915,7 +915,7 @@ public void testCouldNotClose() throws Exception { * Mock objects allow us to produce warnings at will */ @Test - public void testFatalWarning() throws Exception { + void testFatalWarning() throws Exception { String sql = "SELECT forename from custmr"; SQLWarning warnings = new SQLWarning("My warning"); @@ -936,7 +936,7 @@ public void testFatalWarning() throws Exception { } @Test - public void testIgnoredWarning() throws Exception { + void testIgnoredWarning() throws Exception { String sql = "SELECT forename from custmr"; SQLWarning warnings = new SQLWarning("My warning"); @@ -956,7 +956,7 @@ public void testIgnoredWarning() throws Exception { } @Test - public void testSQLErrorCodeTranslation() throws Exception { + void testSQLErrorCodeTranslation() throws Exception { final SQLException sqlException = new SQLException("I have a known problem", "99999", 1054); final String sql = "SELECT ID FROM CUSTOMER"; @@ -977,7 +977,7 @@ public void testSQLErrorCodeTranslation() throws Exception { } @Test - public void testSQLErrorCodeTranslationWithSpecifiedDatabaseName() throws Exception { + void testSQLErrorCodeTranslationWithSpecifiedDatabaseName() throws Exception { final SQLException sqlException = new SQLException("I have a known problem", "99999", 1054); final String sql = "SELECT ID FROM CUSTOMER"; @@ -1002,7 +1002,7 @@ public void testSQLErrorCodeTranslationWithSpecifiedDatabaseName() throws Except * to get the metadata */ @Test - public void testUseCustomExceptionTranslator() throws Exception { + void testUseCustomExceptionTranslator() throws Exception { // Bad SQL state final SQLException sqlException = new SQLException("I have a known problem", "07000", 1054); final String sql = "SELECT ID FROM CUSTOMER"; @@ -1027,7 +1027,7 @@ public void testUseCustomExceptionTranslator() throws Exception { } @Test - public void testStaticResultSetClosed() throws Exception { + void testStaticResultSetClosed() throws Exception { ResultSet resultSet2 = mock(); reset(this.preparedStatement); given(this.preparedStatement.executeQuery()).willReturn(resultSet2); @@ -1049,7 +1049,7 @@ public void testStaticResultSetClosed() throws Exception { } @Test - public void testExecuteClosed() throws Exception { + void testExecuteClosed() throws Exception { given(this.resultSet.next()).willReturn(true); given(this.callableStatement.execute()).willReturn(true); given(this.callableStatement.getUpdateCount()).willReturn(-1); @@ -1066,7 +1066,7 @@ public void testExecuteClosed() throws Exception { } @Test - public void testCaseInsensitiveResultsMap() throws Exception { + void testCaseInsensitiveResultsMap() throws Exception { given(this.callableStatement.execute()).willReturn(false); given(this.callableStatement.getUpdateCount()).willReturn(-1); given(this.callableStatement.getObject(1)).willReturn("X"); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java index cea53b66c9f3..57219fee302c 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ * @author Sam Brannen * @since 02.08.2004 */ -public class RowMapperTests { +class RowMapperTests { private final Connection connection = mock(); @@ -61,7 +61,7 @@ public class RowMapperTests { private List result; @BeforeEach - public void setUp() throws SQLException { + void setUp() throws SQLException { given(connection.createStatement()).willReturn(statement); given(connection.prepareStatement(anyString())).willReturn(preparedStatement); given(statement.executeQuery(anyString())).willReturn(resultSet); @@ -76,12 +76,12 @@ public void setUp() throws SQLException { } @AfterEach - public void verifyClosed() throws Exception { + void verifyClosed() throws Exception { verify(resultSet).close(); } @AfterEach - public void verifyResults() { + void verifyResults() { assertThat(result).isNotNull(); assertThat(result).hasSize(2); TestBean testBean1 = result.get(0); @@ -93,19 +93,19 @@ public void verifyResults() { } @Test - public void staticQueryWithRowMapper() throws SQLException { + void staticQueryWithRowMapper() throws SQLException { result = template.query("some SQL", testRowMapper); verify(statement).close(); } @Test - public void preparedStatementCreatorWithRowMapper() throws SQLException { + void preparedStatementCreatorWithRowMapper() throws SQLException { result = template.query(con -> preparedStatement, testRowMapper); verify(preparedStatement).close(); } @Test - public void preparedStatementSetterWithRowMapper() throws SQLException { + void preparedStatementSetterWithRowMapper() throws SQLException { result = template.query("some SQL", ps -> ps.setString(1, "test"), testRowMapper); verify(preparedStatement).setString(1, "test"); verify(preparedStatement).close(); @@ -121,7 +121,7 @@ public void queryWithArgsAndRowMapper() throws SQLException { } @Test - public void queryWithArgsAndTypesAndRowMapper() throws SQLException { + void queryWithArgsAndTypesAndRowMapper() throws SQLException { result = template.query("some SQL", new Object[] { "test1", "test2" }, new int[] { Types.VARCHAR, Types.VARCHAR }, diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/SimpleRowCountCallbackHandler.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/SimpleRowCountCallbackHandler.java index d59fbb53e3a9..9041dfa422cb 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/SimpleRowCountCallbackHandler.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/SimpleRowCountCallbackHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.jdbc.core; import java.sql.ResultSet; -import java.sql.SQLException; /** * Simple row count callback handler for testing purposes. @@ -32,7 +31,7 @@ public class SimpleRowCountCallbackHandler implements RowCallbackHandler { @Override - public void processRow(ResultSet rs) throws SQLException { + public void processRow(ResultSet rs) { count++; } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java index 0c052025dad9..b9bb5a25345f 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ * @author Kazuki Shimizu * @since 5.0.4 */ -public class SingleColumnRowMapperTests { +class SingleColumnRowMapperTests { @Test // SPR-16483 public void useDefaultConversionService() throws SQLException { diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java index a234449b8267..8f906e85646d 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,25 +48,25 @@ * @author Juergen Hoeller * @since 31.08.2004 */ -public class StatementCreatorUtilsTests { +class StatementCreatorUtilsTests { private PreparedStatement preparedStatement = mock(); @Test - public void testSetParameterValueWithNullAndType() throws SQLException { + void testSetParameterValueWithNullAndType() throws SQLException { StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.VARCHAR, null, null); verify(preparedStatement).setNull(1, Types.VARCHAR); } @Test - public void testSetParameterValueWithNullAndTypeName() throws SQLException { + void testSetParameterValueWithNullAndTypeName() throws SQLException { StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.VARCHAR, "mytype", null); verify(preparedStatement).setNull(1, Types.VARCHAR, "mytype"); } @Test - public void testSetParameterValueWithNullAndUnknownType() throws SQLException { + void testSetParameterValueWithNullAndUnknownType() throws SQLException { StatementCreatorUtils.shouldIgnoreGetParameterType = true; Connection con = mock(); DatabaseMetaData dbmd = mock(); @@ -80,7 +80,7 @@ public void testSetParameterValueWithNullAndUnknownType() throws SQLException { } @Test - public void testSetParameterValueWithNullAndUnknownTypeOnInformix() throws SQLException { + void testSetParameterValueWithNullAndUnknownTypeOnInformix() throws SQLException { StatementCreatorUtils.shouldIgnoreGetParameterType = true; Connection con = mock(); DatabaseMetaData dbmd = mock(); @@ -96,7 +96,7 @@ public void testSetParameterValueWithNullAndUnknownTypeOnInformix() throws SQLEx } @Test - public void testSetParameterValueWithNullAndUnknownTypeOnDerbyEmbedded() throws SQLException { + void testSetParameterValueWithNullAndUnknownTypeOnDerbyEmbedded() throws SQLException { StatementCreatorUtils.shouldIgnoreGetParameterType = true; Connection con = mock(); DatabaseMetaData dbmd = mock(); @@ -112,7 +112,7 @@ public void testSetParameterValueWithNullAndUnknownTypeOnDerbyEmbedded() throws } @Test - public void testSetParameterValueWithNullAndGetParameterTypeWorking() throws SQLException { + void testSetParameterValueWithNullAndGetParameterTypeWorking() throws SQLException { ParameterMetaData pmd = mock(); given(preparedStatement.getParameterMetaData()).willReturn(pmd); given(pmd.getParameterType(1)).willReturn(Types.SMALLINT); @@ -123,13 +123,13 @@ public void testSetParameterValueWithNullAndGetParameterTypeWorking() throws SQL } @Test - public void testSetParameterValueWithString() throws SQLException { + void testSetParameterValueWithString() throws SQLException { StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.VARCHAR, null, "test"); verify(preparedStatement).setString(1, "test"); } @Test - public void testSetParameterValueWithStringAndSpecialType() throws SQLException { + void testSetParameterValueWithStringAndSpecialType() throws SQLException { StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.CHAR, null, "test"); verify(preparedStatement).setObject(1, "test", Types.CHAR); } @@ -140,77 +140,77 @@ public void testSetParameterValueWithStringAndSpecialType() throws SQLException } @Test - public void testSetParameterValueWithSqlDate() throws SQLException { + void testSetParameterValueWithSqlDate() throws SQLException { java.sql.Date date = new java.sql.Date(1000); StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.DATE, null, date); verify(preparedStatement).setDate(1, date); } @Test - public void testSetParameterValueWithDateAndUtilDate() throws SQLException { + void testSetParameterValueWithDateAndUtilDate() throws SQLException { java.util.Date date = new java.util.Date(1000); StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.DATE, null, date); verify(preparedStatement).setDate(1, new java.sql.Date(1000)); } @Test - public void testSetParameterValueWithDateAndCalendar() throws SQLException { + void testSetParameterValueWithDateAndCalendar() throws SQLException { java.util.Calendar cal = new GregorianCalendar(); StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.DATE, null, cal); verify(preparedStatement).setDate(1, new java.sql.Date(cal.getTime().getTime()), cal); } @Test - public void testSetParameterValueWithSqlTime() throws SQLException { + void testSetParameterValueWithSqlTime() throws SQLException { java.sql.Time time = new java.sql.Time(1000); StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.TIME, null, time); verify(preparedStatement).setTime(1, time); } @Test - public void testSetParameterValueWithTimeAndUtilDate() throws SQLException { + void testSetParameterValueWithTimeAndUtilDate() throws SQLException { java.util.Date date = new java.util.Date(1000); StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.TIME, null, date); verify(preparedStatement).setTime(1, new java.sql.Time(1000)); } @Test - public void testSetParameterValueWithTimeAndCalendar() throws SQLException { + void testSetParameterValueWithTimeAndCalendar() throws SQLException { java.util.Calendar cal = new GregorianCalendar(); StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.TIME, null, cal); verify(preparedStatement).setTime(1, new java.sql.Time(cal.getTime().getTime()), cal); } @Test - public void testSetParameterValueWithSqlTimestamp() throws SQLException { + void testSetParameterValueWithSqlTimestamp() throws SQLException { java.sql.Timestamp timestamp = new java.sql.Timestamp(1000); StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.TIMESTAMP, null, timestamp); verify(preparedStatement).setTimestamp(1, timestamp); } @Test - public void testSetParameterValueWithTimestampAndUtilDate() throws SQLException { + void testSetParameterValueWithTimestampAndUtilDate() throws SQLException { java.util.Date date = new java.util.Date(1000); StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.TIMESTAMP, null, date); verify(preparedStatement).setTimestamp(1, new java.sql.Timestamp(1000)); } @Test - public void testSetParameterValueWithTimestampAndCalendar() throws SQLException { + void testSetParameterValueWithTimestampAndCalendar() throws SQLException { java.util.Calendar cal = new GregorianCalendar(); StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.TIMESTAMP, null, cal); verify(preparedStatement).setTimestamp(1, new java.sql.Timestamp(cal.getTime().getTime()), cal); } @Test - public void testSetParameterValueWithDateAndUnknownType() throws SQLException { + void testSetParameterValueWithDateAndUnknownType() throws SQLException { java.util.Date date = new java.util.Date(1000); StatementCreatorUtils.setParameterValue(preparedStatement, 1, SqlTypeValue.TYPE_UNKNOWN, null, date); verify(preparedStatement).setTimestamp(1, new java.sql.Timestamp(1000)); } @Test - public void testSetParameterValueWithCalendarAndUnknownType() throws SQLException { + void testSetParameterValueWithCalendarAndUnknownType() throws SQLException { java.util.Calendar cal = new GregorianCalendar(); StatementCreatorUtils.setParameterValue(preparedStatement, 1, SqlTypeValue.TYPE_UNKNOWN, null, cal); verify(preparedStatement).setTimestamp(1, new java.sql.Timestamp(cal.getTime().getTime()), cal); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSourceTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSourceTests.java index e6ddf99e55fd..ff3d5e603e25 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSourceTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,23 +32,23 @@ * @author Arjen Poutsma * @author Juergen Hoeller */ -public class BeanPropertySqlParameterSourceTests { +class BeanPropertySqlParameterSourceTests { @Test - public void withNullBeanPassedToCtor() { + void withNullBeanPassedToCtor() { assertThatIllegalArgumentException().isThrownBy(() -> new BeanPropertySqlParameterSource(null)); } @Test - public void getValueWhereTheUnderlyingBeanHasNoSuchProperty() { + void getValueWhereTheUnderlyingBeanHasNoSuchProperty() { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean()); assertThatIllegalArgumentException().isThrownBy(() -> source.getValue("thisPropertyDoesNotExist")); } @Test - public void successfulPropertyAccess() { + void successfulPropertyAccess() { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99)); assertThat(Arrays.asList(source.getReadablePropertyNames())).contains("name"); assertThat(Arrays.asList(source.getReadablePropertyNames())).contains("age"); @@ -59,7 +59,7 @@ public void successfulPropertyAccess() { } @Test - public void successfulPropertyAccessWithOverriddenSqlType() { + void successfulPropertyAccessWithOverriddenSqlType() { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99)); source.registerSqlType("age", Types.NUMERIC); assertThat(source.getValue("name")).isEqualTo("tb"); @@ -69,26 +69,26 @@ public void successfulPropertyAccessWithOverriddenSqlType() { } @Test - public void hasValueWhereTheUnderlyingBeanHasNoSuchProperty() { + void hasValueWhereTheUnderlyingBeanHasNoSuchProperty() { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean()); assertThat(source.hasValue("thisPropertyDoesNotExist")).isFalse(); } @Test - public void getValueWhereTheUnderlyingBeanPropertyIsNotReadable() { + void getValueWhereTheUnderlyingBeanPropertyIsNotReadable() { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new NoReadableProperties()); assertThatIllegalArgumentException().isThrownBy(() -> source.getValue("noOp")); } @Test - public void hasValueWhereTheUnderlyingBeanPropertyIsNotReadable() { + void hasValueWhereTheUnderlyingBeanPropertyIsNotReadable() { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new NoReadableProperties()); assertThat(source.hasValue("noOp")).isFalse(); } @Test - public void toStringShowsParameterDetails() { + void toStringShowsParameterDetails() { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99)); assertThat(source.toString()) .startsWith("BeanPropertySqlParameterSource {") @@ -98,7 +98,7 @@ public void toStringShowsParameterDetails() { } @Test - public void toStringShowsCustomSqlType() { + void toStringShowsCustomSqlType() { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99)); source.registerSqlType("name", Integer.MAX_VALUE); assertThat(source.toString()) @@ -109,7 +109,7 @@ public void toStringShowsCustomSqlType() { } @Test - public void toStringDoesNotShowTypeUnknown() { + void toStringDoesNotShowTypeUnknown() { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99)); assertThat(source.toString()) .startsWith("BeanPropertySqlParameterSource {") diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/MapSqlParameterSourceTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/MapSqlParameterSourceTests.java index 2159ab1f50aa..9a20f1d1c86d 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/MapSqlParameterSourceTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/MapSqlParameterSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,22 +31,22 @@ * @author Arjen Poutsma * @author Juergen Hoeller */ -public class MapSqlParameterSourceTests { +class MapSqlParameterSourceTests { @Test - public void nullParameterValuesPassedToCtorIsOk() { + void nullParameterValuesPassedToCtorIsOk() { new MapSqlParameterSource(null); } @Test - public void getValueChokesIfParameterIsNotPresent() { + void getValueChokesIfParameterIsNotPresent() { MapSqlParameterSource source = new MapSqlParameterSource(); assertThatIllegalArgumentException().isThrownBy(() -> source.getValue("pechorin was right!")); } @Test - public void sqlParameterValueRegistersSqlType() { + void sqlParameterValueRegistersSqlType() { MapSqlParameterSource msps = new MapSqlParameterSource("FOO", new SqlParameterValue(Types.NUMERIC, "Foo")); assertThat(msps.getSqlType("FOO")).as("Correct SQL Type not registered").isEqualTo(2); MapSqlParameterSource msps2 = new MapSqlParameterSource(); @@ -55,19 +55,19 @@ public void sqlParameterValueRegistersSqlType() { } @Test - public void toStringShowsParameterDetails() { + void toStringShowsParameterDetails() { MapSqlParameterSource source = new MapSqlParameterSource("FOO", new SqlParameterValue(Types.NUMERIC, "Foo")); assertThat(source.toString()).isEqualTo("MapSqlParameterSource {FOO=Foo (type:NUMERIC)}"); } @Test - public void toStringShowsCustomSqlType() { + void toStringShowsCustomSqlType() { MapSqlParameterSource source = new MapSqlParameterSource("FOO", new SqlParameterValue(Integer.MAX_VALUE, "Foo")); assertThat(source.toString()).isEqualTo(("MapSqlParameterSource {FOO=Foo (type:" + Integer.MAX_VALUE + ")}")); } @Test - public void toStringDoesNotShowTypeUnknown() { + void toStringDoesNotShowTypeUnknown() { MapSqlParameterSource source = new MapSqlParameterSource("FOO", new SqlParameterValue(JdbcUtils.TYPE_UNKNOWN, "Foo")); assertThat(source.toString()).isEqualTo("MapSqlParameterSource {FOO=Foo}"); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplateTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplateTests.java index 2b65f12a7b06..37e661c8990f 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplateTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,7 +61,7 @@ * @author Nikita Khateev * @author Fedor Bobin */ -public class NamedParameterJdbcTemplateTests { +class NamedParameterJdbcTemplateTests { private static final String SELECT_NAMED_PARAMETERS = "select id, forename from custmr where id = :id and country = :country"; @@ -99,7 +99,7 @@ public class NamedParameterJdbcTemplateTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { given(dataSource.getConnection()).willReturn(connection); given(connection.prepareStatement(anyString())).willReturn(preparedStatement); given(preparedStatement.getConnection()).willReturn(connection); @@ -110,24 +110,24 @@ public void setup() throws Exception { @Test - public void testNullDataSourceProvidedToCtor() { + void testNullDataSourceProvidedToCtor() { assertThatIllegalArgumentException().isThrownBy(() -> new NamedParameterJdbcTemplate((DataSource) null)); } @Test - public void testNullJdbcTemplateProvidedToCtor() { + void testNullJdbcTemplateProvidedToCtor() { assertThatIllegalArgumentException().isThrownBy(() -> new NamedParameterJdbcTemplate((JdbcOperations) null)); } @Test - public void testTemplateConfiguration() { + void testTemplateConfiguration() { assertThat(namedParameterTemplate.getJdbcTemplate().getDataSource()).isSameAs(dataSource); } @Test - public void testExecute() throws SQLException { + void testExecute() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); params.put("perfId", 1); @@ -149,7 +149,7 @@ public void testExecute() throws SQLException { @Disabled("SPR-16340") @Test - public void testExecuteArray() throws SQLException { + void testExecuteArray() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); List typeIds = Arrays.asList(1, 2, 3); @@ -174,7 +174,7 @@ public void testExecuteArray() throws SQLException { } @Test - public void testExecuteWithTypedParameters() throws SQLException { + void testExecuteWithTypedParameters() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); params.put("perfId", new SqlParameterValue(Types.DECIMAL, 1)); @@ -195,7 +195,7 @@ public void testExecuteWithTypedParameters() throws SQLException { } @Test - public void testExecuteNoParameters() throws SQLException { + void testExecuteNoParameters() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); Object result = namedParameterTemplate.execute(SELECT_NO_PARAMETERS, @@ -212,7 +212,7 @@ public void testExecuteNoParameters() throws SQLException { } @Test - public void testQueryWithResultSetExtractor() throws SQLException { + void testQueryWithResultSetExtractor() throws SQLException { given(resultSet.next()).willReturn(true); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -239,7 +239,7 @@ public void testQueryWithResultSetExtractor() throws SQLException { } @Test - public void testQueryWithResultSetExtractorNoParameters() throws SQLException { + void testQueryWithResultSetExtractorNoParameters() throws SQLException { given(resultSet.next()).willReturn(true); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -262,7 +262,7 @@ public void testQueryWithResultSetExtractorNoParameters() throws SQLException { } @Test - public void testQueryWithRowCallbackHandler() throws SQLException { + void testQueryWithRowCallbackHandler() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -289,7 +289,7 @@ public void testQueryWithRowCallbackHandler() throws SQLException { } @Test - public void testQueryWithRowCallbackHandlerNoParameters() throws SQLException { + void testQueryWithRowCallbackHandlerNoParameters() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -312,7 +312,7 @@ public void testQueryWithRowCallbackHandlerNoParameters() throws SQLException { } @Test - public void testQueryWithRowMapper() throws SQLException { + void testQueryWithRowMapper() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -339,7 +339,7 @@ public void testQueryWithRowMapper() throws SQLException { } @Test - public void testQueryWithRowMapperNoParameters() throws SQLException { + void testQueryWithRowMapperNoParameters() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -362,7 +362,7 @@ public void testQueryWithRowMapperNoParameters() throws SQLException { } @Test - public void testQueryForObjectWithRowMapper() throws SQLException { + void testQueryForObjectWithRowMapper() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -389,7 +389,7 @@ public void testQueryForObjectWithRowMapper() throws SQLException { } @Test - public void testQueryForStreamWithRowMapper() throws SQLException { + void testQueryForStreamWithRowMapper() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -422,7 +422,7 @@ public void testQueryForStreamWithRowMapper() throws SQLException { } @Test - public void testUpdate() throws SQLException { + void testUpdate() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); params.put("perfId", 1); @@ -438,7 +438,7 @@ public void testUpdate() throws SQLException { } @Test - public void testUpdateWithTypedParameters() throws SQLException { + void testUpdateWithTypedParameters() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); params.put("perfId", new SqlParameterValue(Types.DECIMAL, 1)); @@ -454,7 +454,7 @@ public void testUpdateWithTypedParameters() throws SQLException { } @Test - public void testBatchUpdateWithPlainMap() throws Exception { + void testBatchUpdateWithPlainMap() throws Exception { @SuppressWarnings("unchecked") final Map[] ids = new Map[2]; ids[0] = Collections.singletonMap("id", 100); @@ -479,7 +479,7 @@ public void testBatchUpdateWithPlainMap() throws Exception { } @Test - public void testBatchUpdateWithEmptyMap() throws Exception { + void testBatchUpdateWithEmptyMap() { @SuppressWarnings("unchecked") final Map[] ids = new Map[0]; namedParameterTemplate = new NamedParameterJdbcTemplate(new JdbcTemplate(dataSource, false)); @@ -490,7 +490,7 @@ public void testBatchUpdateWithEmptyMap() throws Exception { } @Test - public void testBatchUpdateWithSqlParameterSource() throws Exception { + void testBatchUpdateWithSqlParameterSource() throws Exception { SqlParameterSource[] ids = new SqlParameterSource[2]; ids[0] = new MapSqlParameterSource("id", 100); ids[1] = new MapSqlParameterSource("id", 200); @@ -514,7 +514,7 @@ public void testBatchUpdateWithSqlParameterSource() throws Exception { } @Test - public void testBatchUpdateWithInClause() throws Exception { + void testBatchUpdateWithInClause() throws Exception { @SuppressWarnings("unchecked") Map[] parameters = new Map[3]; parameters[0] = Collections.singletonMap("ids", Arrays.asList(1, 2)); @@ -554,7 +554,7 @@ public void testBatchUpdateWithInClause() throws Exception { } @Test - public void testBatchUpdateWithSqlParameterSourcePlusTypeInfo() throws Exception { + void testBatchUpdateWithSqlParameterSourcePlusTypeInfo() throws Exception { SqlParameterSource[] ids = new SqlParameterSource[3]; ids[0] = new MapSqlParameterSource().addValue("id", null, Types.NULL); ids[1] = new MapSqlParameterSource().addValue("id", 100, Types.NUMERIC); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java index 7a5b3ae016d1..1297fc29a206 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ * @author Thomas Risberg * @author Phillip Webb */ -public class NamedParameterQueryTests { +class NamedParameterQueryTests { private Connection connection = mock(); @@ -60,7 +60,7 @@ public class NamedParameterQueryTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { given(dataSource.getConnection()).willReturn(connection); given(resultSetMetaData.getColumnCount()).willReturn(1); given(resultSetMetaData.getColumnLabel(1)).willReturn("age"); @@ -69,7 +69,7 @@ public void setup() throws Exception { } @AfterEach - public void verifyClose() throws Exception { + void verifyClose() throws Exception { verify(preparedStatement).close(); verify(resultSet).close(); verify(connection).close(); @@ -77,7 +77,7 @@ public void verifyClose() throws Exception { @Test - public void testQueryForListWithParamMap() throws Exception { + void testQueryForListWithParamMap() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, true, false); given(resultSet.getObject(1)).willReturn(11, 12); @@ -96,7 +96,7 @@ public void testQueryForListWithParamMap() throws Exception { } @Test - public void testQueryForListWithParamMapAndEmptyResult() throws Exception { + void testQueryForListWithParamMapAndEmptyResult() throws Exception { given(resultSet.next()).willReturn(false); MapSqlParameterSource params = new MapSqlParameterSource(); @@ -110,7 +110,7 @@ public void testQueryForListWithParamMapAndEmptyResult() throws Exception { } @Test - public void testQueryForListWithParamMapAndSingleRowAndColumn() throws Exception { + void testQueryForListWithParamMapAndSingleRowAndColumn() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getObject(1)).willReturn(11); @@ -127,7 +127,7 @@ public void testQueryForListWithParamMapAndSingleRowAndColumn() throws Exception } @Test - public void testQueryForListWithParamMapAndIntegerElementAndSingleRowAndColumn() throws Exception { + void testQueryForListWithParamMapAndIntegerElementAndSingleRowAndColumn() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(11); @@ -137,14 +137,13 @@ public void testQueryForListWithParamMapAndIntegerElementAndSingleRowAndColumn() List li = template.queryForList("SELECT AGE FROM CUSTMR WHERE ID < :id", params, Integer.class); - assertThat(li.size()).as("All rows returned").isEqualTo(1); - assertThat(li).element(0).as("First row is Integer").isEqualTo(11); + assertThat(li).containsExactly(11); verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?"); verify(preparedStatement).setObject(1, 3); } @Test - public void testQueryForMapWithParamMapAndSingleRowAndColumn() throws Exception { + void testQueryForMapWithParamMapAndSingleRowAndColumn() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getObject(1)).willReturn(11); @@ -159,7 +158,7 @@ public void testQueryForMapWithParamMapAndSingleRowAndColumn() throws Exception } @Test - public void testQueryForObjectWithParamMapAndRowMapper() throws Exception { + void testQueryForObjectWithParamMapAndRowMapper() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -174,7 +173,7 @@ public void testQueryForObjectWithParamMapAndRowMapper() throws Exception { } @Test - public void testQueryForObjectWithMapAndInteger() throws Exception { + void testQueryForObjectWithMapAndInteger() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -190,7 +189,7 @@ public void testQueryForObjectWithMapAndInteger() throws Exception { } @Test - public void testQueryForObjectWithParamMapAndInteger() throws Exception { + void testQueryForObjectWithParamMapAndInteger() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -206,7 +205,7 @@ public void testQueryForObjectWithParamMapAndInteger() throws Exception { } @Test - public void testQueryForObjectWithParamMapAndList() throws Exception { + void testQueryForObjectWithParamMapAndList() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -221,7 +220,7 @@ public void testQueryForObjectWithParamMapAndList() throws Exception { } @Test - public void testQueryForObjectWithParamMapAndListOfExpressionLists() throws Exception { + void testQueryForObjectWithParamMapAndListOfExpressionLists() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -240,7 +239,7 @@ public void testQueryForObjectWithParamMapAndListOfExpressionLists() throws Exce } @Test - public void testQueryForIntWithParamMap() throws Exception { + void testQueryForIntWithParamMap() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -255,7 +254,7 @@ public void testQueryForIntWithParamMap() throws Exception { } @Test - public void testQueryForLongWithParamBean() throws Exception { + void testQueryForLongWithParamBean() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getLong(1)).willReturn(87L); @@ -269,7 +268,7 @@ public void testQueryForLongWithParamBean() throws Exception { } @Test - public void testQueryForLongWithParamBeanWithCollection() throws Exception { + void testQueryForLongWithParamBeanWithCollection() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getLong(1)).willReturn(87L); @@ -284,7 +283,7 @@ public void testQueryForLongWithParamBeanWithCollection() throws Exception { } @Test - public void testQueryForLongWithParamRecord() throws Exception { + void testQueryForLongWithParamRecord() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getLong(1)).willReturn(87L); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/CallMetaDataContextTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/CallMetaDataContextTests.java index 508fc319a079..24b02f47e1e2 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/CallMetaDataContextTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/CallMetaDataContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ * * @author Thomas Risberg */ -public class CallMetaDataContextTests { +class CallMetaDataContextTests { private DataSource dataSource = mock(); @@ -57,19 +57,19 @@ public class CallMetaDataContextTests { @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { given(connection.getMetaData()).willReturn(databaseMetaData); given(dataSource.getConnection()).willReturn(connection); } @AfterEach - public void verifyClosed() throws Exception { + void verifyClosed() throws Exception { verify(connection).close(); } @Test - public void testMatchParameterValuesAndSqlInOutParameters() throws Exception { + void testMatchParameterValuesAndSqlInOutParameters() throws Exception { final String TABLE = "customers"; final String USER = "me"; given(databaseMetaData.getDatabaseProductName()).willReturn("MyDB"); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientIndexedParameterTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientIndexedParameterTests.java index a0158a36f8a2..80bafa49de65 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientIndexedParameterTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientIndexedParameterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ * @author Juergen Hoeller * @since 6.1 */ -public class JdbcClientIndexedParameterTests { +class JdbcClientIndexedParameterTests { private static final String SELECT_INDEXED_PARAMETERS = "select id, forename from custmr where id = ? and country = ?"; @@ -84,7 +84,7 @@ public class JdbcClientIndexedParameterTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { given(dataSource.getConnection()).willReturn(connection); given(connection.prepareStatement(anyString())).willReturn(preparedStatement); given(preparedStatement.getConnection()).willReturn(connection); @@ -95,7 +95,7 @@ public void setup() throws Exception { @Test - public void queryWithResultSetExtractor() throws SQLException { + void queryWithResultSetExtractor() throws SQLException { given(resultSet.next()).willReturn(true); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -122,7 +122,7 @@ public void queryWithResultSetExtractor() throws SQLException { } @Test - public void queryWithResultSetExtractorNoParameters() throws SQLException { + void queryWithResultSetExtractorNoParameters() throws SQLException { given(resultSet.next()).willReturn(true); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -145,7 +145,7 @@ public void queryWithResultSetExtractorNoParameters() throws SQLException { } @Test - public void queryWithRowCallbackHandler() throws SQLException { + void queryWithRowCallbackHandler() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -172,7 +172,7 @@ public void queryWithRowCallbackHandler() throws SQLException { } @Test - public void queryWithRowCallbackHandlerNoParameters() throws SQLException { + void queryWithRowCallbackHandlerNoParameters() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -195,7 +195,7 @@ public void queryWithRowCallbackHandlerNoParameters() throws SQLException { } @Test - public void queryWithRowMapper() throws SQLException { + void queryWithRowMapper() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -223,7 +223,7 @@ public void queryWithRowMapper() throws SQLException { } @Test - public void queryWithRowMapperNoParameters() throws SQLException { + void queryWithRowMapperNoParameters() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -247,7 +247,7 @@ public void queryWithRowMapperNoParameters() throws SQLException { } @Test - public void queryForObjectWithRowMapper() throws SQLException { + void queryForObjectWithRowMapper() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -274,7 +274,7 @@ public void queryForObjectWithRowMapper() throws SQLException { } @Test - public void queryForStreamWithRowMapper() throws SQLException { + void queryForStreamWithRowMapper() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -307,7 +307,7 @@ public void queryForStreamWithRowMapper() throws SQLException { } @Test - public void update() throws SQLException { + void update() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); params.add(1); @@ -323,7 +323,7 @@ public void update() throws SQLException { } @Test - public void updateWithTypedParameters() throws SQLException { + void updateWithTypedParameters() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); params.add(new SqlParameterValue(Types.DECIMAL, 1)); @@ -339,7 +339,7 @@ public void updateWithTypedParameters() throws SQLException { } @Test - public void updateWithGeneratedKeys() throws SQLException { + void updateWithGeneratedKeys() throws SQLException { given(resultSetMetaData.getColumnCount()).willReturn(1); given(resultSetMetaData.getColumnLabel(1)).willReturn("1"); given(resultSet.getMetaData()).willReturn(resultSetMetaData); @@ -363,7 +363,7 @@ public void updateWithGeneratedKeys() throws SQLException { } @Test - public void updateWithGeneratedKeysAndKeyColumnNames() throws SQLException { + void updateWithGeneratedKeysAndKeyColumnNames() throws SQLException { given(resultSetMetaData.getColumnCount()).willReturn(1); given(resultSetMetaData.getColumnLabel(1)).willReturn("1"); given(resultSet.getMetaData()).willReturn(resultSetMetaData); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientIntegrationTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientIntegrationTests.java index 334230560ec7..99daa91494a2 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientIntegrationTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -155,6 +155,6 @@ private void assertUser(long id, String firstName, String lastName) { } - record User(long id, String firstName, String lastName) {}; + record User(long id, String firstName, String lastName) {} } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientNamedParameterTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientNamedParameterTests.java index 784b6917e3a4..cf457c44186d 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientNamedParameterTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientNamedParameterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -430,7 +430,7 @@ void updateWithGeneratedKeys() throws SQLException { } @Test - public void updateWithGeneratedKeysAndKeyColumnNames() throws SQLException { + void updateWithGeneratedKeysAndKeyColumnNames() throws SQLException { given(resultSetMetaData.getColumnCount()).willReturn(1); given(resultSetMetaData.getColumnLabel(1)).willReturn("1"); given(resultSet.getMetaData()).willReturn(resultSetMetaData); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientQueryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientQueryTests.java index d5f3c9eb7bec..a4bbeaa3c653 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientQueryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/JdbcClientQueryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ * @author Juergen Hoeller * @since 6.1 */ -public class JdbcClientQueryTests { +class JdbcClientQueryTests { private DataSource dataSource = mock(); @@ -60,7 +60,7 @@ public class JdbcClientQueryTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { given(dataSource.getConnection()).willReturn(connection); given(connection.prepareStatement(anyString())).willReturn(preparedStatement); given(preparedStatement.executeQuery()).willReturn(resultSet); @@ -73,7 +73,7 @@ public void setup() throws Exception { // Indexed parameters @Test - public void queryForListWithIndexedParam() throws Exception { + void queryForListWithIndexedParam() throws Exception { given(resultSet.next()).willReturn(true, true, false); given(resultSet.getObject(1)).willReturn(11, 12); @@ -92,7 +92,7 @@ public void queryForListWithIndexedParam() throws Exception { } @Test - public void queryForListWithIndexedParamAndEmptyResult() throws Exception { + void queryForListWithIndexedParamAndEmptyResult() throws Exception { given(resultSet.next()).willReturn(false); List> li = client.sql("SELECT AGE FROM CUSTMR WHERE ID < ?") @@ -107,7 +107,7 @@ public void queryForListWithIndexedParamAndEmptyResult() throws Exception { } @Test - public void queryForListWithIndexedParamAndSingleRow() throws Exception { + void queryForListWithIndexedParamAndSingleRow() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getObject(1)).willReturn(11); @@ -124,7 +124,7 @@ public void queryForListWithIndexedParamAndSingleRow() throws Exception { } @Test - public void queryForMapWithIndexedParamAndSingleRow() throws Exception { + void queryForMapWithIndexedParamAndSingleRow() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getObject(1)).willReturn(11); @@ -141,7 +141,7 @@ public void queryForMapWithIndexedParamAndSingleRow() throws Exception { } @Test - public void queryForListWithIndexedParamAndSingleColumn() throws Exception { + void queryForListWithIndexedParamAndSingleColumn() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getObject(1)).willReturn(11); @@ -149,8 +149,7 @@ public void queryForListWithIndexedParamAndSingleColumn() throws Exception { .param(1, 3) .query().singleColumn(); - assertThat(li.size()).as("All rows returned").isEqualTo(1); - assertThat(li).element(0).as("First row is Integer").isEqualTo(11); + assertThat(li).containsExactly(11); verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?"); verify(preparedStatement).setObject(1, 3); verify(resultSet).close(); @@ -159,7 +158,7 @@ public void queryForListWithIndexedParamAndSingleColumn() throws Exception { } @Test - public void queryForIntegerWithIndexedParamAndSingleValue() throws Exception { + void queryForIntegerWithIndexedParamAndSingleValue() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getObject(1)).willReturn(22); @@ -176,7 +175,7 @@ public void queryForIntegerWithIndexedParamAndSingleValue() throws Exception { } @Test - public void queryForIntegerWithIndexedParamAndRowMapper() throws Exception { + void queryForIntegerWithIndexedParamAndRowMapper() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -194,7 +193,7 @@ public void queryForIntegerWithIndexedParamAndRowMapper() throws Exception { } @Test - public void queryForOptionalWithIndexedParamAndRowMapper() throws Exception { + void queryForOptionalWithIndexedParamAndRowMapper() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -212,7 +211,7 @@ public void queryForOptionalWithIndexedParamAndRowMapper() throws Exception { } @Test - public void queryForIntegerWithIndexedParam() throws Exception { + void queryForIntegerWithIndexedParam() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -229,7 +228,7 @@ public void queryForIntegerWithIndexedParam() throws Exception { } @Test - public void queryForIntWithIndexedParam() throws Exception { + void queryForIntWithIndexedParam() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -246,7 +245,7 @@ public void queryForIntWithIndexedParam() throws Exception { } @Test - public void queryForObjectWithIndexedParamAndList() { + void queryForObjectWithIndexedParamAndList() { assertThatIllegalArgumentException().isThrownBy(() -> client.sql("SELECT AGE FROM CUSTMR WHERE ID IN (?)").param(Arrays.asList(3, 4)).query().singleValue()); } @@ -255,7 +254,7 @@ public void queryForObjectWithIndexedParamAndList() { // Named parameters @Test - public void queryForListWithNamedParam() throws Exception { + void queryForListWithNamedParam() throws Exception { given(resultSet.next()).willReturn(true, true, false); given(resultSet.getObject(1)).willReturn(11, 12); @@ -275,7 +274,7 @@ public void queryForListWithNamedParam() throws Exception { } @Test - public void queryForListWithNamedParamAndEmptyResult() throws Exception { + void queryForListWithNamedParamAndEmptyResult() throws Exception { given(resultSet.next()).willReturn(false); List> li = client.sql("SELECT AGE FROM CUSTMR WHERE ID < :id") @@ -291,7 +290,7 @@ public void queryForListWithNamedParamAndEmptyResult() throws Exception { } @Test - public void queryForListWithNamedParamAndSingleRow() throws Exception { + void queryForListWithNamedParamAndSingleRow() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getObject(1)).willReturn(11); @@ -309,7 +308,7 @@ public void queryForListWithNamedParamAndSingleRow() throws Exception { } @Test - public void queryForMapWithNamedParamAndSingleRow() throws Exception { + void queryForMapWithNamedParamAndSingleRow() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getObject(1)).willReturn(11); @@ -326,7 +325,7 @@ public void queryForMapWithNamedParamAndSingleRow() throws Exception { } @Test - public void queryForListWithNamedParamAndSingleColumn() throws Exception { + void queryForListWithNamedParamAndSingleColumn() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getObject(1)).willReturn(11); @@ -334,8 +333,7 @@ public void queryForListWithNamedParamAndSingleColumn() throws Exception { .param("id", 3) .query().singleColumn(); - assertThat(li.size()).as("All rows returned").isEqualTo(1); - assertThat(li).element(0).as("First row is Integer").isEqualTo(11); + assertThat(li).containsExactly(11); verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?"); verify(preparedStatement).setObject(1, 3); verify(resultSet).close(); @@ -344,7 +342,7 @@ public void queryForListWithNamedParamAndSingleColumn() throws Exception { } @Test - public void queryForIntegerWithNamedParamAndSingleValue() throws Exception { + void queryForIntegerWithNamedParamAndSingleValue() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getObject(1)).willReturn(22); @@ -361,7 +359,7 @@ public void queryForIntegerWithNamedParamAndSingleValue() throws Exception { } @Test - public void queryForIntegerWithNamedParamAndRowMapper() throws Exception { + void queryForIntegerWithNamedParamAndRowMapper() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -379,7 +377,7 @@ public void queryForIntegerWithNamedParamAndRowMapper() throws Exception { } @Test - public void queryForOptionalWithNamedParamAndRowMapper() throws Exception { + void queryForOptionalWithNamedParamAndRowMapper() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -397,7 +395,7 @@ public void queryForOptionalWithNamedParamAndRowMapper() throws Exception { } @Test - public void queryForIntegerWithNamedParam() throws Exception { + void queryForIntegerWithNamedParam() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -414,7 +412,7 @@ public void queryForIntegerWithNamedParam() throws Exception { } @Test - public void queryForIntegerWithNamedParamAndList() throws Exception { + void queryForIntegerWithNamedParamAndList() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -432,7 +430,7 @@ public void queryForIntegerWithNamedParamAndList() throws Exception { } @Test - public void queryForIntegerWithNamedParamAndListOfExpressionLists() throws Exception { + void queryForIntegerWithNamedParamAndListOfExpressionLists() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -455,7 +453,7 @@ public void queryForIntegerWithNamedParamAndListOfExpressionLists() throws Excep } @Test - public void queryForIntWithNamedParam() throws Exception { + void queryForIntWithNamedParam() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -472,7 +470,7 @@ public void queryForIntWithNamedParam() throws Exception { } @Test - public void queryForLongWithParamBean() throws Exception { + void queryForLongWithParamBean() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getLong(1)).willReturn(87L); @@ -489,7 +487,7 @@ public void queryForLongWithParamBean() throws Exception { } @Test - public void queryForLongWithParamBeanWithCollection() throws Exception { + void queryForLongWithParamBeanWithCollection() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getLong(1)).willReturn(87L); @@ -507,7 +505,7 @@ public void queryForLongWithParamBeanWithCollection() throws Exception { } @Test - public void queryForLongWithParamRecord() throws Exception { + void queryForLongWithParamRecord() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getLong(1)).willReturn(87L); @@ -524,7 +522,7 @@ public void queryForLongWithParamRecord() throws Exception { } @Test - public void queryForLongWithParamFieldHolder() throws Exception { + void queryForLongWithParamFieldHolder() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getLong(1)).willReturn(87L); @@ -541,7 +539,7 @@ public void queryForLongWithParamFieldHolder() throws Exception { } @Test - public void queryForMappedRecordWithNamedParam() throws Exception { + void queryForMappedRecordWithNamedParam() throws Exception { given(resultSet.findColumn("age")).willReturn(1); given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); @@ -559,7 +557,7 @@ public void queryForMappedRecordWithNamedParam() throws Exception { } @Test - public void queryForMappedFieldHolderWithNamedParam() throws Exception { + void queryForMappedFieldHolderWithNamedParam() throws Exception { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(22); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcCallTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcCallTests.java index 440d1d2aecd8..2e6050d6358c 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcCallTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcCallTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,7 +79,7 @@ void noSuchStoredProcedure() throws Exception { SimpleJdbcCall sproc = new SimpleJdbcCall(dataSource).withProcedureName(NO_SUCH_PROC); try { assertThatExceptionOfType(BadSqlGrammarException.class) - .isThrownBy(() -> sproc.execute()) + .isThrownBy(sproc::execute) .withCause(sqlException); } finally { @@ -89,7 +89,7 @@ void noSuchStoredProcedure() throws Exception { } @Test - void unnamedParameterHandling() throws Exception { + void unnamedParameterHandling() { final String MY_PROC = "my_proc"; SimpleJdbcCall sproc = new SimpleJdbcCall(dataSource).withProcedureName(MY_PROC); // Shouldn't succeed in adding unnamed parameter diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertIntegrationTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertIntegrationTests.java index bdb499126d0a..499d0bee297e 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertIntegrationTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ class DefaultSchemaTests { class UnquotedIdentifiersInSchemaTests extends AbstractSimpleJdbcInsertIntegrationTests { @Test - void retrieveColumnNamesFromMetadata() throws Exception { + void retrieveColumnNamesFromMetadata() { SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase) .withTableName("users") .usingGeneratedKeyColumns("id"); @@ -80,7 +80,7 @@ void usingColumns() { } @Test // gh-24013 - void usingColumnsAndQuotedIdentifiers() throws Exception { + void usingColumnsAndQuotedIdentifiers() { // NOTE: unquoted identifiers in H2/HSQL must be converted to UPPERCASE // since that's how they are stored in the DB metadata. SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase) @@ -118,7 +118,7 @@ protected String getTableName() { class QuotedIdentifiersInSchemaTests extends AbstractSimpleJdbcInsertIntegrationTests { @Test - void retrieveColumnNamesFromMetadata() throws Exception { + void retrieveColumnNamesFromMetadata() { SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase) .withTableName("Order") .usingGeneratedKeyColumns("id"); @@ -134,7 +134,7 @@ void retrieveColumnNamesFromMetadata() throws Exception { } @Test // gh-24013 - void usingColumnsAndQuotedIdentifiers() throws Exception { + void usingColumnsAndQuotedIdentifiers() { SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase) .withoutTableColumnMetaDataAccess() .withTableName("Order") @@ -194,7 +194,7 @@ void usingColumnsWithSchemaName() { } @Test // gh-24013 - void usingColumnsAndQuotedIdentifiersWithSchemaName() throws Exception { + void usingColumnsAndQuotedIdentifiersWithSchemaName() { // NOTE: unquoted identifiers in H2/HSQL must be converted to UPPERCASE // since that's how they are stored in the DB metadata. SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase) @@ -252,7 +252,7 @@ void usingColumnsWithSchemaName() { } @Test // gh-24013 - void usingColumnsAndQuotedIdentifiersWithSchemaName() throws Exception { + void usingColumnsAndQuotedIdentifiersWithSchemaName() { SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase) .withoutTableColumnMetaDataAccess() .withSchemaName("My_Schema") diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java index 4f82d1dda251..265d0ed1b407 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ * * @author Thomas Risberg */ -public class TableMetaDataContextTests { +class TableMetaDataContextTests { private DataSource dataSource = mock(); @@ -56,14 +56,14 @@ public class TableMetaDataContextTests { @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { given(connection.getMetaData()).willReturn(databaseMetaData); given(dataSource.getConnection()).willReturn(connection); } @Test - public void testMatchInParametersAndSqlTypeInfoWrapping() throws Exception { + void testMatchInParametersAndSqlTypeInfoWrapping() throws Exception { final String TABLE = "customers"; final String USER = "me"; @@ -119,7 +119,7 @@ public void testMatchInParametersAndSqlTypeInfoWrapping() throws Exception { } @Test - public void testTableWithSingleColumnGeneratedKey() throws Exception { + void testTableWithSingleColumnGeneratedKey() throws Exception { final String TABLE = "customers"; final String USER = "me"; diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcDaoSupportTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcDaoSupportTests.java index 7c0bcf9c053a..4e48107dd5e7 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcDaoSupportTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcDaoSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,10 +32,10 @@ * @author Juergen Hoeller * @since 30.07.2003 */ -public class JdbcDaoSupportTests { +class JdbcDaoSupportTests { @Test - public void testJdbcDaoSupportWithDataSource() throws Exception { + void testJdbcDaoSupportWithDataSource() { DataSource ds = mock(); final List test = new ArrayList<>(); JdbcDaoSupport dao = new JdbcDaoSupport() { @@ -52,7 +52,7 @@ protected void initDao() { } @Test - public void testJdbcDaoSupportWithJdbcTemplate() throws Exception { + void testJdbcDaoSupportWithJdbcTemplate() { JdbcTemplate template = new JdbcTemplate(); final List test = new ArrayList<>(); JdbcDaoSupport dao = new JdbcDaoSupport() { diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java index 9bee729228e8..cc6559af013e 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,10 +37,10 @@ /** * @author Alef Arendsen */ -public class LobSupportTests { +class LobSupportTests { @Test - public void testCreatingPreparedStatementCallback() throws SQLException { + void testCreatingPreparedStatementCallback() throws SQLException { LobHandler handler = mock(); LobCreator creator = mock(); PreparedStatement ps = mock(); @@ -69,7 +69,7 @@ protected void setValues(PreparedStatement ps, LobCreator lobCreator) { } @Test - public void testAbstractLobStreamingResultSetExtractorNoRows() throws SQLException { + void testAbstractLobStreamingResultSetExtractorNoRows() throws SQLException { ResultSet rs = mock(); AbstractLobStreamingResultSetExtractor lobRse = getResultSetExtractor(false); assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class) @@ -78,7 +78,7 @@ public void testAbstractLobStreamingResultSetExtractorNoRows() throws SQLExcepti } @Test - public void testAbstractLobStreamingResultSetExtractorOneRow() throws SQLException { + void testAbstractLobStreamingResultSetExtractorOneRow() throws SQLException { ResultSet rs = mock(); given(rs.next()).willReturn(true, false); AbstractLobStreamingResultSetExtractor lobRse = getResultSetExtractor(false); @@ -87,7 +87,7 @@ public void testAbstractLobStreamingResultSetExtractorOneRow() throws SQLExcepti } @Test - public void testAbstractLobStreamingResultSetExtractorMultipleRows() throws SQLException { + void testAbstractLobStreamingResultSetExtractorMultipleRows() throws SQLException { ResultSet rs = mock(); given(rs.next()).willReturn(true, true, false); AbstractLobStreamingResultSetExtractor lobRse = getResultSetExtractor(false); @@ -97,7 +97,7 @@ public void testAbstractLobStreamingResultSetExtractorMultipleRows() throws SQLE } @Test - public void testAbstractLobStreamingResultSetExtractorCorrectException() throws SQLException { + void testAbstractLobStreamingResultSetExtractorCorrectException() throws SQLException { ResultSet rs = mock(); given(rs.next()).willReturn(true); AbstractLobStreamingResultSetExtractor lobRse = getResultSetExtractor(true); @@ -106,7 +106,7 @@ public void testAbstractLobStreamingResultSetExtractorCorrectException() throws } private AbstractLobStreamingResultSetExtractor getResultSetExtractor(final boolean ex) { - AbstractLobStreamingResultSetExtractor lobRse = new AbstractLobStreamingResultSetExtractor<>() { + return new AbstractLobStreamingResultSetExtractor<>() { @Override protected void streamData(ResultSet rs) throws SQLException, IOException { if (ex) { @@ -117,7 +117,6 @@ protected void streamData(ResultSet rs) throws SQLException, IOException { } } }; - return lobRse; } } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/SqlLobValueTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/SqlLobValueTests.java index 4f68bdec1a89..e4b3e26cfc24 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/SqlLobValueTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/SqlLobValueTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -96,7 +96,7 @@ void test2() throws SQLException { } @Test - void test3() throws SQLException { + void test3() { SqlLobValue lob = new SqlLobValue(new InputStreamReader(new ByteArrayInputStream("Bla".getBytes())), 12); assertThatIllegalArgumentException().isThrownBy(() -> lob.setTypeValue(preparedStatement, 1, Types.BLOB, "test")); @@ -132,7 +132,7 @@ void test6() throws SQLException { } @Test - void test7() throws SQLException { + void test7() { SqlLobValue lob = new SqlLobValue("bla".getBytes()); assertThatIllegalArgumentException().isThrownBy(() -> lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test")); @@ -182,7 +182,7 @@ void testCorrectCleanup() throws SQLException { } @Test - void testOtherSqlType() throws SQLException { + void testOtherSqlType() { SqlLobValue lob = new SqlLobValue("Bla", handler); assertThatIllegalArgumentException().isThrownBy(() -> lob.setTypeValue(preparedStatement, 1, Types.SMALLINT, "test")); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceJtaTransactionTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceJtaTransactionTests.java index cb02735f3429..1d72d3cf8302 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceJtaTransactionTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceJtaTransactionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,6 @@ import javax.sql.DataSource; -import jakarta.transaction.RollbackException; import jakarta.transaction.Status; import jakarta.transaction.SystemException; import jakarta.transaction.Transaction; @@ -61,7 +60,7 @@ * @author Juergen Hoeller * @since 17.10.2005 */ -public class DataSourceJtaTransactionTests { +class DataSourceJtaTransactionTests { private DataSource dataSource = mock(); @@ -75,12 +74,12 @@ public class DataSourceJtaTransactionTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { given(dataSource.getConnection()).willReturn(connection); } @AfterEach - public void verifyTransactionSynchronizationManagerState() { + void verifyTransactionSynchronizationManagerState() { assertThat(TransactionSynchronizationManager.getResourceMap()).isEmpty(); assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse(); assertThat(TransactionSynchronizationManager.getCurrentTransactionName()).isNull(); @@ -91,12 +90,12 @@ public void verifyTransactionSynchronizationManagerState() { @Test - public void testJtaTransactionCommit() throws Exception { + void testJtaTransactionCommit() throws Exception { doTestJtaTransaction(false); } @Test - public void testJtaTransactionRollback() throws Exception { + void testJtaTransactionRollback() throws Exception { doTestJtaTransaction(true); } @@ -146,52 +145,52 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run } @Test - public void testJtaTransactionCommitWithPropagationRequiresNew() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNew() throws Exception { doTestJtaTransactionWithPropagationRequiresNew(false, false, false, false); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithAccessAfterResume() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithAccessAfterResume() throws Exception { doTestJtaTransactionWithPropagationRequiresNew(false, false, true, false); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnection() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnection() throws Exception { doTestJtaTransactionWithPropagationRequiresNew(false, true, false, false); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnectionAccessed() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnectionAccessed() throws Exception { doTestJtaTransactionWithPropagationRequiresNew(false, true, true, false); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithTransactionAwareDataSource() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithTransactionAwareDataSource() throws Exception { doTestJtaTransactionWithPropagationRequiresNew(false, false, true, true); } @Test - public void testJtaTransactionRollbackWithPropagationRequiresNew() throws Exception { + void testJtaTransactionRollbackWithPropagationRequiresNew() throws Exception { doTestJtaTransactionWithPropagationRequiresNew(true, false, false, false); } @Test - public void testJtaTransactionRollbackWithPropagationRequiresNewWithAccessAfterResume() throws Exception { + void testJtaTransactionRollbackWithPropagationRequiresNewWithAccessAfterResume() throws Exception { doTestJtaTransactionWithPropagationRequiresNew(true, false, true, false); } @Test - public void testJtaTransactionRollbackWithPropagationRequiresNewWithOpenOuterConnection() throws Exception { + void testJtaTransactionRollbackWithPropagationRequiresNewWithOpenOuterConnection() throws Exception { doTestJtaTransactionWithPropagationRequiresNew(true, true, false, false); } @Test - public void testJtaTransactionRollbackWithPropagationRequiresNewWithOpenOuterConnectionAccessed() throws Exception { + void testJtaTransactionRollbackWithPropagationRequiresNewWithOpenOuterConnectionAccessed() throws Exception { doTestJtaTransactionWithPropagationRequiresNew(true, true, true, false); } @Test - public void testJtaTransactionRollbackWithPropagationRequiresNewWithTransactionAwareDataSource() throws Exception { + void testJtaTransactionRollbackWithPropagationRequiresNewWithTransactionAwareDataSource() throws Exception { doTestJtaTransactionWithPropagationRequiresNew(true, false, true, true); } @@ -317,22 +316,22 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run } @Test - public void testJtaTransactionCommitWithPropagationRequiredWithinSupports() throws Exception { + void testJtaTransactionCommitWithPropagationRequiredWithinSupports() throws Exception { doTestJtaTransactionCommitWithNewTransactionWithinEmptyTransaction(false, false); } @Test - public void testJtaTransactionCommitWithPropagationRequiredWithinNotSupported() throws Exception { + void testJtaTransactionCommitWithPropagationRequiredWithinNotSupported() throws Exception { doTestJtaTransactionCommitWithNewTransactionWithinEmptyTransaction(false, true); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithinSupports() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithinSupports() throws Exception { doTestJtaTransactionCommitWithNewTransactionWithinEmptyTransaction(true, false); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithinNotSupported() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithinNotSupported() throws Exception { doTestJtaTransactionCommitWithNewTransactionWithinEmptyTransaction(true, true); } @@ -406,42 +405,42 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewAndSuspendException() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewAndSuspendException() throws Exception { doTestJtaTransactionWithPropagationRequiresNewAndBeginException(true, false, false); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnectionAndSuspendException() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnectionAndSuspendException() throws Exception { doTestJtaTransactionWithPropagationRequiresNewAndBeginException(true, true, false); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithTransactionAwareDataSourceAndSuspendException() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithTransactionAwareDataSourceAndSuspendException() throws Exception { doTestJtaTransactionWithPropagationRequiresNewAndBeginException(true, false, true); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnectionAndTransactionAwareDataSourceAndSuspendException() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnectionAndTransactionAwareDataSourceAndSuspendException() throws Exception { doTestJtaTransactionWithPropagationRequiresNewAndBeginException(true, true, true); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewAndBeginException() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewAndBeginException() throws Exception { doTestJtaTransactionWithPropagationRequiresNewAndBeginException(false, false, false); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnectionAndBeginException() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnectionAndBeginException() throws Exception { doTestJtaTransactionWithPropagationRequiresNewAndBeginException(false, true, false); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnectionAndTransactionAwareDataSourceAndBeginException() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithOpenOuterConnectionAndTransactionAwareDataSourceAndBeginException() throws Exception { doTestJtaTransactionWithPropagationRequiresNewAndBeginException(false, true, true); } @Test - public void testJtaTransactionCommitWithPropagationRequiresNewWithTransactionAwareDataSourceAndBeginException() throws Exception { + void testJtaTransactionCommitWithPropagationRequiresNewWithTransactionAwareDataSourceAndBeginException() throws Exception { doTestJtaTransactionWithPropagationRequiresNewAndBeginException(false, false, true); } @@ -546,21 +545,16 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run } @Test - public void testJtaTransactionWithConnectionHolderStillBound() throws Exception { + void testJtaTransactionWithConnectionHolderStillBound() throws Exception { @SuppressWarnings("serial") JtaTransactionManager ptm = new JtaTransactionManager(userTransaction) { @Override protected void doRegisterAfterCompletionWithJtaTransaction( JtaTransactionObject txObject, - final List synchronizations) - throws RollbackException, SystemException { - Thread async = new Thread() { - @Override - public void run() { - invokeAfterCompletion(synchronizations, TransactionSynchronization.STATUS_COMMITTED); - } - }; + final List synchronizations) { + Thread async = new Thread(() -> invokeAfterCompletion( + synchronizations, TransactionSynchronization.STATUS_COMMITTED)); async.start(); try { async.join(); @@ -608,7 +602,7 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run } @Test - public void testJtaTransactionWithIsolationLevelDataSourceAdapter() throws Exception { + void testJtaTransactionWithIsolationLevelDataSourceAdapter() throws Exception { given(userTransaction.getStatus()).willReturn( Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, @@ -655,12 +649,12 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run } @Test - public void testJtaTransactionWithIsolationLevelDataSourceRouter() throws Exception { + void testJtaTransactionWithIsolationLevelDataSourceRouter() throws Exception { doTestJtaTransactionWithIsolationLevelDataSourceRouter(false); } @Test - public void testJtaTransactionWithIsolationLevelDataSourceRouterWithDataSourceLookup() throws Exception { + void testJtaTransactionWithIsolationLevelDataSourceRouterWithDataSourceLookup() throws Exception { doTestJtaTransactionWithIsolationLevelDataSourceRouter(true); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java index d2d7934f2453..02f87c4d6901 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,7 +68,7 @@ * @since 04.07.2003 * @see org.springframework.jdbc.support.JdbcTransactionManagerTests */ -public class DataSourceTransactionManagerTests { +public class DataSourceTransactionManagerTests { protected DataSource ds = mock(); @@ -78,7 +78,7 @@ public class DataSourceTransactionManagerTests { EmbeddedDatabase db = new EmbeddedDatabaseBuilder()// .addDefaultScripts()// @@ -51,13 +51,13 @@ public void addDefaultScripts() throws Exception { } @Test - public void addScriptWithBogusFileName() { + void addScriptWithBogusFileName() { assertThatExceptionOfType(CannotReadScriptException.class).isThrownBy( new EmbeddedDatabaseBuilder().addScript("bogus.sql")::build); } @Test - public void addScript() throws Exception { + void addScript() { doTwice(() -> { EmbeddedDatabase db = builder// .addScript("db-schema.sql")// @@ -68,7 +68,7 @@ public void addScript() throws Exception { } @Test - public void addScripts() throws Exception { + void addScripts() { doTwice(() -> { EmbeddedDatabase db = builder// .addScripts("db-schema.sql", "db-test-data.sql")// @@ -78,7 +78,7 @@ public void addScripts() throws Exception { } @Test - public void addScriptsWithDefaultCommentPrefix() throws Exception { + void addScriptsWithDefaultCommentPrefix() { doTwice(() -> { EmbeddedDatabase db = builder// .addScripts("db-schema-comments.sql", "db-test-data.sql")// @@ -88,7 +88,7 @@ public void addScriptsWithDefaultCommentPrefix() throws Exception { } @Test - public void addScriptsWithCustomCommentPrefix() throws Exception { + void addScriptsWithCustomCommentPrefix() { doTwice(() -> { EmbeddedDatabase db = builder// .addScripts("db-schema-custom-comments.sql", "db-test-data.sql")// @@ -99,7 +99,7 @@ public void addScriptsWithCustomCommentPrefix() throws Exception { } @Test - public void addScriptsWithCustomBlockComments() throws Exception { + void addScriptsWithCustomBlockComments() { doTwice(() -> { EmbeddedDatabase db = builder// .addScripts("db-schema-block-comments.sql", "db-test-data.sql")// @@ -111,7 +111,7 @@ public void addScriptsWithCustomBlockComments() throws Exception { } @Test - public void setTypeToH2() throws Exception { + void setTypeToH2() { doTwice(() -> { EmbeddedDatabase db = builder// .setType(H2)// @@ -122,7 +122,7 @@ public void setTypeToH2() throws Exception { } @Test - public void setTypeToDerbyAndIgnoreFailedDrops() throws Exception { + void setTypeToDerbyAndIgnoreFailedDrops() { doTwice(() -> { EmbeddedDatabase db = builder// .setType(DERBY)// @@ -133,7 +133,7 @@ public void setTypeToDerbyAndIgnoreFailedDrops() throws Exception { } @Test - public void createSameSchemaTwiceWithoutUniqueDbNames() throws Exception { + void createSameSchemaTwiceWithoutUniqueDbNames() { EmbeddedDatabase db1 = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())) .addScripts("db-schema-without-dropping.sql").build(); try { @@ -146,7 +146,7 @@ public void createSameSchemaTwiceWithoutUniqueDbNames() throws Exception { } @Test - public void createSameSchemaTwiceWithGeneratedUniqueDbNames() throws Exception { + void createSameSchemaTwiceWithGeneratedUniqueDbNames() { EmbeddedDatabase db1 = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()))// .addScripts("db-schema-without-dropping.sql", "db-test-data.sql")// .generateUniqueName(true)// diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBeanTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBeanTests.java index f9dc0c3d228f..fdeaaeaf86f1 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBeanTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ /** * @author Keith Donald */ -public class EmbeddedDatabaseFactoryBeanTests { +class EmbeddedDatabaseFactoryBeanTests { private final ClassRelativeResourceLoader resourceLoader = new ClassRelativeResourceLoader(getClass()); @@ -40,7 +40,7 @@ Resource resource(String path) { } @Test - public void testFactoryBeanLifecycle() throws Exception { + void testFactoryBeanLifecycle() { EmbeddedDatabaseFactoryBean bean = new EmbeddedDatabaseFactoryBean(); ResourceDatabasePopulator populator = new ResourceDatabasePopulator(resource("db-schema.sql"), resource("db-test-data.sql")); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHintsTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHintsTests.java index df37aac9f65d..2bfb57b7670c 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHintsTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHintsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ * * @author Sebastien Deleuze */ -public class EmbeddedDatabaseFactoryRuntimeHintsTests { +class EmbeddedDatabaseFactoryRuntimeHintsTests { private RuntimeHints hints; diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryTests.java index 7f7b7fdf96f4..ecb41f3e783d 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,13 +27,13 @@ /** * @author Keith Donald */ -public class EmbeddedDatabaseFactoryTests { +class EmbeddedDatabaseFactoryTests { private EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory(); @Test - public void testGetDataSource() { + void testGetDataSource() { StubDatabasePopulator populator = new StubDatabasePopulator(); factory.setDatabasePopulator(populator); EmbeddedDatabase db = factory.getDatabase(); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/AbstractDatabasePopulatorTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/AbstractDatabasePopulatorTests.java index 3ed6bce93a4a..e3377867361c 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/AbstractDatabasePopulatorTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/AbstractDatabasePopulatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseInitializa @Test - void scriptWithSingleLineCommentsAndFailedDrop() throws Exception { + void scriptWithSingleLineCommentsAndFailedDrop() { databasePopulator.addScript(resource("db-schema-failed-drop-comments.sql")); databasePopulator.addScript(resource("db-test-data.sql")); databasePopulator.setIgnoreFailedDrops(true); @@ -55,7 +55,7 @@ void scriptWithSingleLineCommentsAndFailedDrop() throws Exception { } @Test - void scriptWithStandardEscapedLiteral() throws Exception { + void scriptWithStandardEscapedLiteral() { databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(resource("db-test-data-escaped-literal.sql")); DatabasePopulatorUtils.execute(databasePopulator, db); @@ -63,7 +63,7 @@ void scriptWithStandardEscapedLiteral() throws Exception { } @Test - void scriptWithMySqlEscapedLiteral() throws Exception { + void scriptWithMySqlEscapedLiteral() { databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(resource("db-test-data-mysql-escaped-literal.sql")); DatabasePopulatorUtils.execute(databasePopulator, db); @@ -71,7 +71,7 @@ void scriptWithMySqlEscapedLiteral() throws Exception { } @Test - void scriptWithMultipleStatements() throws Exception { + void scriptWithMultipleStatements() { databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(resource("db-test-data-multiple.sql")); DatabasePopulatorUtils.execute(databasePopulator, db); @@ -80,7 +80,7 @@ void scriptWithMultipleStatements() throws Exception { } @Test - void scriptWithMultipleStatementsAndLongSeparator() throws Exception { + void scriptWithMultipleStatementsAndLongSeparator() { databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(resource("db-test-data-endings.sql")); databasePopulator.setSeparator("@@"); @@ -90,7 +90,7 @@ void scriptWithMultipleStatementsAndLongSeparator() throws Exception { } @Test - void scriptWithMultipleStatementsAndWhitespaceSeparator() throws Exception { + void scriptWithMultipleStatementsAndWhitespaceSeparator() { databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(resource("db-test-data-whitespace.sql")); databasePopulator.setSeparator("/\n"); @@ -100,7 +100,7 @@ void scriptWithMultipleStatementsAndWhitespaceSeparator() throws Exception { } @Test - void scriptWithMultipleStatementsAndNewlineSeparator() throws Exception { + void scriptWithMultipleStatementsAndNewlineSeparator() { databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(resource("db-test-data-newline.sql")); DatabasePopulatorUtils.execute(databasePopulator, db); @@ -109,7 +109,7 @@ void scriptWithMultipleStatementsAndNewlineSeparator() throws Exception { } @Test - void scriptWithMultipleStatementsAndMultipleNewlineSeparator() throws Exception { + void scriptWithMultipleStatementsAndMultipleNewlineSeparator() { databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(resource("db-test-data-multi-newline.sql")); databasePopulator.setSeparator("\n\n"); @@ -119,7 +119,7 @@ void scriptWithMultipleStatementsAndMultipleNewlineSeparator() throws Exception } @Test - void scriptWithEolBetweenTokens() throws Exception { + void scriptWithEolBetweenTokens() { databasePopulator.addScript(usersSchema()); databasePopulator.addScript(resource("users-data.sql")); DatabasePopulatorUtils.execute(databasePopulator, db); @@ -127,7 +127,7 @@ void scriptWithEolBetweenTokens() throws Exception { } @Test - void scriptWithCommentsWithinStatements() throws Exception { + void scriptWithCommentsWithinStatements() { databasePopulator.addScript(usersSchema()); databasePopulator.addScript(resource("users-data-with-comments.sql")); DatabasePopulatorUtils.execute(databasePopulator, db); @@ -135,7 +135,7 @@ void scriptWithCommentsWithinStatements() throws Exception { } @Test - void scriptWithoutStatementSeparator() throws Exception { + void scriptWithoutStatementSeparator() { databasePopulator.setSeparator(ScriptUtils.EOF_STATEMENT_SEPARATOR); databasePopulator.addScript(resource("drop-users-schema.sql")); databasePopulator.addScript(resource("users-schema-without-separator.sql")); @@ -146,7 +146,7 @@ void scriptWithoutStatementSeparator() throws Exception { } @Test - void constructorWithMultipleScriptResources() throws Exception { + void constructorWithMultipleScriptResources() { final ResourceDatabasePopulator populator = new ResourceDatabasePopulator(usersSchema(), resource("users-data-with-comments.sql")); DatabasePopulatorUtils.execute(populator, db); @@ -154,7 +154,7 @@ void constructorWithMultipleScriptResources() throws Exception { } @Test - void scriptWithSelectStatements() throws Exception { + void scriptWithSelectStatements() { databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(resource("db-test-data-select.sql")); DatabasePopulatorUtils.execute(databasePopulator, db); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/H2DatabasePopulatorTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/H2DatabasePopulatorTests.java index 6a67619bc893..1da75c22dc0c 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/H2DatabasePopulatorTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/H2DatabasePopulatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ protected EmbeddedDatabaseType getEmbeddedDatabaseType() { * @since 5.0 */ @Test - void scriptWithH2Alias() throws Exception { + void scriptWithH2Alias() { databasePopulator.addScript(usersSchema()); databasePopulator.addScript(resource("db-test-data-h2-alias.sql")); // Set statement separator to double newline so that ";" is not diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsIntegrationTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsIntegrationTests.java index 541611a0571e..63590189c691 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsIntegrationTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ * @since 4.0.3 * @see ScriptUtilsUnitTests */ -public class ScriptUtilsIntegrationTests extends AbstractDatabaseInitializationTests { +class ScriptUtilsIntegrationTests extends AbstractDatabaseInitializationTests { @Override protected EmbeddedDatabaseType getEmbeddedDatabaseType() { @@ -40,12 +40,12 @@ protected EmbeddedDatabaseType getEmbeddedDatabaseType() { } @BeforeEach - public void setUpSchema() throws SQLException { + void setUpSchema() throws SQLException { executeSqlScript(db.getConnection(), usersSchema()); } @Test - public void executeSqlScriptContainingMultiLineComments() throws SQLException { + void executeSqlScriptContainingMultiLineComments() throws SQLException { executeSqlScript(db.getConnection(), resource("test-data-with-multi-line-comments.sql")); assertUsersDatabaseCreated("Hoeller", "Brannen"); } @@ -54,7 +54,7 @@ public void executeSqlScriptContainingMultiLineComments() throws SQLException { * @since 4.2 */ @Test - public void executeSqlScriptContainingSingleQuotesNestedInsideDoubleQuotes() throws SQLException { + void executeSqlScriptContainingSingleQuotesNestedInsideDoubleQuotes() throws SQLException { executeSqlScript(db.getConnection(), resource("users-data-with-single-quotes-nested-in-double-quotes.sql")); assertUsersDatabaseCreated("Hoeller", "Brannen"); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSourceTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSourceTests.java index 6ec95a438c6e..e639f287d1c0 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSourceTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -161,7 +161,7 @@ protected Object determineCurrentLookupKey() { } @Test - public void notInitialized() { + void notInitialized() { AbstractRoutingDataSource routingDataSource = new AbstractRoutingDataSource() { @Override protected Object determineCurrentLookupKey() { diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/BeanFactoryDataSourceLookupTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/BeanFactoryDataSourceLookupTests.java index ff3f4a0be455..d32a516cbe4a 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/BeanFactoryDataSourceLookupTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/BeanFactoryDataSourceLookupTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,13 +34,13 @@ * @author Juergen Hoeller * @author Chris Beams */ -public class BeanFactoryDataSourceLookupTests { +class BeanFactoryDataSourceLookupTests { private static final String DATASOURCE_BEAN_NAME = "dataSource"; @Test - public void testLookupSunnyDay() { + void testLookupSunnyDay() { BeanFactory beanFactory = mock(); StubDataSource expectedDataSource = new StubDataSource(); @@ -55,7 +55,7 @@ public void testLookupSunnyDay() { } @Test - public void testLookupWhereBeanFactoryYieldsNonDataSourceType() throws Exception { + void testLookupWhereBeanFactoryYieldsNonDataSourceType() { final BeanFactory beanFactory = mock(); given(beanFactory.getBean(DATASOURCE_BEAN_NAME, DataSource.class)).willThrow( @@ -68,7 +68,7 @@ public void testLookupWhereBeanFactoryYieldsNonDataSourceType() throws Exception } @Test - public void testLookupWhereBeanFactoryHasNotBeenSupplied() throws Exception { + void testLookupWhereBeanFactoryHasNotBeenSupplied() { BeanFactoryDataSourceLookup lookup = new BeanFactoryDataSourceLookup(); assertThatIllegalStateException().isThrownBy(() -> lookup.getDataSource(DATASOURCE_BEAN_NAME)); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/JndiDataSourceLookupTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/JndiDataSourceLookupTests.java index 741a100de1b9..0399c4167cf0 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/JndiDataSourceLookupTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/JndiDataSourceLookupTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,12 +28,12 @@ * @author Rick Evans * @author Chris Beams */ -public class JndiDataSourceLookupTests { +class JndiDataSourceLookupTests { private static final String DATA_SOURCE_NAME = "Love is like a stove, burns you when it's hot"; @Test - public void testSunnyDay() throws Exception { + void testSunnyDay() { final DataSource expectedDataSource = new StubDataSource(); JndiDataSourceLookup lookup = new JndiDataSourceLookup() { @Override @@ -48,7 +48,7 @@ protected T lookup(String jndiName, Class requiredType) { } @Test - public void testNoDataSourceAtJndiLocation() throws Exception { + void testNoDataSourceAtJndiLocation() { JndiDataSourceLookup lookup = new JndiDataSourceLookup() { @Override protected T lookup(String jndiName, Class requiredType) throws NamingException { diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/MapDataSourceLookupTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/MapDataSourceLookupTests.java index 6259c89e8e6c..9071c399a3cf 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/MapDataSourceLookupTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/MapDataSourceLookupTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,14 +30,14 @@ * @author Rick Evans * @author Chris Beams */ -public class MapDataSourceLookupTests { +class MapDataSourceLookupTests { private static final String DATA_SOURCE_NAME = "dataSource"; @Test @SuppressWarnings({ "unchecked", "rawtypes" }) - public void getDataSourcesReturnsUnmodifiableMap() throws Exception { + public void getDataSourcesReturnsUnmodifiableMap() { MapDataSourceLookup lookup = new MapDataSourceLookup(); Map dataSources = lookup.getDataSources(); @@ -46,7 +46,7 @@ public void getDataSourcesReturnsUnmodifiableMap() throws Exception { } @Test - public void lookupSunnyDay() throws Exception { + void lookupSunnyDay() { Map dataSources = new HashMap<>(); StubDataSource expectedDataSource = new StubDataSource(); dataSources.put(DATA_SOURCE_NAME, expectedDataSource); @@ -58,7 +58,7 @@ public void lookupSunnyDay() throws Exception { } @Test - public void setDataSourcesIsAnIdempotentOperation() throws Exception { + void setDataSourcesIsAnIdempotentOperation() { Map dataSources = new HashMap<>(); StubDataSource expectedDataSource = new StubDataSource(); dataSources.put(DATA_SOURCE_NAME, expectedDataSource); @@ -71,7 +71,7 @@ public void setDataSourcesIsAnIdempotentOperation() throws Exception { } @Test - public void addingDataSourcePermitsOverride() throws Exception { + void addingDataSourcePermitsOverride() { Map dataSources = new HashMap<>(); StubDataSource overriddenDataSource = new StubDataSource(); StubDataSource expectedDataSource = new StubDataSource(); @@ -86,7 +86,7 @@ public void addingDataSourcePermitsOverride() throws Exception { @Test @SuppressWarnings({ "unchecked", "rawtypes" }) - public void getDataSourceWhereSuppliedMapHasNonDataSourceTypeUnderSpecifiedKey() throws Exception { + public void getDataSourceWhereSuppliedMapHasNonDataSourceTypeUnderSpecifiedKey() { Map dataSources = new HashMap(); dataSources.put(DATA_SOURCE_NAME, new Object()); MapDataSourceLookup lookup = new MapDataSourceLookup(dataSources); @@ -96,7 +96,7 @@ public void getDataSourceWhereSuppliedMapHasNonDataSourceTypeUnderSpecifiedKey() } @Test - public void getDataSourceWhereSuppliedMapHasNoEntryForSpecifiedKey() throws Exception { + void getDataSourceWhereSuppliedMapHasNoEntryForSpecifiedKey() { MapDataSourceLookup lookup = new MapDataSourceLookup(); assertThatExceptionOfType(DataSourceLookupFailureException.class).isThrownBy(() -> diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/StubDataSource.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/StubDataSource.java index 9db40f285ef6..977bc0288f69 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/StubDataSource.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/StubDataSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.jdbc.datasource.lookup; import java.sql.Connection; -import java.sql.SQLException; import org.springframework.jdbc.datasource.AbstractDataSource; @@ -31,12 +30,12 @@ class StubDataSource extends AbstractDataSource { @Override - public Connection getConnection() throws SQLException { + public Connection getConnection() { throw new UnsupportedOperationException(); } @Override - public Connection getConnection(String username, String password) throws SQLException { + public Connection getConnection(String username, String password) { throw new UnsupportedOperationException(); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/object/BatchSqlUpdateTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/object/BatchSqlUpdateTests.java index 8c9d0dae935b..45b564da7813 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/object/BatchSqlUpdateTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/object/BatchSqlUpdateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,15 +37,15 @@ * @author Juergen Hoeller * @since 22.02.2005 */ -public class BatchSqlUpdateTests { +class BatchSqlUpdateTests { @Test - public void testBatchUpdateWithExplicitFlush() throws Exception { + void testBatchUpdateWithExplicitFlush() throws Exception { doTestBatchUpdate(false); } @Test - public void testBatchUpdateWithFlushThroughBatchSize() throws Exception { + void testBatchUpdateWithFlushThroughBatchSize() throws Exception { doTestBatchUpdate(true); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java index e91c465fe157..b220c7876377 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ * @author Thomas Risberg * @author Juergen Hoeller */ -public class GenericSqlQueryTests { +class GenericSqlQueryTests { private static final String SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED = "select id, forename from custmr where id = ? and country = ?"; @@ -61,7 +61,7 @@ public class GenericSqlQueryTests { @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions( new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml")); DataSource dataSource = mock(); @@ -71,19 +71,19 @@ public void setUp() throws Exception { } @Test - public void testCustomerQueryWithPlaceholders() throws SQLException { + void testCustomerQueryWithPlaceholders() throws SQLException { SqlQuery query = (SqlQuery) beanFactory.getBean("queryWithPlaceholders"); doTestCustomerQuery(query, false); } @Test - public void testCustomerQueryWithNamedParameters() throws SQLException { + void testCustomerQueryWithNamedParameters() throws SQLException { SqlQuery query = (SqlQuery) beanFactory.getBean("queryWithNamedParameters"); doTestCustomerQuery(query, true); } @Test - public void testCustomerQueryWithRowMapperInstance() throws SQLException { + void testCustomerQueryWithRowMapperInstance() throws SQLException { SqlQuery query = (SqlQuery) beanFactory.getBean("queryWithRowMapperBean"); doTestCustomerQuery(query, true); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericStoredProcedureTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericStoredProcedureTests.java index 3737b0312a04..1bf2ef72ed70 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericStoredProcedureTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericStoredProcedureTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,10 +38,10 @@ /** * @author Thomas Risberg */ -public class GenericStoredProcedureTests { +class GenericStoredProcedureTests { @Test - public void testAddInvoices() throws Exception { + void testAddInvoices() throws Exception { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions( new ClassPathResource("org/springframework/jdbc/object/GenericStoredProcedureTests-context.xml")); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/object/RdbmsOperationTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/object/RdbmsOperationTests.java index ef6b09019257..b723f48d0583 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/object/RdbmsOperationTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/object/RdbmsOperationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,19 +39,19 @@ * @author Juergen Hoeller * @author Sam Brannen */ -public class RdbmsOperationTests { +class RdbmsOperationTests { private final TestRdbmsOperation operation = new TestRdbmsOperation(); @Test - public void emptySql() { + void emptySql() { assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy( operation::compile); } @Test - public void setTypeAfterCompile() { + void setTypeAfterCompile() { operation.setDataSource(new DriverManagerDataSource()); operation.setSql("select * from mytable"); operation.compile(); @@ -60,7 +60,7 @@ public void setTypeAfterCompile() { } @Test - public void declareParameterAfterCompile() { + void declareParameterAfterCompile() { operation.setDataSource(new DriverManagerDataSource()); operation.setSql("select * from mytable"); operation.compile(); @@ -69,39 +69,38 @@ public void declareParameterAfterCompile() { } @Test - public void tooFewParameters() { + void tooFewParameters() { operation.setSql("select * from mytable"); operation.setTypes(new int[] { Types.INTEGER }); assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> - operation.validateParameters((Object[]) null)); + operation.validateParameters(null)); } @Test - public void tooFewMapParameters() { + void tooFewMapParameters() { operation.setDataSource(new DriverManagerDataSource()); operation.setSql("select * from mytable"); operation.setTypes(new int[] { Types.INTEGER }); assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> - operation.validateNamedParameters((Map) null)); + operation.validateNamedParameters(null)); } @Test - public void operationConfiguredViaJdbcTemplateMustGetDataSource() { + void operationConfiguredViaJdbcTemplateMustGetDataSource() { operation.setSql("foo"); - assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> - operation.compile()) + assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(operation::compile) .withMessageContaining("'dataSource'"); } @Test - public void tooManyParameters() { + void tooManyParameters() { operation.setDataSource(new DriverManagerDataSource()); operation.setSql("select * from mytable"); assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> operation.validateParameters(new Object[] { 1, 2 })); } @Test - public void tooManyMapParameters() { + void tooManyMapParameters() { operation.setDataSource(new DriverManagerDataSource()); operation.setSql("select * from mytable"); assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> @@ -109,7 +108,7 @@ public void tooManyMapParameters() { } @Test - public void unspecifiedMapParameters() { + void unspecifiedMapParameters() { operation.setDataSource(new DriverManagerDataSource()); operation.setSql("select * from mytable"); Map params = new HashMap<>(); @@ -119,7 +118,7 @@ public void unspecifiedMapParameters() { } @Test - public void compileTwice() { + void compileTwice() { operation.setDataSource(new DriverManagerDataSource()); operation.setSql("select * from mytable"); operation.setTypes(null); @@ -128,7 +127,7 @@ public void compileTwice() { } @Test - public void emptyDataSource() { + void emptyDataSource() { SqlOperation operation = new SqlOperation() {}; operation.setSql("select * from mytable"); assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy( @@ -136,7 +135,7 @@ public void emptyDataSource() { } @Test - public void parameterPropagation() { + void parameterPropagation() { SqlOperation operation = new SqlOperation() {}; DataSource ds = new DriverManagerDataSource(); operation.setDataSource(ds); @@ -149,7 +148,7 @@ public void parameterPropagation() { } @Test - public void validateInOutParameter() { + void validateInOutParameter() { operation.setDataSource(new DriverManagerDataSource()); operation.setSql("DUMMY_PROC"); operation.declareParameter(new SqlOutParameter("DUMMY_OUT_PARAM", Types.VARCHAR)); @@ -158,13 +157,12 @@ public void validateInOutParameter() { } @Test - public void parametersSetWithList() { + void parametersSetWithList() { DataSource ds = new DriverManagerDataSource(); operation.setDataSource(ds); operation.setSql("select * from mytable where one = ? and two = ?"); - operation.setParameters(new SqlParameter[] { - new SqlParameter("one", Types.NUMERIC), - new SqlParameter("two", Types.NUMERIC)}); + operation.setParameters(new SqlParameter("one", Types.NUMERIC), + new SqlParameter("two", Types.NUMERIC)); operation.afterPropertiesSet(); operation.validateParameters(new Object[] { 1, "2" }); assertThat(operation.getDeclaredParameters()).hasSize(2); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java index 16e361e5734b..ac2d0f3c2533 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import java.sql.SQLException; import java.sql.Types; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -54,7 +53,7 @@ * @author Thomas Risberg * @author Juergen Hoeller */ -public class SqlQueryTests { +class SqlQueryTests { //FIXME inline? private static final String SELECT_ID = @@ -96,14 +95,14 @@ public class SqlQueryTests { @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { given(this.dataSource.getConnection()).willReturn(this.connection); given(this.connection.prepareStatement(anyString())).willReturn(this.preparedStatement); given(preparedStatement.executeQuery()).willReturn(resultSet); } @Test - public void testQueryWithoutParams() throws SQLException { + void testQueryWithoutParams() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(1); @@ -121,14 +120,14 @@ protected Integer mapRow(ResultSet rs, int rownum, @Nullable Object[] params, @N query.compile(); List list = query.execute(); - assertThat(list).isEqualTo(Arrays.asList(1)); + assertThat(list).containsExactly(1); verify(connection).prepareStatement(SELECT_ID); verify(resultSet).close(); verify(preparedStatement).close(); } @Test - public void testQueryWithoutEnoughParams() { + void testQueryWithoutEnoughParams() { MappingSqlQuery query = new MappingSqlQuery<>() { @Override protected Integer mapRow(ResultSet rs, int rownum) throws SQLException { @@ -146,7 +145,7 @@ protected Integer mapRow(ResultSet rs, int rownum) throws SQLException { } @Test - public void testQueryWithMissingMapParams() { + void testQueryWithMissingMapParams() { MappingSqlQuery query = new MappingSqlQuery<>() { @Override protected Integer mapRow(ResultSet rs, int rownum) throws SQLException { @@ -164,7 +163,7 @@ protected Integer mapRow(ResultSet rs, int rownum) throws SQLException { } @Test - public void testStringQueryWithResults() throws Exception { + void testStringQueryWithResults() throws Exception { String[] dbResults = new String[] { "alpha", "beta", "charlie" }; given(resultSet.next()).willReturn(true, true, true, false); given(resultSet.getString(1)).willReturn(dbResults[0], dbResults[1], dbResults[2]); @@ -179,7 +178,7 @@ public void testStringQueryWithResults() throws Exception { } @Test - public void testStringQueryWithoutResults() throws SQLException { + void testStringQueryWithoutResults() throws SQLException { given(resultSet.next()).willReturn(false); StringQuery query = new StringQuery(dataSource, SELECT_FORENAME_EMPTY); String[] results = query.run(); @@ -191,7 +190,7 @@ public void testStringQueryWithoutResults() throws SQLException { } @Test - public void testFindCustomerIntInt() throws SQLException { + void testFindCustomerIntInt() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -232,7 +231,7 @@ public Customer findCustomer(int id, int otherNum) { } @Test - public void testFindCustomerString() throws SQLException { + void testFindCustomerString() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -271,7 +270,7 @@ public Customer findCustomer(String id) { } @Test - public void testFindCustomerMixed() throws SQLException { + void testFindCustomerMixed() throws SQLException { reset(connection); PreparedStatement preparedStatement2 = mock(); ResultSet resultSet2 = mock(); @@ -300,7 +299,7 @@ protected Customer mapRow(ResultSet rs, int rownum) throws SQLException { } public Customer findCustomer(int id, String name) { - return findObject(new Object[] { id, name }); + return findObject(id, name); } } @@ -325,7 +324,7 @@ public Customer findCustomer(int id, String name) { } @Test - public void testFindTooManyCustomers() throws SQLException { + void testFindTooManyCustomers() throws SQLException { given(resultSet.next()).willReturn(true, true, false); given(resultSet.getInt("id")).willReturn(1, 2); given(resultSet.getString("forename")).willReturn("rod", "rod"); @@ -362,7 +361,7 @@ public Customer findCustomer(String id) { } @Test - public void testListCustomersIntInt() throws SQLException { + void testListCustomersIntInt() throws SQLException { given(resultSet.next()).willReturn(true, true, false); given(resultSet.getInt("id")).willReturn(1, 2); given(resultSet.getString("forename")).willReturn("rod", "dave"); @@ -399,7 +398,7 @@ protected Customer mapRow(ResultSet rs, int rownum) throws SQLException { } @Test - public void testListCustomersString() throws SQLException { + void testListCustomersString() throws SQLException { given(resultSet.next()).willReturn(true, true, false); given(resultSet.getInt("id")).willReturn(1, 2); given(resultSet.getString("forename")).willReturn("rod", "dave"); @@ -434,7 +433,7 @@ protected Customer mapRow(ResultSet rs, int rownum) throws SQLException { } @Test - public void testFancyCustomerQuery() throws SQLException { + void testFancyCustomerQuery() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); @@ -476,8 +475,7 @@ public Customer findCustomer(int id) { } @Test - public void testUnnamedParameterDeclarationWithNamedParameterQuery() - throws SQLException { + void testUnnamedParameterDeclarationWithNamedParameterQuery() { class CustomerQuery extends MappingSqlQuery { public CustomerQuery(DataSource ds) { @@ -509,13 +507,13 @@ public Customer findCustomer(int id) { } @Test - public void testNamedParameterCustomerQueryWithUnnamedDeclarations() + void testNamedParameterCustomerQueryWithUnnamedDeclarations() throws SQLException { doTestNamedParameterCustomerQuery(false); } @Test - public void testNamedParameterCustomerQueryWithNamedDeclarations() + void testNamedParameterCustomerQueryWithNamedDeclarations() throws SQLException { doTestNamedParameterCustomerQuery(true); } @@ -573,7 +571,7 @@ public Customer findCustomer(int id, String country) { } @Test - public void testNamedParameterInListQuery() throws SQLException { + void testNamedParameterInListQuery() throws SQLException { given(resultSet.next()).willReturn(true, true, false); given(resultSet.getInt("id")).willReturn(1, 2); given(resultSet.getString("forename")).willReturn("rod", "juergen"); @@ -626,7 +624,7 @@ public List findCustomers(List ids) { } @Test - public void testNamedParameterQueryReusingParameter() throws SQLException { + void testNamedParameterQueryReusingParameter() throws SQLException { given(resultSet.next()).willReturn(true, true, false); given(resultSet.getInt("id")).willReturn(1, 2); given(resultSet.getString("forename")).willReturn("rod", "juergen"); @@ -677,7 +675,7 @@ public List findCustomers(Integer id) { } @Test - public void testNamedParameterUsingInvalidQuestionMarkPlaceHolders() + void testNamedParameterUsingInvalidQuestionMarkPlaceHolders() throws SQLException { given( connection.prepareStatement(SELECT_ID_FORENAME_WHERE_ID_REUSED_1, @@ -713,7 +711,7 @@ public List findCustomers(Integer id1) { } @Test - public void testUpdateCustomers() throws SQLException { + void testUpdateCustomers() throws SQLException { given(resultSet.next()).willReturn(true, true, false); given(resultSet.getInt("id")).willReturn(1, 2); given(connection.prepareStatement(SELECT_ID_FORENAME_WHERE_ID, diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlUpdateTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlUpdateTests.java index 2904dec41391..41ccaadcecd6 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlUpdateTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlUpdateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ * @author Thomas Risberg * @author Juergen Hoeller */ -public class SqlUpdateTests { +class SqlUpdateTests { private static final String UPDATE = "update seat_status set booking_id = null"; @@ -83,19 +83,19 @@ public class SqlUpdateTests { @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { given(dataSource.getConnection()).willReturn(connection); } @AfterEach - public void verifyClosed() throws Exception { + void verifyClosed() throws Exception { verify(preparedStatement).close(); verify(connection).close(); } @Test - public void testUpdate() throws SQLException { + void testUpdate() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); given(connection.prepareStatement(UPDATE)).willReturn(preparedStatement); @@ -106,7 +106,7 @@ public void testUpdate() throws SQLException { } @Test - public void testUpdateInt() throws SQLException { + void testUpdateInt() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); given(connection.prepareStatement(UPDATE_INT)).willReturn(preparedStatement); @@ -118,7 +118,7 @@ public void testUpdateInt() throws SQLException { } @Test - public void testUpdateIntInt() throws SQLException { + void testUpdateIntInt() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); given(connection.prepareStatement(UPDATE_INT_INT)).willReturn(preparedStatement); @@ -131,12 +131,12 @@ public void testUpdateIntInt() throws SQLException { } @Test - public void testNamedParameterUpdateWithUnnamedDeclarations() throws SQLException { + void testNamedParameterUpdateWithUnnamedDeclarations() throws SQLException { doTestNamedParameterUpdate(false); } @Test - public void testNamedParameterUpdateWithNamedDeclarations() throws SQLException { + void testNamedParameterUpdateWithNamedDeclarations() throws SQLException { doTestNamedParameterUpdate(true); } @@ -176,7 +176,7 @@ public int run(int performanceId, int type) { } @Test - public void testUpdateString() throws SQLException { + void testUpdateString() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); given(connection.prepareStatement(UPDATE_STRING)).willReturn(preparedStatement); @@ -188,7 +188,7 @@ public void testUpdateString() throws SQLException { } @Test - public void testUpdateMixed() throws SQLException { + void testUpdateMixed() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); given(connection.prepareStatement(UPDATE_OBJECTS)).willReturn(preparedStatement); @@ -203,7 +203,7 @@ public void testUpdateMixed() throws SQLException { } @Test - public void testUpdateAndGeneratedKeys() throws SQLException { + void testUpdateAndGeneratedKeys() throws SQLException { given(resultSetMetaData.getColumnCount()).willReturn(1); given(resultSetMetaData.getColumnLabel(1)).willReturn("1"); given(resultSet.getMetaData()).willReturn(resultSetMetaData); @@ -226,7 +226,7 @@ public void testUpdateAndGeneratedKeys() throws SQLException { } @Test - public void testUpdateConstructor() throws SQLException { + void testUpdateConstructor() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(1); given(connection.prepareStatement(UPDATE_OBJECTS)).willReturn(preparedStatement); ConstructorUpdater pc = new ConstructorUpdater(); @@ -241,7 +241,7 @@ public void testUpdateConstructor() throws SQLException { } @Test - public void testUnderMaxRows() throws SQLException { + void testUnderMaxRows() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(3); given(connection.prepareStatement(UPDATE)).willReturn(preparedStatement); @@ -252,7 +252,7 @@ public void testUnderMaxRows() throws SQLException { } @Test - public void testMaxRows() throws SQLException { + void testMaxRows() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(5); given(connection.prepareStatement(UPDATE)).willReturn(preparedStatement); @@ -263,7 +263,7 @@ public void testMaxRows() throws SQLException { } @Test - public void testOverMaxRows() throws SQLException { + void testOverMaxRows() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(8); given(connection.prepareStatement(UPDATE)).willReturn(preparedStatement); @@ -274,7 +274,7 @@ public void testOverMaxRows() throws SQLException { } @Test - public void testRequiredRows() throws SQLException { + void testRequiredRows() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(3); given(connection.prepareStatement(UPDATE)).willReturn(preparedStatement); @@ -285,7 +285,7 @@ public void testRequiredRows() throws SQLException { } @Test - public void testNotRequiredRows() throws SQLException { + void testNotRequiredRows() throws SQLException { given(preparedStatement.executeUpdate()).willReturn(2); given(connection.prepareStatement(UPDATE)).willReturn(preparedStatement); RequiredRowsUpdater pc = new RequiredRowsUpdater(); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/object/StoredProcedureTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/object/StoredProcedureTests.java index d131d8bf942f..2dff18b8eb01 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/object/StoredProcedureTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/object/StoredProcedureTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,7 +64,7 @@ * @author Trevor Cook * @author Rod Johnson */ -public class StoredProcedureTests { +class StoredProcedureTests { private Connection connection = mock(); @@ -76,13 +76,13 @@ public class StoredProcedureTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { given(dataSource.getConnection()).willReturn(connection); given(callableStatement.getConnection()).willReturn(connection); } @AfterEach - public void verifyClosed() throws Exception { + void verifyClosed() throws Exception { if (verifyClosedAfter) { verify(callableStatement).close(); verify(connection, atLeastOnce()).close(); @@ -90,7 +90,7 @@ public void verifyClosed() throws Exception { } @Test - public void testNoSuchStoredProcedure() throws Exception { + void testNoSuchStoredProcedure() throws Exception { SQLException sqlException = new SQLException( "Syntax error or access violation exception", "42000"); given(callableStatement.execute()).willThrow(sqlException); @@ -102,21 +102,20 @@ public void testNoSuchStoredProcedure() throws Exception { sproc::execute); } - private void testAddInvoice(final int amount, final int custid) throws Exception { + private void testAddInvoice(final int amount, final int custid) { AddInvoice adder = new AddInvoice(dataSource); int id = adder.execute(amount, custid); assertThat(id).isEqualTo(4); } - private void testAddInvoiceUsingObjectArray(final int amount, final int custid) - throws Exception { + private void testAddInvoiceUsingObjectArray(final int amount, final int custid) { AddInvoiceUsingObjectArray adder = new AddInvoiceUsingObjectArray(dataSource); int id = adder.execute(amount, custid); assertThat(id).isEqualTo(5); } @Test - public void testAddInvoices() throws Exception { + void testAddInvoices() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(3)).willReturn(4); @@ -129,7 +128,7 @@ public void testAddInvoices() throws Exception { } @Test - public void testAddInvoicesUsingObjectArray() throws Exception { + void testAddInvoicesUsingObjectArray() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(3)).willReturn(5); @@ -142,7 +141,7 @@ public void testAddInvoicesUsingObjectArray() throws Exception { } @Test - public void testAddInvoicesWithinTransaction() throws Exception { + void testAddInvoicesWithinTransaction() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(3)).willReturn(4); @@ -166,7 +165,7 @@ public void testAddInvoicesWithinTransaction() throws Exception { * mechanism. */ @Test - public void testStoredProcedureConfiguredViaJdbcTemplateWithCustomExceptionTranslator() + void testStoredProcedureConfiguredViaJdbcTemplateWithCustomExceptionTranslator() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); @@ -202,7 +201,7 @@ public Map call(CallableStatementCreator csc, * Confirm our JdbcTemplate is used */ @Test - public void testStoredProcedureConfiguredViaJdbcTemplate() throws Exception { + void testStoredProcedureConfiguredViaJdbcTemplate() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(2)).willReturn(4); @@ -216,7 +215,7 @@ public void testStoredProcedureConfiguredViaJdbcTemplate() throws Exception { } @Test - public void testNullArg() throws Exception { + void testNullArg() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(connection.prepareCall("{call " + NullArg.SQL + "(?)}")).willReturn(callableStatement); @@ -226,7 +225,7 @@ public void testNullArg() throws Exception { } @Test - public void testUnnamedParameter() throws Exception { + void testUnnamedParameter() { this.verifyClosedAfter = false; // Shouldn't succeed in creating stored procedure with unnamed parameter assertThatExceptionOfType(InvalidDataAccessApiUsageException.class) @@ -234,14 +233,14 @@ public void testUnnamedParameter() throws Exception { } @Test - public void testMissingParameter() throws Exception { + void testMissingParameter() { this.verifyClosedAfter = false; MissingParameterStoredProcedure mp = new MissingParameterStoredProcedure(dataSource); assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(mp::execute); } @Test - public void testStoredProcedureExceptionTranslator() throws Exception { + void testStoredProcedureExceptionTranslator() throws Exception { SQLException sqlException = new SQLException("Syntax error or access violation exception", "42000"); given(callableStatement.execute()).willThrow(sqlException); given(connection.prepareCall("{call " + StoredProcedureExceptionTranslator.SQL + "()}")).willReturn(callableStatement); @@ -250,7 +249,7 @@ public void testStoredProcedureExceptionTranslator() throws Exception { } @Test - public void testStoredProcedureWithResultSet() throws Exception { + void testStoredProcedureWithResultSet() throws Exception { ResultSet resultSet = mock(); given(resultSet.next()).willReturn(true, true, false); given(callableStatement.execute()).willReturn(true); @@ -331,7 +330,7 @@ public void testStoredProcedureWithUndeclaredResults() throws Exception { } @Test - public void testStoredProcedureSkippingResultsProcessing() throws Exception { + void testStoredProcedureSkippingResultsProcessing() throws Exception { given(callableStatement.execute()).willReturn(true); given(callableStatement.getUpdateCount()).willReturn(-1); given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}")).willReturn(callableStatement); @@ -362,14 +361,12 @@ public void testStoredProcedureSkippingUndeclaredResults() throws Exception { assertThat(res.size()).as("incorrect number of returns").isEqualTo(1); List rs1 = (List) res.get("rs"); - assertThat(rs1).hasSize(2); - assertThat(rs1).element(0).isEqualTo("Foo"); - assertThat(rs1).element(1).isEqualTo("Bar"); + assertThat(rs1).containsExactly("Foo", "Bar"); verify(resultSet).close(); } @Test - public void testParameterMapper() throws Exception { + void testParameterMapper() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(2)).willReturn("OK"); @@ -384,7 +381,7 @@ public void testParameterMapper() throws Exception { } @Test - public void testSqlTypeValue() throws Exception { + void testSqlTypeValue() throws Exception { int[] testVal = new int[] { 1, 2 }; given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); @@ -399,7 +396,7 @@ public void testSqlTypeValue() throws Exception { } @Test - public void testNumericWithScale() throws Exception { + void testNumericWithScale() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(1)).willReturn(new BigDecimal("12345.6789")); @@ -603,7 +600,7 @@ private TestParameterMapper() { } @Override - public Map createMap(Connection con) throws SQLException { + public Map createMap(Connection con) { Map inParms = new HashMap<>(); String testValue = con.toString(); inParms.put("in", testValue); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistrarTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistrarTests.java index 4eb3947f5091..091c19a77fae 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistrarTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistrarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,10 +32,9 @@ * * @author Thomas Risberg */ -public class CustomSQLExceptionTranslatorRegistrarTests { +class CustomSQLExceptionTranslatorRegistrarTests { @Test - @SuppressWarnings("resource") public void customErrorCodeTranslation() { new ClassPathXmlApplicationContext("test-custom-translators-context.xml", CustomSQLExceptionTranslatorRegistrarTests.class); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/DefaultLobHandlerTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/DefaultLobHandlerTests.java index 550a9c07afe2..06a5facbfe3a 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/DefaultLobHandlerTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/DefaultLobHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.jdbc.support; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.io.StringReader; @@ -38,7 +37,7 @@ * @author Juergen Hoeller * @since 17.12.2003 */ -public class DefaultLobHandlerTests { +class DefaultLobHandlerTests { private ResultSet rs = mock(); @@ -50,86 +49,86 @@ public class DefaultLobHandlerTests { @Test - public void testGetBlobAsBytes() throws SQLException { + void testGetBlobAsBytes() throws SQLException { lobHandler.getBlobAsBytes(rs, 1); verify(rs).getBytes(1); } @Test - public void testGetBlobAsBinaryStream() throws SQLException { + void testGetBlobAsBinaryStream() throws SQLException { lobHandler.getBlobAsBinaryStream(rs, 1); verify(rs).getBinaryStream(1); } @Test - public void testGetClobAsString() throws SQLException { + void testGetClobAsString() throws SQLException { lobHandler.getClobAsString(rs, 1); verify(rs).getString(1); } @Test - public void testGetClobAsAsciiStream() throws SQLException { + void testGetClobAsAsciiStream() throws SQLException { lobHandler.getClobAsAsciiStream(rs, 1); verify(rs).getAsciiStream(1); } @Test - public void testGetClobAsCharacterStream() throws SQLException { + void testGetClobAsCharacterStream() throws SQLException { lobHandler.getClobAsCharacterStream(rs, 1); verify(rs).getCharacterStream(1); } @Test - public void testSetBlobAsBytes() throws SQLException { + void testSetBlobAsBytes() throws SQLException { byte[] content = "testContent".getBytes(); lobCreator.setBlobAsBytes(ps, 1, content); verify(ps).setBytes(1, content); } @Test - public void testSetBlobAsBinaryStream() throws SQLException, IOException { + void testSetBlobAsBinaryStream() throws SQLException { InputStream bis = new ByteArrayInputStream("testContent".getBytes()); lobCreator.setBlobAsBinaryStream(ps, 1, bis, 11); verify(ps).setBinaryStream(1, bis, 11); } @Test - public void testSetBlobAsBinaryStreamWithoutLength() throws SQLException, IOException { + void testSetBlobAsBinaryStreamWithoutLength() throws SQLException { InputStream bis = new ByteArrayInputStream("testContent".getBytes()); lobCreator.setBlobAsBinaryStream(ps, 1, bis, -1); verify(ps).setBinaryStream(1, bis); } @Test - public void testSetClobAsString() throws SQLException, IOException { + void testSetClobAsString() throws SQLException { String content = "testContent"; lobCreator.setClobAsString(ps, 1, content); verify(ps).setString(1, content); } @Test - public void testSetClobAsAsciiStream() throws SQLException, IOException { + void testSetClobAsAsciiStream() throws SQLException { InputStream bis = new ByteArrayInputStream("testContent".getBytes()); lobCreator.setClobAsAsciiStream(ps, 1, bis, 11); verify(ps).setAsciiStream(1, bis, 11); } @Test - public void testSetClobAsAsciiStreamWithoutLength() throws SQLException, IOException { + void testSetClobAsAsciiStreamWithoutLength() throws SQLException { InputStream bis = new ByteArrayInputStream("testContent".getBytes()); lobCreator.setClobAsAsciiStream(ps, 1, bis, -1); verify(ps).setAsciiStream(1, bis); } @Test - public void testSetClobAsCharacterStream() throws SQLException, IOException { + void testSetClobAsCharacterStream() throws SQLException { Reader str = new StringReader("testContent"); lobCreator.setClobAsCharacterStream(ps, 1, str, 11); verify(ps).setCharacterStream(1, str, 11); } @Test - public void testSetClobAsCharacterStreamWithoutLength() throws SQLException, IOException { + void testSetClobAsCharacterStreamWithoutLength() throws SQLException { Reader str = new StringReader("testContent"); lobCreator.setClobAsCharacterStream(ps, 1, str, -1); verify(ps).setCharacterStream(1, str); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcTransactionManagerTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcTransactionManagerTests.java index c9950596d70b..9f766ec70d8b 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcTransactionManagerTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcTransactionManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ * @since 5.3 * @see org.springframework.jdbc.datasource.DataSourceTransactionManagerTests */ -public class JdbcTransactionManagerTests extends DataSourceTransactionManagerTests { +class JdbcTransactionManagerTests extends DataSourceTransactionManagerTests { @Override protected JdbcTransactionManager createTransactionManager(DataSource ds) { @@ -53,7 +53,7 @@ protected JdbcTransactionManager createTransactionManager(DataSource ds) { @Override @Test - public void testTransactionWithExceptionOnCommit() throws Exception { + protected void testTransactionWithExceptionOnCommit() throws Exception { willThrow(new SQLException("Cannot commit")).given(con).commit(); TransactionTemplate tt = new TransactionTemplate(tm); @@ -71,7 +71,7 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } @Test - public void testTransactionWithDataAccessExceptionOnCommit() throws Exception { + void testTransactionWithDataAccessExceptionOnCommit() throws Exception { willThrow(new SQLException("Cannot commit")).given(con).commit(); ((JdbcTransactionManager) tm).setExceptionTranslator((task, sql, ex) -> new ConcurrencyFailureException(task)); TransactionTemplate tt = new TransactionTemplate(tm); @@ -90,7 +90,7 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } @Test - public void testTransactionWithDataAccessExceptionOnCommitFromLazyExceptionTranslator() throws Exception { + void testTransactionWithDataAccessExceptionOnCommitFromLazyExceptionTranslator() throws Exception { willThrow(new SQLException("Cannot commit", "40")).given(con).commit(); TransactionTemplate tt = new TransactionTemplate(tm); @@ -109,7 +109,7 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { @Override @Test - public void testTransactionWithExceptionOnCommitAndRollbackOnCommitFailure() throws Exception { + protected void testTransactionWithExceptionOnCommitAndRollbackOnCommitFailure() throws Exception { willThrow(new SQLException("Cannot commit")).given(con).commit(); tm.setRollbackOnCommitFailure(true); @@ -131,7 +131,7 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { @Override @Test - public void testTransactionWithExceptionOnRollback() throws Exception { + protected void testTransactionWithExceptionOnRollback() throws Exception { given(con.getAutoCommit()).willReturn(true); willThrow(new SQLException("Cannot rollback")).given(con).rollback(); TransactionTemplate tt = new TransactionTemplate(tm); @@ -163,7 +163,7 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run } @Test - public void testTransactionWithDataAccessExceptionOnRollback() throws Exception { + void testTransactionWithDataAccessExceptionOnRollback() throws Exception { given(con.getAutoCommit()).willReturn(true); willThrow(new SQLException("Cannot rollback")).given(con).rollback(); ((JdbcTransactionManager) tm).setExceptionTranslator((task, sql, ex) -> new ConcurrencyFailureException(task)); @@ -187,7 +187,7 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run } @Test - public void testTransactionWithDataAccessExceptionOnRollbackFromLazyExceptionTranslator() throws Exception { + void testTransactionWithDataAccessExceptionOnRollbackFromLazyExceptionTranslator() throws Exception { given(con.getAutoCommit()).willReturn(true); willThrow(new SQLException("Cannot rollback", "40")).given(con).rollback(); TransactionTemplate tt = new TransactionTemplate(tm); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcUtilsTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcUtilsTests.java index 7b7c3c10c528..83472cbd02e7 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcUtilsTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,10 +29,10 @@ * @author Juergen Hoeller * @author Ben Blinebury */ -public class JdbcUtilsTests { +class JdbcUtilsTests { @Test - public void commonDatabaseName() { + void commonDatabaseName() { assertThat(JdbcUtils.commonDatabaseName("Oracle")).isEqualTo("Oracle"); assertThat(JdbcUtils.commonDatabaseName("DB2-for-Spring")).isEqualTo("DB2"); assertThat(JdbcUtils.commonDatabaseName("Sybase SQL Server")).isEqualTo("Sybase"); @@ -42,7 +42,7 @@ public void commonDatabaseName() { } @Test - public void resolveTypeName() { + void resolveTypeName() { assertThat(JdbcUtils.resolveTypeName(Types.VARCHAR)).isEqualTo("VARCHAR"); assertThat(JdbcUtils.resolveTypeName(Types.NUMERIC)).isEqualTo("NUMERIC"); assertThat(JdbcUtils.resolveTypeName(Types.INTEGER)).isEqualTo("INTEGER"); @@ -50,7 +50,7 @@ public void resolveTypeName() { } @Test - public void convertUnderscoreNameToPropertyName() { + void convertUnderscoreNameToPropertyName() { assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("MY_NAME")).isEqualTo("myName"); assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("yOUR_nAME")).isEqualTo("yourName"); assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("a_name")).isEqualTo("AName"); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/KeyHolderTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/KeyHolderTests.java index d77f57c7f341..dc7b26d5c225 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/KeyHolderTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/KeyHolderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ void getKeyForSingleNonNumericKey() { kh.getKeyList().add(singletonMap("key", "ABC")); assertThatExceptionOfType(DataRetrievalFailureException.class) - .isThrownBy(() -> kh.getKey()) + .isThrownBy(kh::getKey) .withMessage("The generated key type is not supported. Unable to cast [java.lang.String] to [java.lang.Number]."); } @@ -62,7 +62,7 @@ void getKeyWithNoKeysInMap() { kh.getKeyList().add(emptyMap()); assertThatExceptionOfType(DataRetrievalFailureException.class) - .isThrownBy(() -> kh.getKey()) + .isThrownBy(kh::getKey) .withMessageStartingWith("Unable to retrieve the generated key."); } @@ -72,7 +72,7 @@ void getKeyWithMultipleKeysInMap() { assertThat(kh.getKeys()).as("two keys should be in the map").hasSize(2); assertThatExceptionOfType(InvalidDataAccessApiUsageException.class) - .isThrownBy(() -> kh.getKey()) + .isThrownBy(kh::getKey) .withMessageStartingWith("The getKey method should only be used when a single key is returned."); } @@ -103,13 +103,12 @@ void getKeyAsIntegerWithNullValue() { @Test void getKeysWithMultipleKeyRows() { - @SuppressWarnings("serial") Map m = Map.of("key", 1, "seq", 2); kh.getKeyList().addAll(asList(m, m)); assertThat(kh.getKeyList()).as("two rows should be in the list").hasSize(2); assertThatExceptionOfType(InvalidDataAccessApiUsageException.class) - .isThrownBy(() -> kh.getKeys()) + .isThrownBy(kh::getKeys) .withMessageStartingWith("The getKeys method should only be used when keys for a single row are returned."); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLExceptionCustomTranslatorTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLExceptionCustomTranslatorTests.java index 1cd9abb5f5b8..fdf08d260598 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLExceptionCustomTranslatorTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLExceptionCustomTranslatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ * @author Thomas Risberg * @author Sam Brannen */ -public class SQLExceptionCustomTranslatorTests { +class SQLExceptionCustomTranslatorTests { private static SQLErrorCodes ERROR_CODES = new SQLErrorCodes(); @@ -47,7 +47,7 @@ public class SQLExceptionCustomTranslatorTests { @Test - public void badSqlGrammarException() { + void badSqlGrammarException() { SQLException badSqlGrammarExceptionEx = new SQLDataException("", "", 1); DataAccessException dae = sext.translate("task", "SQL", badSqlGrammarExceptionEx); assertThat(dae.getCause()).isEqualTo(badSqlGrammarExceptionEx); @@ -55,7 +55,7 @@ public void badSqlGrammarException() { } @Test - public void dataAccessResourceException() { + void dataAccessResourceException() { SQLException dataAccessResourceEx = new SQLDataException("", "", 2); DataAccessException dae = sext.translate("task", "SQL", dataAccessResourceEx); assertThat(dae.getCause()).isEqualTo(dataAccessResourceEx); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslatorTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslatorTests.java index ce2580431136..63f7f91830e1 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslatorTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,10 +49,10 @@ * @author Thomas Risberg * @author Juergen Hoeller */ -public class SQLExceptionSubclassTranslatorTests { +class SQLExceptionSubclassTranslatorTests { @Test - public void exceptionClassTranslation() { + void exceptionClassTranslation() { doTest(new SQLDataException("", "", 0), DataIntegrityViolationException.class); doTest(new SQLFeatureNotSupportedException("", "", 0), InvalidDataAccessApiUsageException.class); doTest(new SQLIntegrityConstraintViolationException("", "", 0), DataIntegrityViolationException.class); @@ -72,7 +72,7 @@ public void exceptionClassTranslation() { } @Test - public void fallbackStateTranslation() { + void fallbackStateTranslation() { // Test fallback. We assume that no database will ever return this error code, // but 07xxx will be bad grammar picked up by the fallback SQLState translator doTest(new SQLException("", "07xxx", 666666666), BadSqlGrammarException.class); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java index aad0c401fa3f..92318bc2531c 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,7 +69,7 @@ void incrementsSequenceUsingH2EmbeddedDatabaseConfigurer() { @ParameterizedTest @EnumSource(ModeEnum.class) void incrementsSequenceWithExplicitH2CompatibilityMode(ModeEnum mode) { - String connectionUrl = String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false;MODE=%s", UUID.randomUUID().toString(), mode); + String connectionUrl = String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false;MODE=%s", UUID.randomUUID(), mode); DataSource dataSource = new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", ""); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.execute("CREATE SEQUENCE SEQ"); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java index ae58fbf25c34..44823b0ff328 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/rowset/ResultSetWrappingRowSetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ /** * @author Thomas Risberg */ -public class ResultSetWrappingRowSetTests { +class ResultSetWrappingRowSetTests { private ResultSet resultSet = mock(); @@ -45,154 +45,154 @@ public class ResultSetWrappingRowSetTests { @Test - public void testGetBigDecimalInt() throws Exception { + void testGetBigDecimalInt() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", int.class); doTest(rset, rowset, 1, BigDecimal.ONE); } @Test - public void testGetBigDecimalString() throws Exception { + void testGetBigDecimalString() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", String.class); doTest(rset, rowset, "test", BigDecimal.ONE); } @Test - public void testGetStringInt() throws Exception { + void testGetStringInt() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getString", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", int.class); doTest(rset, rowset, 1, "test"); } @Test - public void testGetStringString() throws Exception { + void testGetStringString() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getString", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", String.class); doTest(rset, rowset, "test", "test"); } @Test - public void testGetTimestampInt() throws Exception { + void testGetTimestampInt() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", int.class); doTest(rset, rowset, 1, new Timestamp(1234L)); } @Test - public void testGetTimestampString() throws Exception { + void testGetTimestampString() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", String.class); doTest(rset, rowset, "test", new Timestamp(1234L)); } @Test - public void testGetDateInt() throws Exception { + void testGetDateInt() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getDate", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", int.class); doTest(rset, rowset, 1, new Date(1234L)); } @Test - public void testGetDateString() throws Exception { + void testGetDateString() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getDate", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", String.class); doTest(rset, rowset, "test", new Date(1234L)); } @Test - public void testGetTimeInt() throws Exception { + void testGetTimeInt() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getTime", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", int.class); doTest(rset, rowset, 1, new Time(1234L)); } @Test - public void testGetTimeString() throws Exception { + void testGetTimeString() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getTime", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", String.class); doTest(rset, rowset, "test", new Time(1234L)); } @Test - public void testGetObjectInt() throws Exception { + void testGetObjectInt() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getObject", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", int.class); doTest(rset, rowset, 1, new Object()); } @Test - public void testGetObjectString() throws Exception { + void testGetObjectString() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getObject", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", String.class); doTest(rset, rowset, "test", new Object()); } @Test - public void testGetIntInt() throws Exception { + void testGetIntInt() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getInt", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", int.class); doTest(rset, rowset, 1, 1); } @Test - public void testGetIntString() throws Exception { + void testGetIntString() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getInt", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", String.class); doTest(rset, rowset, "test", 1); } @Test - public void testGetFloatInt() throws Exception { + void testGetFloatInt() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getFloat", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", int.class); doTest(rset, rowset, 1, 1.0f); } @Test - public void testGetFloatString() throws Exception { + void testGetFloatString() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getFloat", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", String.class); doTest(rset, rowset, "test", 1.0f); } @Test - public void testGetDoubleInt() throws Exception { + void testGetDoubleInt() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getDouble", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", int.class); doTest(rset, rowset, 1, 1.0d); } @Test - public void testGetDoubleString() throws Exception { + void testGetDoubleString() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getDouble", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", String.class); doTest(rset, rowset, "test", 1.0d); } @Test - public void testGetLongInt() throws Exception { + void testGetLongInt() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getLong", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", int.class); doTest(rset, rowset, 1, 1L); } @Test - public void testGetLongString() throws Exception { + void testGetLongString() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getLong", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", String.class); doTest(rset, rowset, "test", 1L); } @Test - public void testGetBooleanInt() throws Exception { + void testGetBooleanInt() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getBoolean", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", int.class); doTest(rset, rowset, 1, true); } @Test - public void testGetBooleanString() throws Exception { + void testGetBooleanString() throws Exception { Method rset = ResultSet.class.getDeclaredMethod("getBoolean", int.class); Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", String.class); doTest(rset, rowset, "test", true);