From 8748dd883b5dbf3d30f6481b1e26cb7b2650b809 Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Mon, 21 Nov 2022 15:17:35 +0100 Subject: [PATCH] allow getTrips with limit directly from Query instance backported from commit 406fe076f1763f3757cfdd4bceb3568676679b03 --- CHANGELOG.md | 6 ++++++ pom.xml | 2 +- .../java/de/stklcode/pubtrans/ura/UraClient.java | 15 +++++++++++++-- .../de/stklcode/pubtrans/ura/UraClientTest.java | 12 ++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e09784..c642c60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog All notable changes to this project will be documented in this file. +## unreleased + +### Fixed +* Querying trips with limit directly from `Query` instance (#19) + + ## 1.3.2 - 2022-08-30 ### Improvements diff --git a/pom.xml b/pom.xml index 4dca89a..3b5625b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ de.stklcode.pubtrans juraclient - 1.3.2 + 1.3.3-SNAPSHOT UTF-8 diff --git a/src/main/java/de/stklcode/pubtrans/ura/UraClient.java b/src/main/java/de/stklcode/pubtrans/ura/UraClient.java index efbc8cf..39c772b 100644 --- a/src/main/java/de/stklcode/pubtrans/ura/UraClient.java +++ b/src/main/java/de/stklcode/pubtrans/ura/UraClient.java @@ -192,7 +192,7 @@ public class UraClient implements Serializable { /** * Get list of trips. - * 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. * * @return List of trips. */ @@ -202,7 +202,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. @@ -566,6 +566,17 @@ public class UraClient implements Serializable { return UraClient.this.getTrips(this); } + /** + * Get trips for set filters. + * + * @param limit Maximum number of results. + * @return List of matching trips. + * @since 1.3.3 + */ + public List getTrips(final Integer limit) { + 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 e90f081..4ff940b 100644 --- a/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java +++ b/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java @@ -189,6 +189,12 @@ class UraClientTest { assertThat(trips.get(8).getVisitID(), is(30)); assertThat(trips.get(9).getStop().getId(), is("100002")); + // With limit. + trips = new UraClient(httpMock.baseUrl()).getTrips(5); + assertThat(trips, hasSize(5)); + trips = new UraClient(httpMock.baseUrl()).getTrips(11); + assertThat(trips, hasSize(10)); + // Repeat test for API V2. mockHttpToFile(2, "instant_V2_trips_all.txt"); @@ -239,6 +245,12 @@ class UraClientTest { assertThat(trips.get(2).getLineName(), is("25")); assertThat(trips.get(3).getStop().getIndicator(), is("H.15")); + // With limit. + trips = new UraClient(httpMock.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(httpMock.baseUrl())