Skip to content

Commit 77cdf7a

Browse files
committed
Clean up test
1 parent f95591a commit 77cdf7a

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

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

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ 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
105-
assertThat(sqlTracker.getLoggedQueries()).hasSize( 0 );
106-
assertThat( role ).isEqualTo( emily.getRole() );} )
106+
assertThat( sqlTracker.getLoggedQueries() ).hasSize( 0 );
107+
assertThat( role ).isEqualTo( emily.getRole() );
108+
} )
107109
) ) )
108110
);
109111
}
@@ -116,11 +118,17 @@ public void testTransparentLazyFetching(VertxTestContext context) {
116118
emily.setRole( "Passenger" );
117119
emily.setFate( "Unknown" );
118120

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" ) )
121+
test( context, assertThrown( LazyInitializationException.class,
122+
getMutinySessionFactory().withTransaction( session -> session.persist( emily ) )
123+
.chain( () -> getMutinySessionFactory().withSession( session -> session
124+
.find( Crew.class, emily.getId() )
125+
// getRole() must throw a LazyInitializationException because we are not using
126+
// Mutiny.fetch to load a lazy field
127+
.map( Crew::getRole ) ) )
128+
).invoke( exception -> assertThat( exception )
129+
.as( "Expected LazyInitializationException not thrown" )
130+
.hasMessageContaining( "Reactive sessions do not support transparent lazy fetching" )
131+
)
124132
);
125133
}
126134

@@ -132,14 +140,21 @@ public void testGetReferenceAndTransparentLazyFetching(VertxTestContext context)
132140
emily.setRole( "Passenger" );
133141
emily.setFate( "Unknown" );
134142

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" ) )
143+
test(
144+
context, assertThrown(
145+
LazyInitializationException.class, getMutinySessionFactory()
146+
.withTransaction( session -> session.persist( emily ) )
147+
.chain( () -> getMutinySessionFactory().withSession( session -> {
148+
Crew crew = session.getReference( Crew.class, emily.getId() );
149+
// getRole() must throw a LazyInitializationException because we are not using
150+
// Mutiny.fetch to load a lazy field
151+
String role = crew.getRole();
152+
return Uni.createFrom()
153+
.failure( new AssertionError( "Expected LazyInitializationException not thrown" ) );
154+
} ) )
155+
).invoke( exception -> assertThat( exception )
156+
.as( "Expected LazyInitializationException not thrown" )
157+
.hasMessageContaining( "Reactive sessions do not support transparent lazy fetching" ) )
143158
);
144159
}
145160

0 commit comments

Comments
 (0)