Skip to content

Commit b87336b

Browse files
committed
spring-projects#297 - Update to changes in ExampleMatcher API.
1 parent 80b70e6 commit b87336b

File tree

3 files changed

+41
-42
lines changed

3 files changed

+41
-42
lines changed

jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616
package example.springdata.jpa.querybyexample;
1717

1818
import static org.assertj.core.api.Assertions.*;
19-
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*;
2019
import static org.springframework.data.domain.ExampleMatcher.*;
20+
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*;
21+
22+
import java.util.Optional;
2123

2224
import org.junit.Before;
2325
import org.junit.Test;
2426
import org.junit.runner.RunWith;
2527
import org.springframework.beans.factory.annotation.Autowired;
2628
import org.springframework.boot.test.context.SpringBootTest;
2729
import org.springframework.data.domain.Example;
28-
import org.springframework.data.domain.ExampleMatcher.*;
30+
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
2931
import org.springframework.test.context.junit4.SpringRunner;
3032
import org.springframework.transaction.annotation.Transactional;
3133

@@ -36,7 +38,6 @@
3638
* @author Oliver Gierke
3739
* @author Jens Schauder
3840
*/
39-
@SuppressWarnings("unused")
4041
@RunWith(SpringRunner.class)
4142
@Transactional
4243
@SpringBootTest
@@ -75,7 +76,7 @@ public void countBySimpleExample() {
7576
@Test
7677
public void ignorePropertiesAndMatchByAge() {
7778

78-
Example<User> example = Example.of(flynn, matching().//
79+
Example<User> example = Example.of(flynn, matching(). //
7980
withIgnorePaths("firstname", "lastname"));
8081

8182
assertThat(repository.findOne(example)).contains(flynn);
@@ -87,7 +88,7 @@ public void ignorePropertiesAndMatchByAge() {
8788
@Test
8889
public void substringMatching() {
8990

90-
Example<User> example = Example.of(new User("er", null, null), matching().//
91+
Example<User> example = Example.of(new User("er", null, null), matching(). //
9192
withStringMatcher(StringMatcher.ENDING));
9293

9394
assertThat(repository.findAll(example)).containsExactly(skyler, walter);
@@ -99,11 +100,10 @@ public void substringMatching() {
99100
@Test
100101
public void matchStartingStringsIgnoreCase() {
101102

102-
Example<User> example = Example.of(new User("Walter", "WHITE", null),
103-
matching().//
104-
withIgnorePaths("age").//
105-
withMatcher("firstname", startsWith()).//
106-
withMatcher("lastname", ignoreCase()));
103+
Example<User> example = Example.of(new User("Walter", "WHITE", null), matching(). //
104+
withIgnorePaths("age"). //
105+
withMatcher("firstname", startsWith()). //
106+
withMatcher("lastname", ignoreCase()));
107107

108108
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter);
109109
}
@@ -114,11 +114,10 @@ public void matchStartingStringsIgnoreCase() {
114114
@Test
115115
public void configuringMatchersUsingLambdas() {
116116

117-
Example<User> example = Example.of(new User("Walter", "WHITE", null),
118-
matching().//
119-
withIgnorePaths("age").//
120-
withMatcher("firstname", matcher -> matcher.startsWith()).//
121-
withMatcher("lastname", matcher -> matcher.ignoreCase()));
117+
Example<User> example = Example.of(new User("Walter", "WHITE", null), matching(). //
118+
withIgnorePaths("age"). //
119+
withMatcher("firstname", matcher -> matcher.startsWith()). //
120+
withMatcher("lastname", matcher -> matcher.ignoreCase()));
122121

123122
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter);
124123
}
@@ -130,7 +129,7 @@ public void configuringMatchersUsingLambdas() {
130129
public void valueTransformer() {
131130

132131
Example<User> example = Example.of(new User(null, "White", 99), matching(). //
133-
withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));
132+
withMatcher("age", matcher -> matcher.transform(value -> Optional.of(Integer.valueOf(50)))));
134133

135134
assertThat(repository.findAll(example)).containsExactly(walter);
136135
}

mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import static org.springframework.data.mongodb.core.query.Criteria.*;
2525
import static org.springframework.data.mongodb.core.query.Query.*;
2626

27+
import java.util.Optional;
28+
2729
import org.junit.Before;
2830
import org.junit.Test;
2931
import org.junit.runner.RunWith;
@@ -109,11 +111,10 @@ public void regexMatching() {
109111
@Test
110112
public void matchStartingStringsIgnoreCase() {
111113

112-
Example<Person> example = Example.of(new Person("Walter", "WHITE", null),
113-
matching(). //
114-
withIgnorePaths("age").//
115-
withMatcher("firstname", startsWith()).//
116-
withMatcher("lastname", ignoreCase()));
114+
Example<Person> example = Example.of(new Person("Walter", "WHITE", null), matching(). //
115+
withIgnorePaths("age").//
116+
withMatcher("firstname", startsWith()).//
117+
withMatcher("lastname", ignoreCase()));
117118

118119
assertThat(operations.find(query(byExample(example)), Person.class), hasItems(flynn, walter));
119120
}
@@ -124,11 +125,10 @@ public void matchStartingStringsIgnoreCase() {
124125
@Test
125126
public void configuringMatchersUsingLambdas() {
126127

127-
Example<Person> example = Example.of(new Person("Walter", "WHITE", null),
128-
matching().//
129-
withIgnorePaths("age"). //
130-
withMatcher("firstname", matcher -> matcher.startsWith()). //
131-
withMatcher("lastname", matcher -> matcher.ignoreCase()));
128+
Example<Person> example = Example.of(new Person("Walter", "WHITE", null), matching().//
129+
withIgnorePaths("age"). //
130+
withMatcher("firstname", matcher -> matcher.startsWith()). //
131+
withMatcher("lastname", matcher -> matcher.ignoreCase()));
132132

133133
assertThat(operations.find(query(byExample(example)), Person.class), hasItems(flynn, walter));
134134
}
@@ -140,7 +140,7 @@ public void configuringMatchersUsingLambdas() {
140140
public void valueTransformer() {
141141

142142
Example<Person> example = Example.of(new Person(null, "White", 99), matching(). //
143-
withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));
143+
withMatcher("age", matcher -> matcher.transform(value -> Optional.of(Integer.valueOf(50)))));
144144

145145
assertThat(operations.find(query(byExample(example)), Person.class), hasItems(walter));
146146
}

mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616
package example.springdata.mongodb.querybyexample;
1717

1818
import static org.assertj.core.api.Assertions.*;
19-
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*;
2019
import static org.springframework.data.domain.ExampleMatcher.*;
20+
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*;
21+
22+
import java.util.Optional;
2123

2224
import org.junit.Before;
2325
import org.junit.Test;
2426
import org.junit.runner.RunWith;
2527
import org.springframework.beans.factory.annotation.Autowired;
2628
import org.springframework.boot.test.context.SpringBootTest;
2729
import org.springframework.data.domain.Example;
28-
import org.springframework.data.domain.ExampleMatcher.*;
30+
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
2931
import org.springframework.test.context.junit4.SpringRunner;
3032

3133
/**
@@ -85,7 +87,7 @@ public void ignorePropertiesAndMatchByAge() {
8587
@Test
8688
public void substringMatching() {
8789

88-
Example<Person> example = Example.of(new Person("er", null, null), matching().//
90+
Example<Person> example = Example.of(new Person("er", null, null), matching(). //
8991
withStringMatcher(StringMatcher.ENDING));
9092

9193
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(skyler, walter);
@@ -97,7 +99,7 @@ public void substringMatching() {
9799
@Test
98100
public void regexMatching() {
99101

100-
Example<Person> example = Example.of(new Person("(Skyl|Walt)er", null, null), matching().//
102+
Example<Person> example = Example.of(new Person("(Skyl|Walt)er", null, null), matching(). //
101103
withMatcher("firstname", matcher -> matcher.regex()));
102104

103105
assertThat(repository.findAll(example)).contains(skyler, walter);
@@ -109,11 +111,10 @@ public void regexMatching() {
109111
@Test
110112
public void matchStartingStringsIgnoreCase() {
111113

112-
Example<Person> example = Example.of(new Person("Walter", "WHITE", null),
113-
matching().//
114-
withIgnorePaths("age").//
115-
withMatcher("firstname", startsWith()).//
116-
withMatcher("lastname", ignoreCase()));
114+
Example<Person> example = Example.of(new Person("Walter", "WHITE", null), matching(). //
115+
withIgnorePaths("age"). //
116+
withMatcher("firstname", startsWith()). //
117+
withMatcher("lastname", ignoreCase()));
117118

118119
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter);
119120
}
@@ -124,11 +125,10 @@ public void matchStartingStringsIgnoreCase() {
124125
@Test
125126
public void configuringMatchersUsingLambdas() {
126127

127-
Example<Person> example = Example.of(new Person("Walter", "WHITE", null),
128-
matching().//
129-
withIgnorePaths("age").//
130-
withMatcher("firstname", matcher -> matcher.startsWith()).//
131-
withMatcher("lastname", matcher -> matcher.ignoreCase()));
128+
Example<Person> example = Example.of(new Person("Walter", "WHITE", null), matching(). //
129+
withIgnorePaths("age"). //
130+
withMatcher("firstname", matcher -> matcher.startsWith()). //
131+
withMatcher("lastname", matcher -> matcher.ignoreCase()));
132132

133133
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter);
134134
}
@@ -140,7 +140,7 @@ public void configuringMatchersUsingLambdas() {
140140
public void valueTransformer() {
141141

142142
Example<Person> example = Example.of(new Person(null, "White", 99), matching(). //
143-
withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));
143+
withMatcher("age", matcher -> matcher.transform(value -> Optional.of(Integer.valueOf(50)))));
144144

145145
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(walter);
146146
}

0 commit comments

Comments
 (0)