From 50fe527fa1f8469574943adde8bf446360b38f84 Mon Sep 17 00:00:00 2001 From: Lukas Connolly Date: Mon, 10 Jun 2024 19:18:50 +0200 Subject: [PATCH] TEST: NAV-77 - Fix build issues with ServiceConfigParserIT and add more tests for config validation. --- .../app/service/ServiceConfigParserIT.java | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/test/java/ch/naviqore/app/service/ServiceConfigParserIT.java b/src/test/java/ch/naviqore/app/service/ServiceConfigParserIT.java index e37d3e9b..fb9d9a66 100644 --- a/src/test/java/ch/naviqore/app/service/ServiceConfigParserIT.java +++ b/src/test/java/ch/naviqore/app/service/ServiceConfigParserIT.java @@ -2,6 +2,11 @@ import ch.naviqore.service.config.ServiceConfig; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -10,14 +15,30 @@ public class ServiceConfigParserIT { private static final String GTFS_URL = "src/test/resources/ch/naviqore/gtfs/schedule/sample-feed-1.zip"; private static final int MINIMUM_TRANSFER_TIME = 200; + private static final int SAME_STATION_TRANSFER_TIME = 200; private static final int MAXIMUM_WALKING_DISTANCE = 600; private static final int WALKING_SPEED = 4000; private static final String WALKING_CALCULATOR_TYPE = "BEE_LINE_DISTANCE"; + static Stream provideTestCombinations() { + return Stream.of(Arguments.of(-1, SAME_STATION_TRANSFER_TIME, MAXIMUM_WALKING_DISTANCE, WALKING_SPEED, + WALKING_CALCULATOR_TYPE, "Minimum Transfer Time cannot be smaller zero."), + Arguments.of(MINIMUM_TRANSFER_TIME, -1, MAXIMUM_WALKING_DISTANCE, WALKING_SPEED, + WALKING_CALCULATOR_TYPE, "Same Station Transfer Time cannot be smaller zero."), + Arguments.of(MINIMUM_TRANSFER_TIME, SAME_STATION_TRANSFER_TIME, -1, WALKING_SPEED, + WALKING_CALCULATOR_TYPE, "Maximum Walking Distance cannot be smaller zero."), + Arguments.of(MINIMUM_TRANSFER_TIME, SAME_STATION_TRANSFER_TIME, MAXIMUM_WALKING_DISTANCE, -1, + WALKING_CALCULATOR_TYPE, "Walking speed cannot be smaller zero."), + Arguments.of(MINIMUM_TRANSFER_TIME, SAME_STATION_TRANSFER_TIME, MAXIMUM_WALKING_DISTANCE, 0, + WALKING_CALCULATOR_TYPE, "Walking speed cannot be zero."), + Arguments.of(MINIMUM_TRANSFER_TIME, SAME_STATION_TRANSFER_TIME, MAXIMUM_WALKING_DISTANCE, WALKING_SPEED, + "INVALID", "Can't process invalid Walking Calculator Type.")); + } + @Test void testServiceConfigParser_withValidInputs() { - ServiceConfigParser parser = new ServiceConfigParser(GTFS_URL, MINIMUM_TRANSFER_TIME, MAXIMUM_WALKING_DISTANCE, - WALKING_SPEED, WALKING_CALCULATOR_TYPE); + ServiceConfigParser parser = new ServiceConfigParser(GTFS_URL, MINIMUM_TRANSFER_TIME, + SAME_STATION_TRANSFER_TIME, MAXIMUM_WALKING_DISTANCE, WALKING_SPEED, WALKING_CALCULATOR_TYPE); // check that the service config has been loaded correctly ServiceConfig config = parser.getServiceConfig(); @@ -32,8 +53,19 @@ void testServiceConfigParser_withValidInputs() { void testServiceConfigParser_withInvalidWalkCalculatorType() { // check that the service config has been loaded correctly assertThrows(IllegalArgumentException.class, - () -> new ServiceConfigParser(GTFS_URL, MINIMUM_TRANSFER_TIME, MAXIMUM_WALKING_DISTANCE, WALKING_SPEED, - "INVALID")); + () -> new ServiceConfigParser(GTFS_URL, MINIMUM_TRANSFER_TIME, SAME_STATION_TRANSFER_TIME, + MAXIMUM_WALKING_DISTANCE, WALKING_SPEED, "INVALID")); + } + + @ParameterizedTest(name = "{5}") + @MethodSource("provideTestCombinations") + void testServiceConfigParser_withInvalidInputs(int minimumTransferTime, int sameStationTransferTime, + int maxWalkingDistance, int walkingSpeed, + String walkingCalculatorType, String message) { + // check that the service config has been loaded correctly + assertThrows(IllegalArgumentException.class, + () -> new ServiceConfigParser(GTFS_URL, minimumTransferTime, sameStationTransferTime, + maxWalkingDistance, walkingSpeed, walkingCalculatorType), message); } }