Browse Source

Polish SQLErrorCodeSQLExceptionTranslatorTests

pull/35738/head
Sam Brannen 2 months ago
parent
commit
00e1429378
  1. 27
      spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java

27
spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java

@ -42,6 +42,8 @@ import static org.mockito.Mockito.mock; @@ -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 { @@ -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 { @@ -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 { @@ -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);

Loading…
Cancel
Save