Response types checked
This commit is contained in:
parent
4b6b09ce52
commit
727e7bd171
@ -40,6 +40,9 @@ public class UraClient {
|
||||
private static final String PAR_TRIP_ID = "TripID";
|
||||
private static final String PAR_ESTTIME = "EstimatedTime";
|
||||
|
||||
private static final Integer RES_TYPE_STOP = 0;
|
||||
private static final Integer RES_TYPE_PREDICTION = 1;
|
||||
|
||||
|
||||
private static final String[] REQUEST_STOP = {PAR_STOP_NAME, PAR_STOP_ID, PAR_STOP_INDICATOR, PAR_STOP_STATE, PAR_GEOLOCATION};
|
||||
private static final String[] REQUEST_TRIP = {PAR_STOP_NAME, PAR_STOP_ID, PAR_STOP_INDICATOR, PAR_STOP_STATE, PAR_GEOLOCATION,
|
||||
@ -142,13 +145,11 @@ public class UraClient {
|
||||
try (InputStream is = requestInstant(REQUEST_TRIP, stops, lines);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
|
||||
String line;
|
||||
boolean first = false;
|
||||
while ((line = br.readLine()) != null) {
|
||||
if (!first) {
|
||||
first = true;
|
||||
continue;
|
||||
}
|
||||
trips.add(new Trip(mapper.readValue(line, List.class)));
|
||||
while ((line = br.readLine()) != null && (limit == null || trips.size() < limit)) {
|
||||
List l = mapper.readValue(line, List.class);
|
||||
/* Check if result exists and has correct response type */
|
||||
if (l != null && l.size() > 0 && l.get(0).equals(RES_TYPE_PREDICTION))
|
||||
trips.add(new Trip(l));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -166,13 +167,11 @@ public class UraClient {
|
||||
try (InputStream is = requestInstant(REQUEST_STOP, null, null);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
|
||||
String line;
|
||||
boolean first = false;
|
||||
while ((line = br.readLine()) != null) {
|
||||
if (!first) {
|
||||
first = true;
|
||||
continue;
|
||||
}
|
||||
stops.add(new Stop(mapper.readValue(line, List.class)));
|
||||
List l = mapper.readValue(line, List.class);
|
||||
/* Check if result exists and has correct response type */
|
||||
if (l != null && l.size() > 0 && l.get(0).equals(RES_TYPE_STOP))
|
||||
stops.add(new Stop(l));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -63,6 +63,11 @@ public class UraClientTest {
|
||||
assertThat(trips.get(7).getEstimatedTime(), is(1482854580000L));
|
||||
assertThat(trips.get(8).getVisitID(), is(30));
|
||||
assertThat(trips.get(9).getStop().getId(), is("100002"));
|
||||
|
||||
/* Get limited number of trips */
|
||||
PowerMockito.when(mockURL.openStream()).thenReturn(getClass().getResourceAsStream("instant_trips_all.txt"));
|
||||
trips = new UraClient("mocked").getTrips(5);
|
||||
assertThat(trips, hasSize(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user