From 00e1429378572446eda4c60e5ad6d456f7671ae9 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Thu, 30 Oct 2025 15:41:04 +0100 Subject: [PATCH] Polish SQLErrorCodeSQLExceptionTranslatorTests --- ...LErrorCodeSQLExceptionTranslatorTests.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java index 01926e0b359..1f02db5aca6 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java @@ -42,6 +42,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** + * Tests for {@link SQLErrorCodeSQLExceptionTranslator}. + * * @author Rod Johnson * @author Juergen Hoeller * @author Sam Brannen @@ -128,11 +130,11 @@ class SQLErrorCodeSQLExceptionTranslatorTests { @Test @SuppressWarnings("serial") void customTranslateMethodTranslation() { - final String TASK = "TASK"; - final String SQL = "SQL SELECT *"; - final DataAccessException customDex = new DataAccessException("") {}; + String TASK = "TASK"; + String SQL = "SQL SELECT *"; + DataAccessException customDex = new DataAccessException("") {}; - final SQLException badSqlEx = new SQLException("", "", 1); + SQLException badSqlEx = new SQLException("", "", 1); SQLException integrityViolationEx = new SQLException("", "", 6); translator = new SQLErrorCodeSQLExceptionTranslator() { @@ -150,18 +152,17 @@ class SQLErrorCodeSQLExceptionTranslatorTests { assertThat(translator.translate(TASK, SQL, badSqlEx)).isEqualTo(customDex); // Shouldn't custom translate this - DataAccessException dataAccessException = translator.translate(TASK, SQL, integrityViolationEx); - assertThat(dataAccessException) + assertThat(translator.translate(TASK, SQL, integrityViolationEx)) .isInstanceOf(DataIntegrityViolationException.class) .hasCause(integrityViolationEx); } @Test void customExceptionTranslation() { - final String TASK = "TASK"; - final String SQL = "SQL SELECT *"; - final SQLErrorCodes customErrorCodes = new SQLErrorCodes(); - final CustomSQLErrorCodesTranslation customTranslation = new CustomSQLErrorCodesTranslation(); + String TASK = "TASK"; + String SQL = "SQL SELECT *"; + SQLErrorCodes customErrorCodes = new SQLErrorCodes(); + CustomSQLErrorCodesTranslation customTranslation = new CustomSQLErrorCodesTranslation(); customErrorCodes.setBadSqlGrammarCodes("1", "2"); customErrorCodes.setDataIntegrityViolationCodes("3", "4"); @@ -173,15 +174,13 @@ class SQLErrorCodeSQLExceptionTranslatorTests { // Should custom translate this SQLException badSqlEx = new SQLException("", "", 1); - DataAccessException dataAccessException = translator.translate(TASK, SQL, badSqlEx); - assertThat(dataAccessException) + assertThat(translator.translate(TASK, SQL, badSqlEx)) .isInstanceOf(CustomErrorCodeException.class) .hasCause(badSqlEx); // Shouldn't custom translate this SQLException invResEx = new SQLException("", "", 3); - dataAccessException = translator.translate(TASK, SQL, invResEx); - assertThat(dataAccessException) + assertThat(translator.translate(TASK, SQL, invResEx)) .isInstanceOf(DataIntegrityViolationException.class) .hasCause(invResEx);