Skip to content

Commit a2d5d30

Browse files
committed
[#487] Fix assert on non sorted collections
Unless the entities define it, we cannot rely on the element order to check the content of a collection.
1 parent 9b276ec commit a2d5d30

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.List;
1010
import java.util.Objects;
1111
import java.util.concurrent.CompletionStage;
12-
import java.util.stream.Collectors;
1312
import javax.persistence.ElementCollection;
1413
import javax.persistence.Entity;
1514
import javax.persistence.FetchType;
@@ -26,7 +25,8 @@
2625

2726
import io.smallrye.mutiny.Uni;
2827
import io.vertx.ext.unit.TestContext;
29-
import org.assertj.core.api.Assertions;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
3030

3131
/**
3232
* Tests @{@link ElementCollection} on a {@link List} of basic types.
@@ -602,21 +602,9 @@ private Uni<List<Object>> selectFromPhonesWithMutiny(Person person) {
602602
.getResultList();
603603
}
604604

605-
/**
606-
* Utility method to check the content of the collection of elements.
607-
* It sorts the expected and actual phones before comparing.
608-
*/
609605
private static void assertPhones(TestContext context, Person person, String... expectedPhones) {
610606
context.assertNotNull( person );
611-
String[] sortedExpected = Arrays.stream( expectedPhones ).sorted()
612-
.sorted( String.CASE_INSENSITIVE_ORDER )
613-
.collect( Collectors.toList() )
614-
.toArray( new String[expectedPhones.length] );
615-
List<String> sortedActual = person.getPhones().stream()
616-
.sorted( String.CASE_INSENSITIVE_ORDER )
617-
.collect( Collectors.toList() );
618-
Assertions.assertThat( sortedActual )
619-
.containsExactly( sortedExpected );
607+
assertThat( person.getPhones() ).containsExactlyInAnyOrder( expectedPhones );
620608
}
621609

622610
@Entity(name = "Person")

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.List;
1111
import java.util.Objects;
1212
import java.util.concurrent.CompletionStage;
13+
import java.util.stream.Collectors;
1314
import javax.persistence.ElementCollection;
1415
import javax.persistence.Embeddable;
1516
import javax.persistence.Entity;
@@ -27,6 +28,8 @@
2728
import io.smallrye.mutiny.Uni;
2829
import io.vertx.ext.unit.TestContext;
2930

31+
import static org.assertj.core.api.Assertions.assertThat;
32+
3033
/**
3134
* Tests @{@link ElementCollection} on a {@link java.util.Set} of basic types.
3235
* <p>
@@ -689,10 +692,11 @@ private Uni<List<Object>> selectFromPhonesWithMutiny(Person person) {
689692

690693
private static void assertPhones(TestContext context, Person person, String... phones) {
691694
context.assertNotNull( person );
692-
context.assertEquals( phones.length, person.getPhones().size() );
693-
for (int i=0; i<phones.length; i++) {
694-
context.assertEquals( phones[i], person.getPhones().get(i).getNumber() );
695-
}
695+
context.assertNotNull( person.getPhones() );
696+
List<String> personPhones = person.getPhones()
697+
.stream().map( phone -> phone.getNumber() ).collect( Collectors.toList() );
698+
699+
assertThat( personPhones ).containsExactlyInAnyOrder( phones );
696700
}
697701

698702
@Entity(name = "Person")

0 commit comments

Comments
 (0)