Add missing test for IllegalArgumentException
Backport Bot / build (push) Has been cancelled Details
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Has been cancelled Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:false version:17], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:21], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:23], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled Details
Deploy Docs / Dispatch docs deployment (push) Has been cancelled Details
Build and Deploy Snapshot / Verify (push) Has been cancelled Details

See gh-35111
This commit is contained in:
Juergen Hoeller 2025-06-25 22:35:26 +02:00
parent 61474cc34c
commit 511739e3de
1 changed files with 7 additions and 2 deletions

View File

@ -17,11 +17,11 @@
package org.springframework.orm.jpa.hibernate; package org.springframework.orm.jpa.hibernate;
import jakarta.persistence.OptimisticLockException; import jakarta.persistence.OptimisticLockException;
import jakarta.persistence.PersistenceException;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.dialect.lock.OptimisticEntityLockException; import org.hibernate.dialect.lock.OptimisticEntityLockException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.orm.ObjectOptimisticLockingFailureException; import org.springframework.orm.ObjectOptimisticLockingFailureException;
import org.springframework.orm.jpa.JpaDialect; import org.springframework.orm.jpa.JpaDialect;
import org.springframework.orm.jpa.JpaOptimisticLockingFailureException; import org.springframework.orm.jpa.JpaOptimisticLockingFailureException;
@ -40,7 +40,7 @@ class HibernateJpaDialectTests {
@Test @Test
void testTranslateException() { void testTranslateException() {
// Plain JPA exception // Plain JPA exception
PersistenceException ex = new OptimisticLockException(); RuntimeException ex = new OptimisticLockException();
assertThat(dialect.translateExceptionIfPossible(ex)) assertThat(dialect.translateExceptionIfPossible(ex))
.isInstanceOf(JpaOptimisticLockingFailureException.class).hasCause(ex); .isInstanceOf(JpaOptimisticLockingFailureException.class).hasCause(ex);
@ -53,6 +53,11 @@ class HibernateJpaDialectTests {
ex = new HibernateException(new OptimisticEntityLockException("", "")); ex = new HibernateException(new OptimisticEntityLockException("", ""));
assertThat(dialect.translateExceptionIfPossible(ex)) assertThat(dialect.translateExceptionIfPossible(ex))
.isInstanceOf(ObjectOptimisticLockingFailureException.class).hasCause(ex); .isInstanceOf(ObjectOptimisticLockingFailureException.class).hasCause(ex);
// IllegalArgumentException
ex = new IllegalArgumentException("");
assertThat(dialect.translateExceptionIfPossible(ex))
.isInstanceOf(InvalidDataAccessApiUsageException.class).hasCause(ex);
} }
} }