Skip to content

Commit d357392

Browse files
committed
[#1639] Test ConstraintViolationException SQLState code
1 parent 7ed6d24 commit d357392

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/MutinyExceptionsTest.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import jakarta.persistence.Table;
2222

2323
import static java.util.concurrent.TimeUnit.MINUTES;
24-
import static org.junit.jupiter.api.Assertions.assertEquals;
25-
import static org.junit.jupiter.api.Assertions.fail;
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
import static org.hibernate.reactive.testing.ReactiveAssertions.assertThrown;
2626

2727
@Timeout(value = 10, timeUnit = MINUTES)
2828

@@ -33,25 +33,22 @@ protected Collection<Class<?>> annotatedEntities() {
3333
return List.of( Person.class );
3434
}
3535

36-
Class<?> getExpectedException() {
37-
return ConstraintViolationException.class;
38-
}
39-
4036
@Test
4137
public void testDuplicateKeyException(VertxTestContext context) {
42-
test( context, openMutinySession()
38+
test( context, assertThrown( ConstraintViolationException.class, openMutinySession()
4339
.call( session -> session.persist( new Person( "testFLush1", "unique" ) ) )
4440
.call( Mutiny.Session::flush )
4541
.call( session -> session.persist( new Person( "testFlush2", "unique" ) ) )
46-
.call( Mutiny.Session::flush )
47-
.invoke( ignore -> fail( "Expected exception not thrown" ) )
48-
.onFailure().recoverWithItem( err -> {
49-
assertEquals( getExpectedException(), err.getClass() );
50-
return null;
51-
} )
42+
.call( Mutiny.Session::flush ) )
43+
.invoke( MutinyExceptionsTest::testExceptionMessage )
5244
);
5345
}
5446

47+
private static void testExceptionMessage(ConstraintViolationException exception) {
48+
assertThat( exception.getConstraintName() ).isNotNull();
49+
assertThat( exception.getSQLState() ).matches( "23\\d{3}" );
50+
}
51+
5552
@Entity(name = "Person")
5653
@Table(name = "PersonForExceptionWithMutiny")
5754
public static class Person {

0 commit comments

Comments
 (0)