Skip to content

Commit 0abb15c

Browse files
committed
chore: remove some warnings from tests
Replace assertions
1 parent 6ccdf1b commit 0abb15c

File tree

1 file changed

+46
-41
lines changed

1 file changed

+46
-41
lines changed

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

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
*/
66
package org.hibernate.reactive;
77

8-
import java.util.Collection;
9-
import java.util.Date;
10-
import java.util.List;
11-
import java.util.Objects;
12-
138
import org.junit.jupiter.api.Assertions;
149
import org.junit.jupiter.api.Test;
1510

@@ -26,12 +21,13 @@
2621
import jakarta.persistence.Table;
2722
import jakarta.persistence.Temporal;
2823
import jakarta.persistence.TemporalType;
24+
import java.util.Collection;
25+
import java.util.Date;
26+
import java.util.List;
27+
import java.util.Objects;
2928

3029
import static java.util.concurrent.TimeUnit.MINUTES;
31-
import static org.junit.jupiter.api.Assertions.assertEquals;
32-
import static org.junit.jupiter.api.Assertions.assertFalse;
33-
import static org.junit.jupiter.api.Assertions.assertNotNull;
34-
import static org.junit.jupiter.api.Assertions.assertTrue;
30+
import static org.assertj.core.api.Assertions.assertThat;
3531

3632
@Timeout(value = 10, timeUnit = MINUTES)
3733

@@ -56,9 +52,8 @@ public void testRootClassViaAssociation(VertxTestContext context) {
5652
.thenCompose( v -> openSession() )
5753
.thenCompose( s2 -> s2.find( Author.class, author.getId() ) )
5854
.thenAccept( auth -> {
59-
assertNotNull( auth );
60-
assertEquals( author, auth );
61-
assertEquals( book.getTitle(), auth.getBook().getTitle() );
55+
assertThat( auth ).isEqualTo( author );
56+
assertThat( auth.getBook().getTitle() ).isEqualTo( book.getTitle() );
6257
} )
6358
)
6459
);
@@ -77,17 +72,15 @@ public void testSubclassViaAssociation(VertxTestContext context) {
7772
.thenCompose( v -> s.flush() )
7873
.thenCompose( v -> s.find( Author.class, author.getId() ) )
7974
.thenAccept( auth -> {
80-
assertNotNull( auth );
81-
assertEquals( author, auth );
82-
assertEquals( book.getTitle(), auth.getBook().getTitle() );
75+
assertThat( auth ).isEqualTo( author );
76+
assertThat( auth.getBook().getTitle() ).isEqualTo( book.getTitle() );
8377
} )
8478
)
8579
);
8680
}
8781

8882
@Test
8983
public void testRootClassViaFind(VertxTestContext context) {
90-
9184
final Book novel = new Book( 6, "The Boy, The Mole, The Fox and The Horse", new Date());
9285
final Author author = new Author( "Charlie Mackesy", novel );
9386

@@ -99,9 +92,8 @@ public void testRootClassViaFind(VertxTestContext context) {
9992
.thenCompose( v -> openSession()
10093
.thenCompose( s -> s.find(Book.class, 6) ) )
10194
.thenAccept(book -> {
102-
assertNotNull(book);
103-
assertFalse(book instanceof SpellBook);
104-
assertEquals(book.getTitle(), "The Boy, The Mole, The Fox and The Horse");
95+
assertThat( book ).isNotInstanceOf( SpellBook.class );
96+
assertThat( book.getTitle() ).isEqualTo( "The Boy, The Mole, The Fox and The Horse" );
10597
}));
10698
}
10799

@@ -117,35 +109,41 @@ public void testSubclassViaFind(VertxTestContext context) {
117109
.thenCompose( v -> s.flush() ) )
118110
.thenCompose( v -> openSession().thenCompose( s -> s.find(Book.class, 6) ) )
119111
.thenAccept(book -> {
120-
assertNotNull(book);
121-
assertTrue(book instanceof SpellBook);
122-
assertEquals(book.getTitle(), "Necronomicon");
112+
assertThat( book ).isInstanceOf( SpellBook.class );
113+
assertThat( book.getTitle() ).isEqualTo( "Necronomicon" );
123114
}));
124115
}
125116

126117
@Test
127118
public void testQueryUpdate(VertxTestContext context) {
128119
final SpellBook spells = new SpellBook( 6, "Necronomicon", true, new Date() );
129-
// final Author author = new Author( "Abdul Alhazred", spells );
130120

131-
test( context,
121+
test(
122+
context,
132123
openSession()
133-
.thenCompose( s -> s.persist(spells).thenCompose( v -> s.flush() ) )
124+
.thenCompose( s -> s.persist( spells ).thenCompose( v -> s.flush() ) )
134125
.thenCompose( vv -> openSession()
135-
.thenCompose( s -> s.withTransaction( t -> s.createMutationQuery("update SpellBook set title='x' where forbidden=false").executeUpdate() )
136-
.thenCompose( v -> s.withTransaction( t -> s.createMutationQuery("update SpellBook set forbidden=false where title='Necronomicon'").executeUpdate() ) )
137-
.thenCompose( v -> s.withTransaction( t -> s.createMutationQuery("update Book set title=title||' II' where title='Necronomicon'").executeUpdate() ) )
138-
.thenCompose( v -> s.find(Book.class, 6) )
126+
.thenCompose( s -> s.withTransaction( t -> s
127+
.createMutationQuery( "update SpellBook set title='x' where forbidden=false" )
128+
.executeUpdate() )
129+
.thenCompose( v -> s.withTransaction( t -> s
130+
.createMutationQuery( "update SpellBook set forbidden=false where title='Necronomicon'" )
131+
.executeUpdate() ) )
132+
.thenCompose( v -> s.withTransaction( t -> s
133+
.createMutationQuery( "update Book set title=title||' II' where title='Necronomicon'" )
134+
.executeUpdate() ) )
135+
.thenCompose( v -> s.find( Book.class, 6 ) )
139136
.thenAccept( book -> {
140-
assertNotNull(book);
141-
assertTrue(book instanceof SpellBook);
142-
assertEquals(book.getTitle(), "Necronomicon II");
137+
assertThat( book ).isInstanceOf( SpellBook.class );
138+
assertThat( book.getTitle() ).isEqualTo( "Necronomicon II" );
143139
} )
144-
) )
140+
) )
145141
.thenCompose( vv -> openSession()
146-
.thenCompose( s -> s.withTransaction( t -> s.createMutationQuery("delete Book where title='Necronomicon II'").executeUpdate() ) )
142+
.thenCompose( s -> s.withTransaction( t -> s
143+
.createMutationQuery( "delete Book where title='Necronomicon II'" )
144+
.executeUpdate() ) )
147145
.thenCompose( v -> openSession() )
148-
.thenCompose( s -> s.find(Book.class, 6) )
146+
.thenCompose( s -> s.find( Book.class, 6 ) )
149147
.thenAccept( Assertions::assertNull )
150148
)
151149
);
@@ -154,7 +152,6 @@ public void testQueryUpdate(VertxTestContext context) {
154152
@Test
155153
public void testQueryUpdateWithParameters(VertxTestContext context) {
156154
final SpellBook spells = new SpellBook( 6, "Necronomicon", true, new Date() );
157-
// final Author author = new Author( "Abdul Alhazred", spells );
158155

159156
test( context,
160157
openSession()
@@ -174,11 +171,9 @@ public void testQueryUpdateWithParameters(VertxTestContext context) {
174171
.thenCompose( v -> openSession()
175172
.thenCompose( s -> s.find( Book.class, 6) )
176173
.thenAccept( book -> {
177-
assertNotNull(book);
178-
assertTrue(book instanceof SpellBook);
179-
assertEquals(book.getTitle(), "Necronomicon II");
180-
}
181-
)
174+
assertThat( book ).isInstanceOf( SpellBook.class );
175+
assertThat( book.getTitle() ).isEqualTo( "Necronomicon II" );
176+
} )
182177
)
183178
.thenCompose( v -> openSession()
184179
.thenCompose( s -> s.withTransaction( t -> s.createMutationQuery("delete Book where title=:tit")
@@ -207,6 +202,11 @@ public SpellBook(Integer id, String title, boolean forbidden, Date published) {
207202
public boolean getForbidden() {
208203
return forbidden;
209204
}
205+
206+
@Override
207+
public String toString() {
208+
return "SpellBook{" + super.toString() + ",forbidden=" + forbidden + '}';
209+
}
210210
}
211211

212212
@Entity(name="Book")
@@ -268,6 +268,11 @@ public boolean equals(Object o) {
268268
public int hashCode() {
269269
return Objects.hash( title );
270270
}
271+
272+
@Override
273+
public String toString() {
274+
return id + ", " + title + ", " + published;
275+
}
271276
}
272277

273278
@Entity(name = "Author")

0 commit comments

Comments
 (0)