Skip to content

Commit f20e083

Browse files
committed
Clean up test
1 parent f95591a commit f20e083

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

integration-tests/bytecode-enhancements-it/src/test/java/org/hibernate/reactive/it/LazyBasicFieldTest.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ public void testFetchBasicFieldAlsoInitializesIt(VertxTestContext context) {
9898
.find( Crew.class, emily.getId() )
9999
.call( crew -> session.fetch( crew, Crew_.role )
100100
.invoke( role -> assertThat( role ).isEqualTo( emily.getRole() ) ) )
101-
.invoke( () -> sqlTracker.clear() )
102-
.call( crew -> session.fetch( crew, Crew_.role )
101+
.invoke( sqlTracker::clear )
102+
.call( crew -> session
103+
.fetch( crew, Crew_.role )
103104
.invoke( role -> {
104105
// No select query expected, the previous fetch must have initialized the role attribute
105106
assertThat(sqlTracker.getLoggedQueries()).hasSize( 0 );
@@ -116,11 +117,15 @@ public void testTransparentLazyFetching(VertxTestContext context) {
116117
emily.setRole( "Passenger" );
117118
emily.setFate( "Unknown" );
118119

119-
test( context, assertThrown( LazyInitializationException.class, getMutinySessionFactory()
120-
.withTransaction( session -> session.persist( emily ) )
121-
.call( () -> getMutinySessionFactory().withSession( session -> session.find( Crew.class, emily.getId() )
122-
.invoke( Crew::getRole ) ) )
123-
).invoke( exception -> assertThat( exception.getMessage() ).contains( "Reactive sessions do not support transparent lazy fetching" ) )
120+
test( context, assertThrown( LazyInitializationException.class,
121+
getMutinySessionFactory().withTransaction( session -> session.persist( emily ) )
122+
.chain( () -> getMutinySessionFactory().withSession( session -> session
123+
.find( Crew.class, emily.getId() )
124+
.map( Crew::getRole ) ) )
125+
).invoke( exception -> assertThat( exception )
126+
.as( "Expected LazyInitializationException not thrown" )
127+
.hasMessageContaining( "Reactive sessions do not support transparent lazy fetching" )
128+
)
124129
);
125130
}
126131

@@ -132,14 +137,21 @@ public void testGetReferenceAndTransparentLazyFetching(VertxTestContext context)
132137
emily.setRole( "Passenger" );
133138
emily.setFate( "Unknown" );
134139

135-
test( context, assertThrown( LazyInitializationException.class, getMutinySessionFactory()
136-
.withTransaction( session -> session.persist( emily ) )
137-
.chain( () -> getMutinySessionFactory().withSession( session -> {
138-
Crew crew = session.getReference( Crew.class, emily.getId() );
139-
String role = crew.getRole();
140-
return session.flush();
141-
} ) )
142-
).invoke( exception -> assertThat( exception.getMessage() ).contains( "Reactive sessions do not support transparent lazy fetching" ) )
140+
test(
141+
context, assertThrown(
142+
LazyInitializationException.class, getMutinySessionFactory()
143+
.withTransaction( session -> session.persist( emily ) )
144+
.chain( () -> getMutinySessionFactory().withSession( session -> {
145+
Crew crew = session.getReference( Crew.class, emily.getId() );
146+
// getRole() must throw a LazyInitializationException because we are not using
147+
// Mutiny.fetch to load a lazy field
148+
String role = crew.getRole();
149+
return Uni.createFrom()
150+
.failure( new AssertionError( "Expected LazyInitializationException not thrown" ) );
151+
} ) )
152+
).invoke( exception -> assertThat( exception )
153+
.as( "Expected LazyInitializationException not thrown" )
154+
.hasMessageContaining( "Reactive sessions do not support transparent lazy fetching" ) )
143155
);
144156
}
145157

0 commit comments

Comments
 (0)