Skip to content

Commit

Permalink
STYLE: 158 - Analyze complete project and solve code issues
Browse files Browse the repository at this point in the history
  • Loading branch information
munterfi committed Jan 13, 2025
1 parent f3c2a41 commit 0a54895
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 33 deletions.
31 changes: 9 additions & 22 deletions src/main/java/ch/naviqore/service/gtfs/raptor/TypeMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,15 @@ public static EnumSet<ch.naviqore.raptor.TravelMode> map(EnumSet<TravelMode> tra

private static TravelMode map(RouteType routeType) {
DefaultRouteType defaultRouteType = RouteTypeMapper.map(routeType);
switch (defaultRouteType) {
case BUS:
case TROLLEYBUS:
return TravelMode.BUS;
case TRAM:
case CABLE_TRAM:
return TravelMode.TRAM;
case RAIL:
case MONORAIL:
return TravelMode.RAIL;
case FERRY:
return TravelMode.SHIP;
case SUBWAY:
return TravelMode.SUBWAY;
case AERIAL_LIFT:
return TravelMode.AERIAL_LIFT;
case FUNICULAR:
return TravelMode.FUNICULAR;
default:
// should never happen
throw new IllegalArgumentException("Route type not supported");
}
return switch (defaultRouteType) {
case BUS, TROLLEYBUS -> TravelMode.BUS;
case TRAM, CABLE_TRAM -> TravelMode.TRAM;
case RAIL, MONORAIL -> TravelMode.RAIL;
case FERRY -> TravelMode.SHIP;
case SUBWAY -> TravelMode.SUBWAY;
case AERIAL_LIFT -> TravelMode.AERIAL_LIFT;
case FUNICULAR -> TravelMode.FUNICULAR;
};
}

private static Leg createPublicTransitLeg(ch.naviqore.raptor.Leg leg, GtfsSchedule schedule, int distance) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/ch/naviqore/app/TestRestRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public TestRestRequest(TestRestTemplate template) {
}

public TestRestRequest setPort(int port) {
this.uriBuilder = UriComponentsBuilder.fromHttpUrl(String.format("http://localhost:%d", port));
this.uriBuilder = UriComponentsBuilder.fromUriString(String.format("http://localhost:%d", port));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void testFromStopReturnConnectionsTrue() {
Connection connection = stopConnection.getConnection();
// make sure each connection has a departure time after/equal the expected start time
assertFalse(connection.getLegs().getFirst().getDepartureTime().isBefore(expectedStartTime));
assertEquals(connection.getLegs().getFirst().getFromStop().getId(), sourceStopId);
assertEquals(sourceStopId, connection.getLegs().getFirst().getFromStop().getId());

Trip trip = stopConnection.getConnectingLeg().getTrip();
if (trip != null) {
Expand Down Expand Up @@ -444,7 +444,7 @@ void testFromStopReturnConnectionsTrueTimeTypeArrival() {

// make sure each connection has an arrival time after/equal the expected start time
assertFalse(connection.getLegs().getLast().getArrivalTime().isAfter(expectedArrivalTime));
assertEquals(connection.getLegs().getLast().getToStop().getId(), sourceStopId);
assertEquals(sourceStopId, connection.getLegs().getLast().getToStop().getId());

Trip trip = connectingLeg.getTrip();
if (trip != null) {
Expand Down
10 changes: 4 additions & 6 deletions src/test/java/ch/naviqore/raptor/router/RaptorRouterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ void findConnectionWithZeroTravelTimeTripsAndConsequentWalkTransfer(RaptorRouter
Connection connection = connections.getFirst();
Leg firstRouteLeg = connection.getLegs().getFirst();
Leg walkTransferLeg = connection.getLegs().get(1);
assertEquals(firstRouteLeg.getType(), Leg.Type.ROUTE);
assertEquals(walkTransferLeg.getType(), Leg.Type.WALK_TRANSFER);
assertEquals(Leg.Type.ROUTE, firstRouteLeg.getType());
assertEquals(Leg.Type.WALK_TRANSFER, walkTransferLeg.getType());
assertEquals(firstRouteLeg.getDepartureTime(), firstRouteLeg.getArrivalTime(),
"Departure time at C should be equal to arrival time at D");
assertEquals(firstRouteLeg.getDepartureTime(), walkTransferLeg.getDepartureTime(),
Expand Down Expand Up @@ -921,21 +921,19 @@ void throwErrorForInvalidWalkToTargetTimeFromOneOfManyTargetStops() {

@Test
void throwErrorNullSourceStops() {
Map<String, LocalDateTime> sourceStops = null;
Map<String, Integer> targetStops = Map.of(STOP_H, 0);

assertThrows(IllegalArgumentException.class,
() -> RaptorRouterTestHelpers.routeEarliestArrival(raptor, sourceStops, targetStops),
() -> RaptorRouterTestHelpers.routeEarliestArrival(raptor, null, targetStops),
"Source stops cannot be null");
}

@Test
void throwErrorNullTargetStops() {
Map<String, LocalDateTime> sourceStops = Map.of(STOP_A, START_OF_DAY);
Map<String, Integer> targetStops = null;

assertThrows(IllegalArgumentException.class,
() -> RaptorRouterTestHelpers.routeEarliestArrival(raptor, sourceStops, targetStops),
() -> RaptorRouterTestHelpers.routeEarliestArrival(raptor, sourceStops, null),
"Target stops cannot be null");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void setUp() {
class Connection {

@Test
void shouldThrowOnInvalidStop() throws StopNotFoundException, ConnectionRoutingException {
void shouldThrowOnInvalidStop() {
assertThrows(StopNotFoundException.class,
() -> service.getConnections(service.getStopById("NOT_A_STOP"), service.getStopById("C"),
DATE_TIME, TimeType.DEPARTURE, QUERY_CONFIG));
Expand Down Expand Up @@ -405,7 +405,7 @@ void source_arrival() throws ConnectionRoutingException, StopNotFoundException {
class Isolines {

@Test
void shouldThrowOnInvalidStop() throws StopNotFoundException, ConnectionRoutingException {
void shouldThrowOnInvalidStop() {
assertThrows(StopNotFoundException.class,
() -> service.getIsolines(service.getStopById("NOT_A_STOP"), DATE_TIME, TimeType.DEPARTURE,
QUERY_CONFIG));
Expand Down

0 comments on commit 0a54895

Please sign in to comment.