Skip to content

Commit 20f6963

Browse files
schauderodrotbohm
authored andcommitted
spring-projects#297 - Fixed failing test due to repository methods now returning Optional.
Also migrated Tests to AssertJ.
1 parent 5fcec44 commit 20f6963

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

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

Lines changed: 11 additions & 12 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,19 +15,17 @@
1515
*/
1616
package example.springdata.jpa.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
import org.springframework.transaction.annotation.Transactional;
3331

@@ -36,6 +34,7 @@
3634
*
3735
* @author Mark Paluch
3836
* @author Oliver Gierke
37+
* @author Jens Schauder
3938
*/
4039
@SuppressWarnings("unused")
4140
@RunWith(SpringRunner.class)
@@ -67,7 +66,7 @@ public void countBySimpleExample() {
6766

6867
Example<User> example = Example.of(new User(null, "White", null));
6968

70-
assertThat(repository.count(example), is(3L));
69+
assertThat(repository.count(example)).isEqualTo(3L);
7170
}
7271

7372
/**
@@ -79,7 +78,7 @@ public void ignorePropertiesAndMatchByAge() {
7978
Example<User> example = Example.of(flynn, matching().//
8079
withIgnorePaths("firstname", "lastname"));
8180

82-
assertThat(repository.findOne(example), is(flynn));
81+
assertThat(repository.findOne(example)).contains(flynn);
8382
}
8483

8584
/**
@@ -91,7 +90,7 @@ public void substringMatching() {
9190
Example<User> example = Example.of(new User("er", null, null), matching().//
9291
withStringMatcher(StringMatcher.ENDING));
9392

94-
assertThat(repository.findAll(example), hasItems(skyler, walter));
93+
assertThat(repository.findAll(example)).containsExactly(skyler, walter);
9594
}
9695

9796
/**
@@ -106,7 +105,7 @@ public void matchStartingStringsIgnoreCase() {
106105
withMatcher("firstname", startsWith()).//
107106
withMatcher("lastname", ignoreCase()));
108107

109-
assertThat(repository.findAll(example), hasItems(flynn, walter));
108+
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter);
110109
}
111110

112111
/**
@@ -121,7 +120,7 @@ public void configuringMatchersUsingLambdas() {
121120
withMatcher("firstname", matcher -> matcher.startsWith()).//
122121
withMatcher("lastname", matcher -> matcher.ignoreCase()));
123122

124-
assertThat(repository.findAll(example), hasItems(flynn, walter));
123+
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter);
125124
}
126125

127126
/**
@@ -133,6 +132,6 @@ public void valueTransformer() {
133132
Example<User> example = Example.of(new User(null, "White", 99), matching(). //
134133
withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));
135134

136-
assertThat(repository.findAll(example), hasItems(walter));
135+
assertThat(repository.findAll(example)).containsExactly(walter);
137136
}
138137
}

0 commit comments

Comments
 (0)