From 68762fd0734945776b7b6d6944dd00897ddd6329 Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Thu, 23 May 2024 14:53:26 +0200 Subject: [PATCH] refactor: Stablize test. Sorting is probably a good idea when testing the result on a specific order. --- .../QuerydslNeo4jPredicateExecutorIT.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/springframework/data/neo4j/integration/imperative/QuerydslNeo4jPredicateExecutorIT.java b/src/test/java/org/springframework/data/neo4j/integration/imperative/QuerydslNeo4jPredicateExecutorIT.java index fd15b4ac2..d1361d872 100644 --- a/src/test/java/org/springframework/data/neo4j/integration/imperative/QuerydslNeo4jPredicateExecutorIT.java +++ b/src/test/java/org/springframework/data/neo4j/integration/imperative/QuerydslNeo4jPredicateExecutorIT.java @@ -47,7 +47,7 @@ import org.springframework.data.neo4j.test.Neo4jExtension; import org.springframework.data.neo4j.test.Neo4jIntegrationTest; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.query.FluentQuery; +import org.springframework.data.repository.query.FluentQuery.FetchableFluentQuery; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; @@ -97,7 +97,7 @@ protected static void setupData(@Autowired BookmarkCapture bookmarkCapture) { void fluentFindOneShouldWork(@Autowired QueryDSLPersonRepository repository) { Predicate predicate = Expressions.predicate(Ops.EQ, firstNamePath, Expressions.asString("Helge")); - Person person = repository.findBy(predicate, q -> q.oneValue()); + Person person = repository.findBy(predicate, FetchableFluentQuery::oneValue); assertThat(person).isNotNull(); assertThat(person).extracting(Person::getLastName).isEqualTo("Schneider"); @@ -108,7 +108,7 @@ void fluentFindAllShouldWork(@Autowired QueryDSLPersonRepository repository) { Predicate predicate = Expressions.predicate(Ops.EQ, firstNamePath, Expressions.asString("Helge")) .or(Expressions.predicate(Ops.EQ, lastNamePath, Expressions.asString("B."))); - List people = repository.findBy(predicate, q -> q.all()); + List people = repository.findBy(predicate, FetchableFluentQuery::all); assertThat(people).extracting(Person::getFirstName) .containsExactlyInAnyOrder("Bela", "Helge"); @@ -170,9 +170,10 @@ void scrollByExampleWithContinuingOffset(@Autowired QueryDSLPersonRepository rep Predicate predicate = Expressions.predicate(Ops.EQ, firstNamePath, Expressions.asString("Helge")) .or(Expressions.predicate(Ops.EQ, lastNamePath, Expressions.asString("B."))); - Window peopleWindow = repository.findBy(predicate, q -> q.limit(1).sortBy(Sort.by("firstName").descending()).scroll(ScrollPosition.offset())); + var firstName = Sort.by("firstName").descending(); + Window peopleWindow = repository.findBy(predicate, q -> q.limit(1).sortBy(firstName).scroll(ScrollPosition.offset())); ScrollPosition currentPosition = peopleWindow.positionAt(peopleWindow.getContent().get(0)); - peopleWindow = repository.findBy(predicate, q -> q.limit(1).scroll(currentPosition)); + peopleWindow = repository.findBy(predicate, q -> q.limit(1).sortBy(firstName).scroll(currentPosition)); assertThat(peopleWindow.getContent()).extracting(Person::getFirstName) .containsExactlyInAnyOrder("Bela"); @@ -250,7 +251,7 @@ void fluentfindAllAsShouldWork(@Autowired QueryDSLPersonRepository repository) { void fluentStreamShouldWork(@Autowired QueryDSLPersonRepository repository) { Predicate predicate = Expressions.predicate(Ops.EQ, firstNamePath, Expressions.asString("Helge")); - Stream people = repository.findBy(predicate, FluentQuery.FetchableFluentQuery::stream); + Stream people = repository.findBy(predicate, FetchableFluentQuery::stream); assertThat(people.map(Person::getFirstName)).containsExactly("Helge"); } @@ -323,7 +324,7 @@ void fluentFindAllWithLimitShouldWork(@Autowired QueryDSLPersonRepository reposi Predicate predicate = Expressions.predicate(Ops.EQ, firstNamePath, Expressions.asString("Helge")) .or(Expressions.predicate(Ops.EQ, lastNamePath, Expressions.asString("B."))); List people = repository.findBy(predicate, - q -> q.limit(1)).all(); + q -> q.limit(1).sortBy(Sort.by("firstName").descending())).all(); assertThat(people).hasSize(1); assertThat(people).extracting(Person::getFirstName).containsExactly("Helge");