@Test public void testGetBestTransportInTimeTransit() { DirectionsRoute[] car = new DirectionsRoute[1]; car[0] = this.data.carRoutes[5]; DirectionsRoute[] transport = new DirectionsRoute[1]; transport[0] = this.data.transportRoutes[6]; DirectionsRoute[] bike = new DirectionsRoute[1]; bike[0] = this.data.bicycleRoutes[1]; doReturn(car).when(this.directionsApiCalls).fromToWithDepartureTime("A", "B", TravelMode.DRIVING, new DateTime(0)); doReturn(transport).when(this.directionsApiCalls).fromToWithDepartureTime("A", "B", TravelMode.TRANSIT, new DateTime(0)); doReturn(bike).when(this.directionsApiCalls).fromToWithDepartureTime("A", "B", TravelMode.BICYCLING, new DateTime(0)); BestTransportResult result = this.logic.getBestTransportInTime("A", "B", new DateTime(0)); assertThat(result.getMode(), equalTo(TravelMode.TRANSIT)); assertThat(result.getRoute(), equalTo(transport[0])); verify(this.directionsApiCalls).fromToWithDepartureTime("A", "B", TravelMode.DRIVING, new DateTime(0)); verify(this.directionsApiCalls).fromToWithDepartureTime("A", "B", TravelMode.TRANSIT, new DateTime(0)); verify(this.directionsApiCalls).fromToWithDepartureTime("A", "B", TravelMode.BICYCLING, new DateTime(0)); }
public BestTransportResult getBestTransportInTime(String origin, String destination, ReadableInstant departureTime) { EnumMap<TravelMode, DirectionsRoute> routesOfTravelModes = new EnumMap<>(TravelMode.class); routesOfTravelModes.put(TravelMode.DRIVING, findBestRoute( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.DRIVING, departureTime))); routesOfTravelModes.put(TravelMode.TRANSIT, findBestArrivalTime( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.TRANSIT, departureTime))); routesOfTravelModes.put(TravelMode.BICYCLING, findBestRoute( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.BICYCLING, departureTime))); long bestTime = Long.MAX_VALUE; TravelMode bestTravelMode = null; long time; if (routesOfTravelModes.get(TravelMode.DRIVING) != null) { time = new DateTime(departureTime) .plusSeconds(Math.toIntExact( routesOfTravelModes.get(TravelMode.DRIVING).legs[0].durationInTraffic.inSeconds)) .getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.DRIVING; bestTime = time; } } if (routesOfTravelModes.get(TravelMode.TRANSIT) != null) { time = routesOfTravelModes.get(TravelMode.TRANSIT).legs[0].arrivalTime.getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.TRANSIT; bestTime = time; } } if (routesOfTravelModes.get(TravelMode.BICYCLING) != null) { time = new DateTime(departureTime) .plusSeconds( Math.toIntExact(routesOfTravelModes.get(TravelMode.BICYCLING).legs[0].duration.inSeconds)) .getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.BICYCLING; } } if (bestTravelMode != null) { return new BestTransportResult(bestTravelMode, routesOfTravelModes.get(bestTravelMode)); } return null; }
DirectionApiLogic { public BestTransportResult getBestTransportInTime(String origin, String destination, ReadableInstant departureTime) { EnumMap<TravelMode, DirectionsRoute> routesOfTravelModes = new EnumMap<>(TravelMode.class); routesOfTravelModes.put(TravelMode.DRIVING, findBestRoute( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.DRIVING, departureTime))); routesOfTravelModes.put(TravelMode.TRANSIT, findBestArrivalTime( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.TRANSIT, departureTime))); routesOfTravelModes.put(TravelMode.BICYCLING, findBestRoute( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.BICYCLING, departureTime))); long bestTime = Long.MAX_VALUE; TravelMode bestTravelMode = null; long time; if (routesOfTravelModes.get(TravelMode.DRIVING) != null) { time = new DateTime(departureTime) .plusSeconds(Math.toIntExact( routesOfTravelModes.get(TravelMode.DRIVING).legs[0].durationInTraffic.inSeconds)) .getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.DRIVING; bestTime = time; } } if (routesOfTravelModes.get(TravelMode.TRANSIT) != null) { time = routesOfTravelModes.get(TravelMode.TRANSIT).legs[0].arrivalTime.getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.TRANSIT; bestTime = time; } } if (routesOfTravelModes.get(TravelMode.BICYCLING) != null) { time = new DateTime(departureTime) .plusSeconds( Math.toIntExact(routesOfTravelModes.get(TravelMode.BICYCLING).legs[0].duration.inSeconds)) .getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.BICYCLING; } } if (bestTravelMode != null) { return new BestTransportResult(bestTravelMode, routesOfTravelModes.get(bestTravelMode)); } return null; } }
DirectionApiLogic { public BestTransportResult getBestTransportInTime(String origin, String destination, ReadableInstant departureTime) { EnumMap<TravelMode, DirectionsRoute> routesOfTravelModes = new EnumMap<>(TravelMode.class); routesOfTravelModes.put(TravelMode.DRIVING, findBestRoute( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.DRIVING, departureTime))); routesOfTravelModes.put(TravelMode.TRANSIT, findBestArrivalTime( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.TRANSIT, departureTime))); routesOfTravelModes.put(TravelMode.BICYCLING, findBestRoute( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.BICYCLING, departureTime))); long bestTime = Long.MAX_VALUE; TravelMode bestTravelMode = null; long time; if (routesOfTravelModes.get(TravelMode.DRIVING) != null) { time = new DateTime(departureTime) .plusSeconds(Math.toIntExact( routesOfTravelModes.get(TravelMode.DRIVING).legs[0].durationInTraffic.inSeconds)) .getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.DRIVING; bestTime = time; } } if (routesOfTravelModes.get(TravelMode.TRANSIT) != null) { time = routesOfTravelModes.get(TravelMode.TRANSIT).legs[0].arrivalTime.getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.TRANSIT; bestTime = time; } } if (routesOfTravelModes.get(TravelMode.BICYCLING) != null) { time = new DateTime(departureTime) .plusSeconds( Math.toIntExact(routesOfTravelModes.get(TravelMode.BICYCLING).legs[0].duration.inSeconds)) .getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.BICYCLING; } } if (bestTravelMode != null) { return new BestTransportResult(bestTravelMode, routesOfTravelModes.get(bestTravelMode)); } return null; }  }
DirectionApiLogic { public BestTransportResult getBestTransportInTime(String origin, String destination, ReadableInstant departureTime) { EnumMap<TravelMode, DirectionsRoute> routesOfTravelModes = new EnumMap<>(TravelMode.class); routesOfTravelModes.put(TravelMode.DRIVING, findBestRoute( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.DRIVING, departureTime))); routesOfTravelModes.put(TravelMode.TRANSIT, findBestArrivalTime( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.TRANSIT, departureTime))); routesOfTravelModes.put(TravelMode.BICYCLING, findBestRoute( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.BICYCLING, departureTime))); long bestTime = Long.MAX_VALUE; TravelMode bestTravelMode = null; long time; if (routesOfTravelModes.get(TravelMode.DRIVING) != null) { time = new DateTime(departureTime) .plusSeconds(Math.toIntExact( routesOfTravelModes.get(TravelMode.DRIVING).legs[0].durationInTraffic.inSeconds)) .getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.DRIVING; bestTime = time; } } if (routesOfTravelModes.get(TravelMode.TRANSIT) != null) { time = routesOfTravelModes.get(TravelMode.TRANSIT).legs[0].arrivalTime.getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.TRANSIT; bestTime = time; } } if (routesOfTravelModes.get(TravelMode.BICYCLING) != null) { time = new DateTime(departureTime) .plusSeconds( Math.toIntExact(routesOfTravelModes.get(TravelMode.BICYCLING).legs[0].duration.inSeconds)) .getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.BICYCLING; } } if (bestTravelMode != null) { return new BestTransportResult(bestTravelMode, routesOfTravelModes.get(bestTravelMode)); } return null; }  BestTransportResult fromTo(String origin, String destination, TravelMode mode); BestTransportResult fromToWithDeparture(String origin, String destination, TravelMode mode,
			ReadableInstant departureTime); ReadableInstant whenIHaveToGo(String origin, String destination, TravelMode mode, DateTime arrivalTime); BestTransportResult getBestTransportInTime(String origin, String destination,
			ReadableInstant departureTime); TravelMode getTravelMode(String mode); }
DirectionApiLogic { public BestTransportResult getBestTransportInTime(String origin, String destination, ReadableInstant departureTime) { EnumMap<TravelMode, DirectionsRoute> routesOfTravelModes = new EnumMap<>(TravelMode.class); routesOfTravelModes.put(TravelMode.DRIVING, findBestRoute( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.DRIVING, departureTime))); routesOfTravelModes.put(TravelMode.TRANSIT, findBestArrivalTime( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.TRANSIT, departureTime))); routesOfTravelModes.put(TravelMode.BICYCLING, findBestRoute( this.calls.fromToWithDepartureTime(origin, destination, TravelMode.BICYCLING, departureTime))); long bestTime = Long.MAX_VALUE; TravelMode bestTravelMode = null; long time; if (routesOfTravelModes.get(TravelMode.DRIVING) != null) { time = new DateTime(departureTime) .plusSeconds(Math.toIntExact( routesOfTravelModes.get(TravelMode.DRIVING).legs[0].durationInTraffic.inSeconds)) .getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.DRIVING; bestTime = time; } } if (routesOfTravelModes.get(TravelMode.TRANSIT) != null) { time = routesOfTravelModes.get(TravelMode.TRANSIT).legs[0].arrivalTime.getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.TRANSIT; bestTime = time; } } if (routesOfTravelModes.get(TravelMode.BICYCLING) != null) { time = new DateTime(departureTime) .plusSeconds( Math.toIntExact(routesOfTravelModes.get(TravelMode.BICYCLING).legs[0].duration.inSeconds)) .getMillis(); if (bestTime > time) { bestTravelMode = TravelMode.BICYCLING; } } if (bestTravelMode != null) { return new BestTransportResult(bestTravelMode, routesOfTravelModes.get(bestTravelMode)); } return null; }  BestTransportResult fromTo(String origin, String destination, TravelMode mode); BestTransportResult fromToWithDeparture(String origin, String destination, TravelMode mode,
			ReadableInstant departureTime); ReadableInstant whenIHaveToGo(String origin, String destination, TravelMode mode, DateTime arrivalTime); BestTransportResult getBestTransportInTime(String origin, String destination,
			ReadableInstant departureTime); TravelMode getTravelMode(String mode);  }