Skip to content

Commit 80b70e6

Browse files
schauderodrotbohm
authored andcommitted
spring-projects#297 - Fixed failing test due to repository methods now returning Optional.
Also migrated Tests to AssertJ. Fixed compilation failure due to changed API of CollectionOptions
1 parent 20f6963 commit 80b70e6

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,26 +15,25 @@
1515
*/
1616
package example.springdata.mongodb.querybyexample;
1717

18-
import static org.hamcrest.CoreMatchers.*;
19-
import static org.junit.Assert.*;
20-
import static org.springframework.data.domain.ExampleMatcher.*;
18+
import static org.assertj.core.api.Assertions.*;
2119
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*;
22-
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
20+
import static org.springframework.data.domain.ExampleMatcher.*;
2321

2422
import org.junit.Before;
2523
import org.junit.Test;
2624
import org.junit.runner.RunWith;
2725
import org.springframework.beans.factory.annotation.Autowired;
2826
import org.springframework.boot.test.context.SpringBootTest;
2927
import org.springframework.data.domain.Example;
30-
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
28+
import org.springframework.data.domain.ExampleMatcher.*;
3129
import org.springframework.test.context.junit4.SpringRunner;
3230

3331
/**
3432
* Integration test showing the usage of MongoDB Query-by-Example support through Spring Data repositories.
3533
*
3634
* @author Mark Paluch
3735
* @author Oliver Gierke
36+
* @author Jens Schauder
3837
*/
3938
@SuppressWarnings("unused")
4039
@RunWith(SpringRunner.class)
@@ -65,7 +64,7 @@ public void countBySimpleExample() {
6564

6665
Example<Person> example = Example.of(new Person(null, "White", null));
6766

68-
assertThat(repository.count(example), is(3L));
67+
assertThat(repository.count(example)).isEqualTo(3L);
6968
}
7069

7170
/**
@@ -77,7 +76,7 @@ public void ignorePropertiesAndMatchByAge() {
7776
Example<Person> example = Example.of(flynn, matching(). //
7877
withIgnorePaths("firstname", "lastname"));
7978

80-
assertThat(repository.findOne(example), is(flynn));
79+
assertThat(repository.findOne(example)).contains(flynn);
8180
}
8281

8382
/**
@@ -89,7 +88,7 @@ public void substringMatching() {
8988
Example<Person> example = Example.of(new Person("er", null, null), matching().//
9089
withStringMatcher(StringMatcher.ENDING));
9190

92-
assertThat(repository.findAll(example), hasItems(skyler, walter));
91+
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(skyler, walter);
9392
}
9493

9594
/**
@@ -101,7 +100,7 @@ public void regexMatching() {
101100
Example<Person> example = Example.of(new Person("(Skyl|Walt)er", null, null), matching().//
102101
withMatcher("firstname", matcher -> matcher.regex()));
103102

104-
assertThat(repository.findAll(example), hasItems(skyler, walter));
103+
assertThat(repository.findAll(example)).contains(skyler, walter);
105104
}
106105

107106
/**
@@ -116,7 +115,7 @@ public void matchStartingStringsIgnoreCase() {
116115
withMatcher("firstname", startsWith()).//
117116
withMatcher("lastname", ignoreCase()));
118117

119-
assertThat(repository.findAll(example), hasItems(flynn, walter));
118+
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter);
120119
}
121120

122121
/**
@@ -131,7 +130,7 @@ public void configuringMatchersUsingLambdas() {
131130
withMatcher("firstname", matcher -> matcher.startsWith()).//
132131
withMatcher("lastname", matcher -> matcher.ignoreCase()));
133132

134-
assertThat(repository.findAll(example), hasItems(flynn, walter));
133+
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter);
135134
}
136135

137136
/**
@@ -143,6 +142,6 @@ public void valueTransformer() {
143142
Example<Person> example = Example.of(new Person(null, "White", 99), matching(). //
144143
withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));
145144

146-
assertThat(repository.findAll(example), hasItems(walter));
145+
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(walter);
147146
}
148147
}

mongodb/reactive/src/test/java/example/springdata/mongodb/people/ReactivePersonRepositoryIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void setUp() {
5050

5151
operations.collectionExists(Person.class) //
5252
.flatMap(exists -> exists ? operations.dropCollection(Person.class) : Mono.just(exists)) //
53-
.flatMap(o -> operations.createCollection(Person.class, new CollectionOptions(1024 * 1024, 100, true))) //
53+
.flatMap(o -> operations.createCollection(Person.class, CollectionOptions.empty().size(1024 * 1024).maxDocuments( 100).capped())) //
5454
.then() //
5555
.block();
5656

mongodb/reactive/src/test/java/example/springdata/mongodb/people/RxJava1PersonRepositoryIntegrationTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@
4141
* reactive flavors.
4242
*
4343
* @author Mark Paluch
44+
* @author Jens Schauder
4445
*/
4546
@RunWith(SpringRunner.class)
4647
@SpringBootTest
@@ -54,7 +55,7 @@ public void setUp() {
5455

5556
operations.collectionExists(Person.class) //
5657
.flatMap(exists -> exists ? operations.dropCollection(Person.class) : Mono.just(exists)) //
57-
.flatMap(o -> operations.createCollection(Person.class, new CollectionOptions(1024 * 1024, 100, true))) //
58+
.flatMap(o -> operations.createCollection(Person.class, CollectionOptions.empty().size(1024 * 1024).maxDocuments(100).capped())) //
5859
.then() //
5960
.block();
6061

0 commit comments

Comments
 (0)