|
1 | 1 | package com.baeldung.passenger; |
2 | 2 |
|
3 | | -import static org.hamcrest.MatcherAssert.assertThat; |
4 | | -import static org.hamcrest.Matchers.contains; |
5 | | -import static org.hamcrest.core.IsNot.not; |
6 | | -import static org.junit.Assert.assertEquals; |
7 | | -import static org.junit.Assert.assertTrue; |
8 | | - |
9 | | -import java.util.List; |
10 | | -import java.util.Optional; |
11 | | - |
12 | | -import javax.persistence.EntityManager; |
13 | | -import javax.persistence.PersistenceContext; |
14 | | - |
15 | 3 | import org.junit.Before; |
16 | 4 | import org.junit.Test; |
17 | 5 | import org.junit.runner.RunWith; |
|
24 | 12 | import org.springframework.data.domain.Sort; |
25 | 13 | import org.springframework.test.context.junit4.SpringRunner; |
26 | 14 |
|
| 15 | +import javax.persistence.EntityManager; |
| 16 | +import javax.persistence.PersistenceContext; |
| 17 | +import java.util.List; |
| 18 | +import java.util.Optional; |
| 19 | + |
| 20 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 21 | +import static org.hamcrest.Matchers.contains; |
| 22 | +import static org.hamcrest.core.IsNot.not; |
| 23 | +import static org.junit.Assert.assertEquals; |
| 24 | +import static org.junit.Assert.assertTrue; |
| 25 | + |
27 | 26 | @DataJpaTest |
28 | 27 | @RunWith(SpringRunner.class) |
29 | 28 | public class PassengerRepositoryIntegrationTest { |
@@ -152,18 +151,36 @@ public void givenPassengers_whenFindByIgnoringMatcher_thenExpectedReturned() { |
152 | 151 | Passenger fred = Passenger.from("Fred", "Bloggs", 22); |
153 | 152 | Passenger siya = Passenger.from("Siya", "Kolisi", 85); |
154 | 153 | Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); |
155 | | - |
| 154 | + |
156 | 155 | ExampleMatcher ignoringExampleMatcher = ExampleMatcher.matchingAny().withMatcher("lastName", |
157 | | - ExampleMatcher.GenericPropertyMatchers.startsWith().ignoreCase()).withIgnorePaths("firstName", "seatNumber"); |
158 | | - |
| 156 | + ExampleMatcher.GenericPropertyMatchers.startsWith().ignoreCase()).withIgnorePaths("firstName", "seatNumber"); |
| 157 | + |
159 | 158 | Example<Passenger> example = Example.of(Passenger.from(null, "b", null), |
160 | | - ignoringExampleMatcher); |
161 | | - |
| 159 | + ignoringExampleMatcher); |
| 160 | + |
162 | 161 | List<Passenger> passengers = repository.findAll(example); |
163 | | - |
| 162 | + |
164 | 163 | assertThat(passengers, contains(fred, ricki)); |
165 | 164 | assertThat(passengers, not(contains(jill))); |
166 | 165 | assertThat(passengers, not(contains(eve))); |
167 | 166 | assertThat(passengers, not(contains(siya))); |
168 | 167 | } |
| 168 | + |
| 169 | + @Test |
| 170 | + public void givenPassengers_whenMatchingIgnoreCase_thenExpectedReturned() { |
| 171 | + Passenger jill = Passenger.from("Jill", "Smith", 50); |
| 172 | + Passenger eve = Passenger.from("Eve", "Jackson", 95); |
| 173 | + Passenger fred = Passenger.from("Fred", "Bloggs", 22); |
| 174 | + Passenger siya = Passenger.from("Siya", "Kolisi", 85); |
| 175 | + Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); |
| 176 | + |
| 177 | + List<Passenger> passengers = repository.findByFirstNameIgnoreCase("FRED"); |
| 178 | + |
| 179 | + assertThat(passengers, contains(fred)); |
| 180 | + assertThat(passengers, not(contains(eve))); |
| 181 | + assertThat(passengers, not(contains(siya))); |
| 182 | + assertThat(passengers, not(contains(jill))); |
| 183 | + assertThat(passengers, not(contains(ricki))); |
| 184 | + |
| 185 | + } |
169 | 186 | } |
0 commit comments