Skip to content

Commit 21096b1

Browse files
sorting MQL translation (#90)
HIBERNATE-68
1 parent 776a5eb commit 21096b1

File tree

13 files changed

+1274
-80
lines changed

13 files changed

+1274
-80
lines changed

src/integrationTest/java/com/mongodb/hibernate/MongoTestAssertions.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
2020

21+
import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;
2122
import org.jspecify.annotations.Nullable;
2223

2324
public final class MongoTestAssertions {
@@ -35,4 +36,19 @@ public static void assertEquals(@Nullable Object expected, @Nullable Object actu
3536
.withStrictTypeChecking()
3637
.isEqualTo(expected);
3738
}
39+
40+
/**
41+
* This method is intended to be a drop-in replacement for
42+
* {@link org.junit.jupiter.api.Assertions#assertIterableEquals(Iterable, Iterable)}. It should work even if
43+
* elements in {@code expected}/{@code actual} do not override {@link Object#equals(Object)}.
44+
*/
45+
@SuppressWarnings("unchecked")
46+
public static <T> void assertIterableEq(Iterable<T> expectedResultList, Iterable<? extends T> actualResultList) {
47+
assertThat((Iterable<T>) actualResultList)
48+
.usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration.builder()
49+
.withIgnoreAllOverriddenEquals(false)
50+
.withStrictTypeChecking(true)
51+
.build())
52+
.containsExactlyElementsOf(expectedResultList);
53+
}
3854
}

src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.mongodb.hibernate.query.select;
1818

19+
import static com.mongodb.hibernate.MongoTestAssertions.assertIterableEq;
1920
import static org.assertj.core.api.Assertions.assertThat;
2021
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2122

@@ -65,9 +66,12 @@ <T> void assertSelectionQuery(
6566
Consumer<SelectionQuery<T>> queryPostProcessor,
6667
String expectedMql,
6768
List<T> expectedResultList) {
68-
assertSelectionQuery(hql, resultType, queryPostProcessor, expectedMql, resultList -> assertThat(resultList)
69-
.usingRecursiveFieldByFieldElementComparator()
70-
.containsExactlyElementsOf(expectedResultList));
69+
assertSelectionQuery(
70+
hql,
71+
resultType,
72+
queryPostProcessor,
73+
expectedMql,
74+
resultList -> assertIterableEq(expectedResultList, resultList));
7175
}
7276

7377
<T> void assertSelectionQuery(String hql, Class<T> resultType, String expectedMql, List<T> expectedResultList) {

src/integrationTest/java/com/mongodb/hibernate/query/select/Book.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,31 @@
1616

1717
package com.mongodb.hibernate.query.select;
1818

19-
import com.mongodb.hibernate.annotations.ObjectIdGenerator;
2019
import jakarta.persistence.Entity;
2120
import jakarta.persistence.Id;
2221
import jakarta.persistence.Table;
2322
import java.math.BigDecimal;
24-
import org.bson.types.ObjectId;
2523

2624
@Entity(name = "Book")
2725
@Table(name = "books")
28-
public class Book {
26+
class Book {
2927
@Id
30-
@ObjectIdGenerator
31-
ObjectId id;
32-
33-
Book() {}
28+
int id;
3429

30+
// TODO-HIBERNATE-48 dummy values are set for currently null value is not supported
3531
String title = "";
3632
Boolean outOfStock = false;
3733
Integer publishYear = 0;
3834
Long isbn13 = 0L;
39-
Double discount = 0.0D;
35+
Double discount = 0.0;
4036
BigDecimal price = new BigDecimal("0.0");
37+
38+
Book() {}
39+
40+
Book(int id, String title, Integer publishYear, Boolean outOfStock) {
41+
this.id = id;
42+
this.title = title;
43+
this.publishYear = publishYear;
44+
this.outOfStock = outOfStock;
45+
}
4146
}

src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionWhereClauseIntegrationTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ class BooleanExpressionWhereClauseIntegrationTests extends AbstractSelectionQuer
3333
@BeforeEach
3434
void beforeEach() {
3535
bookOutOfStock = new Book();
36+
bookOutOfStock.id = 1;
3637
bookOutOfStock.outOfStock = true;
3738

3839
bookInStock = new Book();
40+
bookInStock.id = 2;
3941
bookInStock.outOfStock = false;
4042

4143
getSessionFactoryScope().inTransaction(session -> {

0 commit comments

Comments
 (0)