Merge pull request #5774 from eugenp/BAEL-2331-v2
add data order methods
This commit is contained in:
commit
469cd9ec25
|
@ -1,5 +1,6 @@
|
||||||
package com.baeldung.passenger;
|
package com.baeldung.passenger;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -9,4 +10,8 @@ interface PassengerRepository extends JpaRepository<Passenger, Long>, CustomPass
|
||||||
Passenger findFirstByOrderBySeatNumberAsc();
|
Passenger findFirstByOrderBySeatNumberAsc();
|
||||||
|
|
||||||
List<Passenger> findByOrderBySeatNumberAsc();
|
List<Passenger> findByOrderBySeatNumberAsc();
|
||||||
|
|
||||||
|
List<Passenger> findByLastNameOrderBySeatNumberAsc(String lastName);
|
||||||
|
|
||||||
|
List<Passenger> findByLastName(String lastName, Sort sort);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class PassengerRepositoryIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSeveralPassengersWhenOrderedBySeatNumberAscThenThePassengersReturnedInCorrectOrder() {
|
public void givenPassengers_whenOrderedBySeatNumberAsc_thenCorrectOrder() {
|
||||||
Passenger fred = Passenger.from("Fred", "Bloggs", 22);
|
Passenger fred = Passenger.from("Fred", "Bloggs", 22);
|
||||||
Passenger ricki = Passenger.from("Ricki", "Bobbie", 36);
|
Passenger ricki = Passenger.from("Ricki", "Bobbie", 36);
|
||||||
Passenger jill = Passenger.from("Jill", "Smith", 50);
|
Passenger jill = Passenger.from("Jill", "Smith", 50);
|
||||||
|
@ -83,7 +83,7 @@ public class PassengerRepositoryIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSeveralPassengersWhenFindAllWithSortBySeatNumberAscThenReturnPassengersInCorrectOrder() {
|
public void givenPassengers_whenFindAllWithSortBySeatNumberAsc_thenCorrectOrder() {
|
||||||
Passenger fred = Passenger.from("Fred", "Bloggs", 22);
|
Passenger fred = Passenger.from("Fred", "Bloggs", 22);
|
||||||
Passenger ricki = Passenger.from("Ricki", "Bobbie", 36);
|
Passenger ricki = Passenger.from("Ricki", "Bobbie", 36);
|
||||||
Passenger jill = Passenger.from("Jill", "Smith", 50);
|
Passenger jill = Passenger.from("Jill", "Smith", 50);
|
||||||
|
@ -94,4 +94,5 @@ public class PassengerRepositoryIntegrationTest {
|
||||||
|
|
||||||
assertThat(passengers, contains(fred, ricki, jill, siya, eve));
|
assertThat(passengers, contains(fred, ricki, jill, siya, eve));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue