From 0a5489595c8d65246fa809944dd9bf76958ad123 Mon Sep 17 00:00:00 2001 From: Merlin Unterfinger Date: Mon, 13 Jan 2025 11:42:01 +0100 Subject: [PATCH] STYLE: 158 - Analyze complete project and solve code issues --- .../service/gtfs/raptor/TypeMapper.java | 31 ++++++------------- .../java/ch/naviqore/app/TestRestRequest.java | 2 +- .../app/controller/RoutingControllerTest.java | 4 +-- .../raptor/router/RaptorRouterTest.java | 10 +++--- .../gtfs/raptor/GtfsRaptorServiceIT.java | 4 +-- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/src/main/java/ch/naviqore/service/gtfs/raptor/TypeMapper.java b/src/main/java/ch/naviqore/service/gtfs/raptor/TypeMapper.java index 9a8a2648..57fb7f48 100644 --- a/src/main/java/ch/naviqore/service/gtfs/raptor/TypeMapper.java +++ b/src/main/java/ch/naviqore/service/gtfs/raptor/TypeMapper.java @@ -137,28 +137,15 @@ public static EnumSet map(EnumSet 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) { diff --git a/src/test/java/ch/naviqore/app/TestRestRequest.java b/src/test/java/ch/naviqore/app/TestRestRequest.java index b3047689..4fffa1be 100644 --- a/src/test/java/ch/naviqore/app/TestRestRequest.java +++ b/src/test/java/ch/naviqore/app/TestRestRequest.java @@ -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; } diff --git a/src/test/java/ch/naviqore/app/controller/RoutingControllerTest.java b/src/test/java/ch/naviqore/app/controller/RoutingControllerTest.java index f3f6caa0..6a8abdd2 100644 --- a/src/test/java/ch/naviqore/app/controller/RoutingControllerTest.java +++ b/src/test/java/ch/naviqore/app/controller/RoutingControllerTest.java @@ -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) { @@ -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) { diff --git a/src/test/java/ch/naviqore/raptor/router/RaptorRouterTest.java b/src/test/java/ch/naviqore/raptor/router/RaptorRouterTest.java index 54835acf..3852bef9 100644 --- a/src/test/java/ch/naviqore/raptor/router/RaptorRouterTest.java +++ b/src/test/java/ch/naviqore/raptor/router/RaptorRouterTest.java @@ -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(), @@ -921,21 +921,19 @@ void throwErrorForInvalidWalkToTargetTimeFromOneOfManyTargetStops() { @Test void throwErrorNullSourceStops() { - Map sourceStops = null; Map 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 sourceStops = Map.of(STOP_A, START_OF_DAY); - Map targetStops = null; assertThrows(IllegalArgumentException.class, - () -> RaptorRouterTestHelpers.routeEarliestArrival(raptor, sourceStops, targetStops), + () -> RaptorRouterTestHelpers.routeEarliestArrival(raptor, sourceStops, null), "Target stops cannot be null"); } diff --git a/src/test/java/ch/naviqore/service/gtfs/raptor/GtfsRaptorServiceIT.java b/src/test/java/ch/naviqore/service/gtfs/raptor/GtfsRaptorServiceIT.java index 476076c0..20d0aeb1 100644 --- a/src/test/java/ch/naviqore/service/gtfs/raptor/GtfsRaptorServiceIT.java +++ b/src/test/java/ch/naviqore/service/gtfs/raptor/GtfsRaptorServiceIT.java @@ -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)); @@ -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));