allow getTrips with limit directly from Query instance

This commit is contained in:
Stefan Kalscheuer 2022-11-21 14:22:20 +01:00
parent 7cb5aefb5b
commit 406fe076f1
Signed by: stefan
GPG Key ID: 3887EC2A53B55430
3 changed files with 29 additions and 2 deletions

View File

@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
### Security
* Updated dependencies
### Fixed
* Querying trips with limit directly from `Query` instance (#18)
### Misc
* Tested with JDK 19

View File

@ -225,7 +225,7 @@ public class UraClient implements Serializable {
/**
* Get list of trips with limit.
* If forStops() and/or forLines() has been called, those will be used as filter.
* If {@link #forStops(String...)} and/or {@link #forLines(String...)} has been called, those will be used as filter.
*
* @param limit Maximum number of results.
* @return List of trips.
@ -342,7 +342,7 @@ public class UraClient implements Serializable {
/**
* List available stopIDs.
* If forStops() and/or forLines() has been called, those will be used as filter.
* If {@link #forStops(String...)} and/or {@link #forLines(String...)} has been called, those will be used as filter.
*
* @param query The query.
* @return The list.
@ -642,6 +642,18 @@ public class UraClient implements Serializable {
return UraClient.this.getTrips(this);
}
/**
* Get trips for set filters with limit.
*
* @param limit Maximum number of results.
* @return List of matching trips.
* @throws UraClientException Error with API communication.
* @since 2.0.4
*/
public List<Trip> getTrips(final Integer limit) throws UraClientException {
return UraClient.this.getTrips(this, limit);
}
/**
* Get trips for set filters.
*

View File

@ -183,6 +183,12 @@ public class UraClientTest {
assertThat(trips.get(8).getVisitID(), is(30));
assertThat(trips.get(9).getStop().getId(), is("100002"));
// With limit.
trips = new UraClient(wireMock.baseUrl()).getTrips(5);
assertThat(trips, hasSize(5));
trips = new UraClient(wireMock.baseUrl()).getTrips(11);
assertThat(trips, hasSize(10));
// Repeat test for API V2.
mockHttpToFile(2, "instant_V2_trips_all.txt");
@ -242,6 +248,12 @@ public class UraClientTest {
assertThat(trips.get(2).getLineName(), is("25"));
assertThat(trips.get(3).getStop().getIndicator(), is("H.15"));
// With limit.
trips = new UraClient(wireMock.baseUrl())
.forStops("100000")
.getTrips(7);
assertThat(trips, hasSize(7));
// Get trips for stop name "Uniklinik" and verify some values.
mockHttpToFile(1, "instant_V1_trips_stop_name.txt");
trips = new UraClient(wireMock.baseUrl())