Skip to content

Commit e4e5d98

Browse files
committed
AssertJ
1 parent 5f430e4 commit e4e5d98

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

persistence-modules/core-java-persistence-4/src/test/java/com/baeldung/sql/MultipleSQLExecutionLiveTest.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import static org.junit.jupiter.api.Assertions.assertEquals;
1414
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
import static org.assertj.core.api.Assertions.assertThat;
1516

1617
// Please note, this test requires a MySQL server running on localhost:3306 with database users_db already created.
1718
// We have added creation of the table it in the setup() method.
@@ -81,16 +82,11 @@ public void givenMultipleSelectStatements_whenExecuting_thenCorrectUsersAreFetch
8182

8283
List<User> users = execution.executeMultipleSelectStatements();
8384

84-
// Here we verify the correct number of users were fetched
85-
assertEquals(2, users.size(), "There should be exactly two users fetched.");
86-
87-
List<String> fetchedUserNames = users.stream()
88-
.map(User::getName)
89-
.toList();
90-
91-
// Here, we verify that expected users are present
92-
List<String> expectedUserNames = List.of("Alice", "Bob");
93-
assertTrue(fetchedUserNames.containsAll(expectedUserNames), "Fetched users should match the expected names.");
85+
// Here we verify that exactly two users are fetched and their names match the expected ones
86+
assertThat(users)
87+
.hasSize(2)
88+
.extracting(User::getName)
89+
.containsExactlyInAnyOrder("Alice", "Bob");
9490
}
9591
}
9692

0 commit comments

Comments
 (0)