Skip to content

Commit

Permalink
allow getTrips with limit directly from Query instance
Browse files Browse the repository at this point in the history
  • Loading branch information
stklcode committed Nov 21, 2022
1 parent 7cb5aef commit 406fe07
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 14 additions & 2 deletions src/main/java/de/stklcode/pubtrans/ura/UraClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public List<Trip> getTrips() throws UraClientException {

/**
* 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.
Expand Down Expand Up @@ -342,7 +342,7 @@ public List<Stop> getStops() throws UraClientException {

/**
* 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.
Expand Down Expand Up @@ -642,6 +642,18 @@ public List<Trip> getTrips() throws UraClientException {
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.
*
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ public void getTripsTest() throws UraClientException {
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");

Expand Down Expand Up @@ -242,6 +248,12 @@ public void getTripsForStopTest() throws UraClientException {
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())
Expand Down

0 comments on commit 406fe07

Please sign in to comment.