From b87336ba8f509cfad10b956bc7618b5652776eea Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 25 Jul 2017 14:22:45 +0200 Subject: [PATCH] #297 - Update to changes in ExampleMatcher API. --- .../UserRepositoryIntegrationTests.java | 31 +++++++++---------- .../MongoOperationsIntegrationTests.java | 22 ++++++------- .../UserRepositoryIntegrationTests.java | 30 +++++++++--------- 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java index bc162d9e..ad653fcc 100644 --- a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java +++ b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java @@ -16,8 +16,10 @@ package example.springdata.jpa.querybyexample; import static org.assertj.core.api.Assertions.*; -import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; import static org.springframework.data.domain.ExampleMatcher.*; +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; + +import java.util.Optional; import org.junit.Before; import org.junit.Test; @@ -25,7 +27,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Example; -import org.springframework.data.domain.ExampleMatcher.*; +import org.springframework.data.domain.ExampleMatcher.StringMatcher; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; @@ -36,7 +38,6 @@ import org.springframework.transaction.annotation.Transactional; * @author Oliver Gierke * @author Jens Schauder */ -@SuppressWarnings("unused") @RunWith(SpringRunner.class) @Transactional @SpringBootTest @@ -75,7 +76,7 @@ public class UserRepositoryIntegrationTests { @Test public void ignorePropertiesAndMatchByAge() { - Example example = Example.of(flynn, matching().// + Example example = Example.of(flynn, matching(). // withIgnorePaths("firstname", "lastname")); assertThat(repository.findOne(example)).contains(flynn); @@ -87,7 +88,7 @@ public class UserRepositoryIntegrationTests { @Test public void substringMatching() { - Example example = Example.of(new User("er", null, null), matching().// + Example example = Example.of(new User("er", null, null), matching(). // withStringMatcher(StringMatcher.ENDING)); assertThat(repository.findAll(example)).containsExactly(skyler, walter); @@ -99,11 +100,10 @@ public class UserRepositoryIntegrationTests { @Test public void matchStartingStringsIgnoreCase() { - Example example = Example.of(new User("Walter", "WHITE", null), - matching().// - withIgnorePaths("age").// - withMatcher("firstname", startsWith()).// - withMatcher("lastname", ignoreCase())); + Example example = Example.of(new User("Walter", "WHITE", null), matching(). // + withIgnorePaths("age"). // + withMatcher("firstname", startsWith()). // + withMatcher("lastname", ignoreCase())); assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter); } @@ -114,11 +114,10 @@ public class UserRepositoryIntegrationTests { @Test public void configuringMatchersUsingLambdas() { - Example example = Example.of(new User("Walter", "WHITE", null), - matching().// - withIgnorePaths("age").// - withMatcher("firstname", matcher -> matcher.startsWith()).// - withMatcher("lastname", matcher -> matcher.ignoreCase())); + Example example = Example.of(new User("Walter", "WHITE", null), matching(). // + withIgnorePaths("age"). // + withMatcher("firstname", matcher -> matcher.startsWith()). // + withMatcher("lastname", matcher -> matcher.ignoreCase())); assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter); } @@ -130,7 +129,7 @@ public class UserRepositoryIntegrationTests { public void valueTransformer() { Example example = Example.of(new User(null, "White", 99), matching(). // - withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50)))); + withMatcher("age", matcher -> matcher.transform(value -> Optional.of(Integer.valueOf(50))))); assertThat(repository.findAll(example)).containsExactly(walter); } diff --git a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java index dbc76cb9..623340ef 100644 --- a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java +++ b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java @@ -24,6 +24,8 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc import static org.springframework.data.mongodb.core.query.Criteria.*; import static org.springframework.data.mongodb.core.query.Query.*; +import java.util.Optional; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -109,11 +111,10 @@ public class MongoOperationsIntegrationTests { @Test public void matchStartingStringsIgnoreCase() { - Example example = Example.of(new Person("Walter", "WHITE", null), - matching(). // - withIgnorePaths("age").// - withMatcher("firstname", startsWith()).// - withMatcher("lastname", ignoreCase())); + Example example = Example.of(new Person("Walter", "WHITE", null), matching(). // + withIgnorePaths("age").// + withMatcher("firstname", startsWith()).// + withMatcher("lastname", ignoreCase())); assertThat(operations.find(query(byExample(example)), Person.class), hasItems(flynn, walter)); } @@ -124,11 +125,10 @@ public class MongoOperationsIntegrationTests { @Test public void configuringMatchersUsingLambdas() { - Example example = Example.of(new Person("Walter", "WHITE", null), - matching().// - withIgnorePaths("age"). // - withMatcher("firstname", matcher -> matcher.startsWith()). // - withMatcher("lastname", matcher -> matcher.ignoreCase())); + Example example = Example.of(new Person("Walter", "WHITE", null), matching().// + withIgnorePaths("age"). // + withMatcher("firstname", matcher -> matcher.startsWith()). // + withMatcher("lastname", matcher -> matcher.ignoreCase())); assertThat(operations.find(query(byExample(example)), Person.class), hasItems(flynn, walter)); } @@ -140,7 +140,7 @@ public class MongoOperationsIntegrationTests { public void valueTransformer() { Example example = Example.of(new Person(null, "White", 99), matching(). // - withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50)))); + withMatcher("age", matcher -> matcher.transform(value -> Optional.of(Integer.valueOf(50))))); assertThat(operations.find(query(byExample(example)), Person.class), hasItems(walter)); } diff --git a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java index e5c2146b..d706cdc2 100644 --- a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java +++ b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java @@ -16,8 +16,10 @@ package example.springdata.mongodb.querybyexample; import static org.assertj.core.api.Assertions.*; -import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; import static org.springframework.data.domain.ExampleMatcher.*; +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; + +import java.util.Optional; import org.junit.Before; import org.junit.Test; @@ -25,7 +27,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Example; -import org.springframework.data.domain.ExampleMatcher.*; +import org.springframework.data.domain.ExampleMatcher.StringMatcher; import org.springframework.test.context.junit4.SpringRunner; /** @@ -85,7 +87,7 @@ public class UserRepositoryIntegrationTests { @Test public void substringMatching() { - Example example = Example.of(new Person("er", null, null), matching().// + Example example = Example.of(new Person("er", null, null), matching(). // withStringMatcher(StringMatcher.ENDING)); assertThat(repository.findAll(example)).containsExactlyInAnyOrder(skyler, walter); @@ -97,7 +99,7 @@ public class UserRepositoryIntegrationTests { @Test public void regexMatching() { - Example example = Example.of(new Person("(Skyl|Walt)er", null, null), matching().// + Example example = Example.of(new Person("(Skyl|Walt)er", null, null), matching(). // withMatcher("firstname", matcher -> matcher.regex())); assertThat(repository.findAll(example)).contains(skyler, walter); @@ -109,11 +111,10 @@ public class UserRepositoryIntegrationTests { @Test public void matchStartingStringsIgnoreCase() { - Example example = Example.of(new Person("Walter", "WHITE", null), - matching().// - withIgnorePaths("age").// - withMatcher("firstname", startsWith()).// - withMatcher("lastname", ignoreCase())); + Example example = Example.of(new Person("Walter", "WHITE", null), matching(). // + withIgnorePaths("age"). // + withMatcher("firstname", startsWith()). // + withMatcher("lastname", ignoreCase())); assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter); } @@ -124,11 +125,10 @@ public class UserRepositoryIntegrationTests { @Test public void configuringMatchersUsingLambdas() { - Example example = Example.of(new Person("Walter", "WHITE", null), - matching().// - withIgnorePaths("age").// - withMatcher("firstname", matcher -> matcher.startsWith()).// - withMatcher("lastname", matcher -> matcher.ignoreCase())); + Example example = Example.of(new Person("Walter", "WHITE", null), matching(). // + withIgnorePaths("age"). // + withMatcher("firstname", matcher -> matcher.startsWith()). // + withMatcher("lastname", matcher -> matcher.ignoreCase())); assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter); } @@ -140,7 +140,7 @@ public class UserRepositoryIntegrationTests { public void valueTransformer() { Example example = Example.of(new Person(null, "White", 99), matching(). // - withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50)))); + withMatcher("age", matcher -> matcher.transform(value -> Optional.of(Integer.valueOf(50))))); assertThat(repository.findAll(example)).containsExactlyInAnyOrder(walter); }