21
21
import jakarta .persistence .Table ;
22
22
23
23
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 ;
26
26
27
27
@ Timeout (value = 10 , timeUnit = MINUTES )
28
28
@@ -33,25 +33,22 @@ protected Collection<Class<?>> annotatedEntities() {
33
33
return List .of ( Person .class );
34
34
}
35
35
36
- Class <?> getExpectedException () {
37
- return ConstraintViolationException .class ;
38
- }
39
-
40
36
@ Test
41
37
public void testDuplicateKeyException (VertxTestContext context ) {
42
- test ( context , openMutinySession ()
38
+ test ( context , assertThrown ( ConstraintViolationException . class , openMutinySession ()
43
39
.call ( session -> session .persist ( new Person ( "testFLush1" , "unique" ) ) )
44
40
.call ( Mutiny .Session ::flush )
45
41
.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 )
52
44
);
53
45
}
54
46
47
+ private static void testExceptionMessage (ConstraintViolationException exception ) {
48
+ assertThat ( exception .getConstraintName () ).isNotNull ();
49
+ assertThat ( exception .getSQLState () ).matches ( "23\\ d{3}" );
50
+ }
51
+
55
52
@ Entity (name = "Person" )
56
53
@ Table (name = "PersonForExceptionWithMutiny" )
57
54
public static class Person {
0 commit comments