5
5
*/
6
6
package org .hibernate .reactive ;
7
7
8
+ import java .util .concurrent .CompletableFuture ;
8
9
import javax .persistence .Entity ;
9
10
import javax .persistence .Id ;
10
11
14
15
15
16
import org .junit .Test ;
16
17
18
+ import io .smallrye .mutiny .Uni ;
17
19
import io .vertx .core .Context ;
18
20
import io .vertx .core .Vertx ;
19
21
import io .vertx .ext .unit .Async ;
@@ -53,7 +55,7 @@ public void testPersistWithStage(TestContext testContext) throws Exception {
53
55
newContext .runOnContext ( event -> test ( async , testContext , session
54
56
.persist ( new Competition ( "Cheese Rolling" ) )
55
57
.thenCompose ( v -> session .flush () )
56
- .handle ( (v , e ) -> assertExceptionThrown ( e ) ) )
58
+ .handle ( (v , e ) -> assertExceptionThrown ( e ). join () ) )
57
59
);
58
60
}
59
61
@@ -70,7 +72,7 @@ public void testFindWithStage(TestContext testContext) throws Exception {
70
72
// Run test in the new context
71
73
newContext .runOnContext ( event -> test ( async , testContext , session
72
74
.find ( Competition .class , "Chess boxing" )
73
- .handle ( (v , e ) -> assertExceptionThrown ( e ) ) )
75
+ .handle ( (v , e ) -> assertExceptionThrown ( e ). join () ) )
74
76
);
75
77
}
76
78
@@ -88,8 +90,8 @@ public void testOnPersistWithMutiny(TestContext testContext) throws Exception {
88
90
newContext .runOnContext ( event -> test ( async , testContext , session
89
91
.persist ( new Competition ( "Cheese Rolling" ) )
90
92
.call ( session ::flush )
91
- .onItem (). failWith ( () -> new AssertionError ( "No exception thrown" ) )
92
- .onFailure (). recoverWithItem ( e -> assertExceptionThrown ( e ) ) )
93
+ .onItemOrFailure ( )
94
+ .transformToUni ( ( unused , e ) -> Uni . createFrom (). completionStage ( assertExceptionThrown ( e ) ) ) )
93
95
);
94
96
}
95
97
@@ -106,22 +108,25 @@ public void testFindWithMutiny(TestContext testContext) throws Exception {
106
108
// Run test in the new context
107
109
newContext .runOnContext ( event -> test ( async , testContext , session
108
110
.find ( Competition .class , "Chess boxing" )
109
- .onItem (). failWith ( () -> new AssertionError ( "No exception thrown" ) )
110
- .onFailure (). recoverWithItem ( e -> assertExceptionThrown ( e ) ) )
111
+ .onItemOrFailure ( )
112
+ .transformToUni ( ( unused , e ) -> Uni . createFrom (). completionStage ( assertExceptionThrown ( e ) ) ) )
111
113
);
112
114
}
113
115
114
116
// Check that at least one exception has the expected message
115
- private static <T > T assertExceptionThrown (Throwable e ) {
117
+ private static CompletableFuture <Void > assertExceptionThrown (Throwable e ) {
118
+ CompletableFuture <Void > result = new CompletableFuture <>();
116
119
Throwable t = e ;
117
120
while ( t != null ) {
118
121
if ( t .getClass ().equals ( IllegalStateException .class )
119
122
&& t .getMessage ().contains ( ERROR_MESSAGE ) ) {
120
- return null ;
123
+ result .complete ( null );
124
+ return result ;
121
125
}
122
126
t = t .getCause ();
123
127
}
124
- throw new AssertionError ( "Expected exception not thrown. Exception thrown: " + e );
128
+ result .completeExceptionally ( new AssertionError ( "Expected exception not thrown. Exception thrown: " + e ) );
129
+ return result ;
125
130
}
126
131
127
132
@ Entity
0 commit comments