Skip to content

Commit 4a74f05

Browse files
committed
Clean up existing tests
1 parent c328f97 commit 4a74f05

File tree

7 files changed

+633
-665
lines changed

7 files changed

+633
-665
lines changed

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

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@
3838
import jakarta.persistence.Version;
3939

4040
import static java.util.concurrent.TimeUnit.MINUTES;
41-
import static org.junit.jupiter.api.Assertions.assertEquals;
42-
import static org.junit.jupiter.api.Assertions.assertFalse;
43-
import static org.junit.jupiter.api.Assertions.assertTrue;
41+
import static org.assertj.core.api.Assertions.assertThat;
4442

4543
@Timeout(value = 10, timeUnit = MINUTES)
46-
4744
public class BatchFetchTest extends BaseReactiveTest {
4845

4946
@Override
@@ -70,40 +67,37 @@ public void testQuery(VertxTestContext context) {
7067

7168
test( context, getSessionFactory()
7269
.withTransaction( s -> s.persist( basik ) )
73-
.thenCompose( v -> openSession() )
74-
.thenCompose( s -> s.createSelectionQuery( "from Node n order by id", Node.class )
70+
.thenCompose( v -> getSessionFactory().withSession( s -> s
71+
.createSelectionQuery( "from Node n order by id", Node.class )
7572
.getResultList()
7673
.thenCompose( list -> {
77-
assertEquals( list.size(), 2 );
74+
assertThat( list ).hasSize( 2 );
7875
Node n1 = list.get( 0 );
7976
Node n2 = list.get( 1 );
80-
assertFalse( Hibernate.isInitialized( n1.getElements() ), "'n1.elements' should not be initialize" );
81-
assertFalse( Hibernate.isInitialized( n2.getElements() ), "'n2.elements' should not be initialize" );
77+
assertThat( Hibernate.isInitialized( n1.getElements() ) ).as( "'n1.elements' should not be initialized" ).isFalse();
78+
assertThat( Hibernate.isInitialized( n2.getElements() ) ).as( "'n2.elements' should not be initialized" ).isFalse();
8279
return s.fetch( n1.getElements() )
8380
.thenAccept( elements -> {
84-
assertTrue( Hibernate.isInitialized( elements ), "'elements' after fetch should not be initialize" );
85-
assertTrue( Hibernate.isInitialized( n1.getElements() ), "'n1.elements' after fetch should be initialize" );
86-
assertTrue( Hibernate.isInitialized( n2.getElements() ), "'n2.elements' after fetch should be initialize" );
81+
assertThat( Hibernate.isInitialized( elements ) ).as( "'elements' after fetch should not be initialize" ).isTrue();
82+
assertThat( Hibernate.isInitialized( n1.getElements() ) ).as( "'n1.elements' after fetch should be initialize" ).isTrue();
83+
assertThat( Hibernate.isInitialized( n2.getElements() ) ).as( "'n2.elements' after fetch should be initialize" ).isTrue();
8784
} );
8885
} )
89-
)
86+
) )
9087
.thenCompose( v -> openSession() )
9188
.thenCompose( s -> s.createSelectionQuery( "from Element e order by id", Element.class )
9289
.getResultList()
9390
.thenCompose( list -> {
94-
assertEquals( list.size(), 5 );
95-
list.forEach( element -> assertFalse( Hibernate.isInitialized( element.node ) ) );
96-
list.forEach( element -> assertEquals( s.getLockMode( element.node ), LockMode.NONE ) );
91+
assertThat( list ).hasSize( 5 );
92+
list.forEach( element -> assertThat( Hibernate.isInitialized( element.node ) ).isFalse() );
93+
list.forEach( element -> assertThat( s.getLockMode( element.node ) ).isEqualTo( LockMode.NONE ) );
9794
return s.fetch( list.get( 0 ).node )
9895
.thenAccept( node -> {
99-
assertTrue( Hibernate.isInitialized( node ) );
96+
assertThat( Hibernate.isInitialized( node ) ).isTrue();
10097
//TODO: I would like to assert that they're all initialized
10198
// but apparently it doesn't set the proxies to init'd
10299
// so check the LockMode as a workaround
103-
list.forEach( element -> assertEquals(
104-
s.getLockMode( element.node ),
105-
LockMode.READ
106-
) );
100+
list.forEach( element -> assertThat( s.getLockMode( element.node ) ).isEqualTo( LockMode.READ ) );
107101
} );
108102
} )
109103
)
@@ -125,11 +119,11 @@ public void testBatchLoad(VertxTestContext context) {
125119
.thenCompose( v -> openSession() )
126120
.thenCompose( s -> s.find( Element.class, basik.elements.get( 1 ).id, basik.elements.get( 2 ).id, basik.elements.get( 0 ).id ) )
127121
.thenAccept( elements -> {
128-
assertFalse( elements.isEmpty() );
129-
assertEquals( 3, elements.size() );
130-
assertEquals( basik.elements.get( 1 ).id, elements.get( 0 ).id );
131-
assertEquals( basik.elements.get( 2 ).id, elements.get( 1 ).id );
132-
assertEquals( basik.elements.get( 0 ).id, elements.get( 2 ).id );
122+
assertThat( elements ).isNotEmpty();
123+
assertThat( elements ).hasSize( 3 );
124+
assertThat( elements.get( 0 ).id ).isEqualTo( basik.elements.get( 1 ).id );
125+
assertThat( elements.get( 1 ).id ).isEqualTo( basik.elements.get( 2 ).id );
126+
assertThat( elements.get( 2 ).id ).isEqualTo( basik.elements.get( 0 ).id );
133127
} )
134128
);
135129
}
@@ -150,12 +144,12 @@ public void testWithCollection(VertxTestContext context) {
150144
.createSelectionQuery( "from Node n order by id", Node.class )
151145
.getResultList()
152146
.thenCompose( list -> {
153-
assertEquals( list.size(), 1 );
147+
assertThat( list ).hasSize( 1 );
154148
Node n1 = list.get( 0 );
155-
assertFalse( Hibernate.isInitialized( n1.elements ) );
149+
assertThat( Hibernate.isInitialized( n1.elements ) ).isFalse();
156150
return s.fetch( n1.elements ).thenAccept( elements -> {
157-
assertTrue( Hibernate.isInitialized( elements ) );
158-
assertTrue( Hibernate.isInitialized( n1.elements ) );
151+
assertThat( Hibernate.isInitialized( elements ) ).isTrue();
152+
assertThat( Hibernate.isInitialized( n1.elements ) ).isTrue();
159153
} );
160154
} )
161155
)
@@ -177,7 +171,7 @@ public Element(Node node) {
177171
this.node = node;
178172
}
179173

180-
Element() {
174+
public Element() {
181175
}
182176

183177
public Node getNode() {
@@ -227,7 +221,7 @@ public Node(String string) {
227221
this.string = string;
228222
}
229223

230-
Node() {
224+
public Node() {
231225
}
232226

233227
@PrePersist

0 commit comments

Comments
 (0)