mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Polish SQLErrorCodeSQLExceptionTranslatorTests
This commit is contained in:
+13
-14
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user