diff --git a/CHANGELOG.md b/CHANGELOG.md index f74a6dc..37e32cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/de/stklcode/pubtrans/ura/UraClient.java b/src/main/java/de/stklcode/pubtrans/ura/UraClient.java index 2794811..e097eb4 100644 --- a/src/main/java/de/stklcode/pubtrans/ura/UraClient.java +++ b/src/main/java/de/stklcode/pubtrans/ura/UraClient.java @@ -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 getTrips(final Integer limit) throws UraClientException { + return UraClient.this.getTrips(this, limit); + } + /** * Get trips for set filters. * diff --git a/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java b/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java index 795be5a..51e39d4 100644 --- a/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java +++ b/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java @@ -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())