diff --git a/toll_fee_calc_app/pom.xml b/toll_fee_calc_app/pom.xml new file mode 100644 index 00000000..45d720a2 --- /dev/null +++ b/toll_fee_calc_app/pom.xml @@ -0,0 +1,96 @@ + + 4.0.0 + com.evolve-technology.161602 + toll_free_calc_app + 0.0.1-SNAPSHOT + + UTF-8 + 11 + 11 + 5.3.19 + + + + junit + junit + 4.11 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.5.2 + test + + + org.junit.jupiter + junit-jupiter-api + 5.5.2 + test + + + org.junit.jupiter + junit-jupiter-params + 5.5.2 + test + + + org.junit.platform + junit-platform-suite + 1.8.1 + test + + + org.junit.platform + junit-platform-launcher + 1.3.2 + test + + + org.projectlombok + lombok + true + 1.18.20 + + + org.apache.logging.log4j + log4j-core + 2.17.2 + + + org.apache.logging.log4j + log4j-api + 2.17.2 + + + javax.validation + validation-api + 2.0.1.Final + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M3 + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/TollFeeCalculatorApplication.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/TollFeeCalculatorApplication.java new file mode 100644 index 00000000..5efc0e20 --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/TollFeeCalculatorApplication.java @@ -0,0 +1,8 @@ +package com.evolve_technology.calculator; + +public class TollFeeCalculatorApplication { + + public static void main(String[] args) { + // TODO Auto-generated method stub + } +} diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/exception/CustomErrorException.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/exception/CustomErrorException.java new file mode 100644 index 00000000..100a7bcb --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/exception/CustomErrorException.java @@ -0,0 +1,21 @@ +package com.evolve_technology.calculator.exception; + +import lombok.Data; + +@Data +public class CustomErrorException extends RuntimeException { + private Object data = null; + + public CustomErrorException() { + super(); + } + + public CustomErrorException(String message) { + super(message); + } + + public CustomErrorException(String message, Object data) { + this(message); + this.data = data; + } +} diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/properties/TollConfiguration.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/properties/TollConfiguration.java new file mode 100644 index 00000000..3e07bd21 --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/properties/TollConfiguration.java @@ -0,0 +1,63 @@ +package com.evolve_technology.calculator.properties; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import lombok.Data; + +@Data +public class TollConfiguration { + private static final Logger logger = LogManager + .getLogger(TollConfiguration.class); + private String year; + private List dates; + private List vehicles; + private List months; + + public TollConfiguration() { + try (InputStream input = TollConfiguration.class.getClassLoader() + .getResourceAsStream("application.properties")) { + + Properties prop = new Properties(); + + if (input == null) { + logger.info("Sorry, unable to find application.properties"); + return; + } + + // load a properties file from class path, inside static method + prop.load(input); + + // get the property value and print it out + if (prop.getProperty("dates") != null) { + setDates(Arrays.asList(prop.getProperty("dates").split(","))); + } + + if (prop.getProperty("months") != null) { + setMonths(Arrays.asList(prop.getProperty("months").split(","))); + } + + if (prop.getProperty("vehicles") != null) { + setVehicles( + Arrays.asList(prop.getProperty("vehicles").split(","))); + } + + setYear(prop.getProperty("year")); + + logger.info("dates :: {} " + getDates()); + logger.info("months :: {} " + getMonths()); + logger.info("vehicles :: {} " + getVehicles()); + logger.info("year :: {} " + getYear()); + + } catch (IOException ex) { + ex.printStackTrace(); + logger.error(ex.getMessage()); + } + } +} diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/TollFeeService.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/TollFeeService.java new file mode 100644 index 00000000..368d016c --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/TollFeeService.java @@ -0,0 +1,9 @@ +package com.evolve_technology.calculator.service; + +import java.time.LocalDateTime; +import java.util.List; + +public interface TollFeeService { + + public Integer getTollFee(final List list, String vehicle); +} diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/TollFreeDatesService.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/TollFreeDatesService.java new file mode 100644 index 00000000..b18c2969 --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/TollFreeDatesService.java @@ -0,0 +1,9 @@ +package com.evolve_technology.calculator.service; + +import java.util.List; + +public interface TollFreeDatesService { + public Boolean isTollFreeDate(String date); + + public List getTollFreeDates(); +} diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/TollFreeVehicleService.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/TollFreeVehicleService.java new file mode 100644 index 00000000..8afe0fd7 --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/TollFreeVehicleService.java @@ -0,0 +1,9 @@ +package com.evolve_technology.calculator.service; + +import java.util.List; + +public interface TollFreeVehicleService { + public List getTollFreeVehicles(); + + public boolean isTollFreeVehicle(String vehicle); +} diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/impl/TollFeeServiceImpl.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/impl/TollFeeServiceImpl.java new file mode 100644 index 00000000..1611b75d --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/impl/TollFeeServiceImpl.java @@ -0,0 +1,67 @@ +package com.evolve_technology.calculator.service.impl; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.evolve_technology.calculator.service.TollFeeService; +import com.evolve_technology.calculator.util.TollUtil; +import com.evolve_technology.calculator.validation.TollValidation; + +public class TollFeeServiceImpl implements TollFeeService { + + private static final Logger logger = LogManager + .getLogger(TollFeeServiceImpl.class); + + TollUtil tollUtil; + + private Map tollMap = new HashMap<>(); + + public TollFeeServiceImpl(TollUtil tollUtil) { + this.tollUtil = tollUtil; + } + + public Integer getTollFee(List inputDates, String vehicle) { + TollValidation.validate(inputDates, vehicle); + logger.info( + "Inside getTollFee method :: inputDates = {} and vehicle = {}", + inputDates, vehicle); + for (LocalDateTime localDateTime : inputDates) { + int hour = localDateTime.getHour(); + int minute = localDateTime.getMinute(); + LocalDate localDate = localDateTime.toLocalDate(); + Integer newFee = tollUtil.tollCompute(vehicle, localDate, hour, + minute); + String key = localDate.toString() + ":" + hour; + if (!tollMap.containsKey(key)) { + tollMap.put(key, newFee); + } else { + if (newFee > tollMap.get(key)) + tollMap.put(key, newFee); + } + } + return process(); + } + + public int process() { + logger.info("tollMap {} :: " + tollMap); + Map map = new HashMap<>(); + for (String key : tollMap.keySet()) { + LocalDate localDate = LocalDate.parse(key.split(":")[0]); + if (!map.containsKey(localDate)) { + map.putIfAbsent(localDate, tollMap.get(key)); + } else { + int sum = tollMap.get(key) + map.get(localDate); + map.put(localDate, sum > 60 ? 60 : sum); + } + } + return map.values().stream() + .collect(Collectors.summingInt(Integer::intValue)); + } +} diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/impl/TollFreeDatesServiceImpl.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/impl/TollFreeDatesServiceImpl.java new file mode 100644 index 00000000..55bc80f3 --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/impl/TollFreeDatesServiceImpl.java @@ -0,0 +1,54 @@ +package com.evolve_technology.calculator.service.impl; + +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.evolve_technology.calculator.properties.TollConfiguration; +import com.evolve_technology.calculator.service.TollFreeDatesService; + +public class TollFreeDatesServiceImpl implements TollFreeDatesService { + private static final Logger logger = LogManager + .getLogger(TollFreeDatesServiceImpl.class); + + TollConfiguration tollConfiguration; + + public TollFreeDatesServiceImpl(TollConfiguration tollConfiguration) { + this.tollConfiguration = tollConfiguration; + } + + @Override + public Boolean isTollFreeDate(String date) { + logger.info("Inside isTollFreeDate method :: date = {} ", date); + + LocalDate input = LocalDate.parse(date); + if (input.getDayOfWeek() == DayOfWeek.SATURDAY + || input.getDayOfWeek() == DayOfWeek.SUNDAY) { + logger.info("date {} is actually a weekend so no toll Enjoy.", + date); + return true; + } + + if (tollConfiguration.getMonths().stream() + .filter(month -> month.trim() + .equalsIgnoreCase(input.getMonth().toString())) + .findAny().isPresent()) { + logger.info("date {} lies in JULY month so no toll Enjoy.", date); + return true; + } + + return getTollFreeDates().stream() + .filter(x -> x.trim().equalsIgnoreCase(input.toString())) + .findAny().isPresent(); + } + + @Override + public List getTollFreeDates() { + logger.info("Inside getTollFreeDates method "); + return tollConfiguration.getDates(); + } + +} diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/impl/TollFreeVehiclesServiceImpl.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/impl/TollFreeVehiclesServiceImpl.java new file mode 100644 index 00000000..ea471324 --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/service/impl/TollFreeVehiclesServiceImpl.java @@ -0,0 +1,35 @@ +package com.evolve_technology.calculator.service.impl; + +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.evolve_technology.calculator.properties.TollConfiguration; +import com.evolve_technology.calculator.service.TollFreeVehicleService; + +public class TollFreeVehiclesServiceImpl implements TollFreeVehicleService { + + TollConfiguration tollConfiguration; + + private static final Logger logger = LogManager + .getLogger(TollFreeVehiclesServiceImpl.class); + + public TollFreeVehiclesServiceImpl(TollConfiguration tollConfiguration) { + this.tollConfiguration = tollConfiguration; + } + + public List getTollFreeVehicles() { + logger.info("Inside getTollFreeVehicles method "); + return tollConfiguration.getVehicles(); + } + + public boolean isTollFreeVehicle(String vehicle) { + logger.info("Inside isTollFreeVehicle method :: vehicle = {} ", + vehicle); + List vehicles = getTollFreeVehicles(); + return vehicles.stream().filter(v -> v.trim().equalsIgnoreCase(vehicle)) + .findAny().isPresent(); + } + +} diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/util/TollRules.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/util/TollRules.java new file mode 100644 index 00000000..d8f31fc4 --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/util/TollRules.java @@ -0,0 +1,27 @@ +package com.evolve_technology.calculator.util; + +public class TollRules { + + public static int getHourlyRate(int hour, int minute) { + if (hour == 6 && minute >= 0 && minute <= 29) + return 8; + else if (hour == 6 && minute >= 30 && minute <= 59) + return 13; + else if (hour == 7 && minute >= 0 && minute <= 59) + return 18; + else if (hour == 8 && minute >= 0 && minute <= 29) + return 13; + else if (hour >= 8 && hour <= 14 && minute >= 30 && minute <= 59) + return 8; + else if (hour == 15 && minute >= 0 && minute <= 29) + return 13; + else if (hour == 15 && minute >= 0 || hour == 16 && minute <= 59) + return 18; + else if (hour == 17 && minute >= 0 && minute <= 59) + return 13; + else if (hour == 18 && minute >= 0 && minute <= 29) + return 8; + else + return 0; + } +} diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/util/TollUtil.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/util/TollUtil.java new file mode 100644 index 00000000..d80e189c --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/util/TollUtil.java @@ -0,0 +1,27 @@ +package com.evolve_technology.calculator.util; + +import java.time.LocalDate; + +import com.evolve_technology.calculator.service.TollFreeDatesService; +import com.evolve_technology.calculator.service.TollFreeVehicleService; + +public class TollUtil { + TollFreeDatesService tollFreeDatesService; + + TollFreeVehicleService tollFreeVehicleService; + + public TollUtil(TollFreeDatesService tollFreeDatesService, + TollFreeVehicleService tollFreeVehicleService) { + this.tollFreeDatesService = tollFreeDatesService; + this.tollFreeVehicleService = tollFreeVehicleService; + } + + public int tollCompute(String vehicle, LocalDate localDate, int hour, + int minute) { + if (tollFreeDatesService.isTollFreeDate(localDate.toString()) + || tollFreeVehicleService.isTollFreeVehicle(vehicle)) + return 0; + return TollRules.getHourlyRate(hour, minute); + } + +} diff --git a/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/validation/TollValidation.java b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/validation/TollValidation.java new file mode 100644 index 00000000..4c37d952 --- /dev/null +++ b/toll_fee_calc_app/src/main/java/com/evolve_technology/calculator/validation/TollValidation.java @@ -0,0 +1,17 @@ +package com.evolve_technology.calculator.validation; + +import java.time.LocalDateTime; +import java.util.List; + +import com.evolve_technology.calculator.exception.CustomErrorException; + +public class TollValidation { + public static void validate(List inputDates, + String vehicle) { + if (inputDates == null || vehicle == null || inputDates.isEmpty() + || vehicle.isBlank()) + throw new CustomErrorException( + "inputDates and vehicle must not be null or empty. "); + } + +} diff --git a/toll_fee_calc_app/src/main/resources/application.properties b/toll_fee_calc_app/src/main/resources/application.properties new file mode 100644 index 00000000..37ded940 --- /dev/null +++ b/toll_fee_calc_app/src/main/resources/application.properties @@ -0,0 +1,13 @@ +server.servlet.context-path=/v1/api + +# Year +year=2013 + +# Toll Free Dates +dates=2013-01-01 , 2013-03-28 , 2013-03-29 , 2013-04-01 , 2013-04-30 , 2013-05-01 , 2013-05-08 , 2013-05-09 , 2013-06-05 , 2013-06-06 , 2013-06-21 , 2013-11-01 , 2013-12-24 , 2013-12-25 , 2013-12-26 , 2013-12-31 + +# Toll Free Months +months= JULY + +# Toll Free Vehicles +vehicles= Motorbike , Tractor , Emergency , Diplomat , Foreign , Military \ No newline at end of file diff --git a/toll_fee_calc_app/src/main/resources/log4j2.properties b/toll_fee_calc_app/src/main/resources/log4j2.properties new file mode 100644 index 00000000..f5696d93 --- /dev/null +++ b/toll_fee_calc_app/src/main/resources/log4j2.properties @@ -0,0 +1,10 @@ +log4j.rootLogger=INFO,file,stdout + +# Redirect log messages to console + +appender.console.type=Console +appender.console.name=consoleLogger +appender.console.layout.type= PatternLayout +appender.console.layout.pattern = [Loglevel=%p] [Timestmp=%d{ISO8601}][Thread=%t][Msg=%F %L %m]%n +rootLogger.appenderRef.stdout.ref=consoleLogger +rootLogger.level=info diff --git a/toll_fee_calc_app/src/test/java/com/evolve_technology/calculator/service/impl/TollFeeServiceImplTest.java b/toll_fee_calc_app/src/test/java/com/evolve_technology/calculator/service/impl/TollFeeServiceImplTest.java new file mode 100644 index 00000000..df7be330 --- /dev/null +++ b/toll_fee_calc_app/src/test/java/com/evolve_technology/calculator/service/impl/TollFeeServiceImplTest.java @@ -0,0 +1,322 @@ +package com.evolve_technology.calculator.service.impl; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.evolve_technology.calculator.exception.CustomErrorException; +import com.evolve_technology.calculator.properties.TollConfiguration; +import com.evolve_technology.calculator.service.TollFeeService; +import com.evolve_technology.calculator.service.TollFreeDatesService; +import com.evolve_technology.calculator.service.TollFreeVehicleService; +import com.evolve_technology.calculator.util.TollUtil; + +class TollFeeServiceImplTest { + + TollFeeService tollFeeService; + + @BeforeEach + public void setup() { + TollConfiguration tollConfiguration = new TollConfiguration(); + TollFreeVehicleService tollFreeVehicleService = new TollFreeVehiclesServiceImpl( + tollConfiguration); + TollFreeDatesService tollFreeDatesService = new TollFreeDatesServiceImpl( + tollConfiguration); + TollUtil tollUtil = new TollUtil(tollFreeDatesService, + tollFreeVehicleService); + tollFeeService = new TollFeeServiceImpl(tollUtil); + + } + + /* + * Jan 2013 5,12,19,26 are saturday + */ + @Test + void testGetTollFeeSaturdayJanuary2013() { + + List inputDates = Stream + .of(LocalDateTime.of(2013, 01, 05, 8, 8), + LocalDateTime.of(2013, 01, 12, 8, 8), + LocalDateTime.of(2013, 01, 19, 8, 8), + LocalDateTime.of(2013, 01, 26, 8, 8)) + .collect(Collectors.toList()); + assertEquals(tollFeeService.getTollFee(inputDates, "car"), 0); + } + + /* + * Null as inputs + */ + @Test + void testGetTollFeeWithNullInputs() { + // Both input null + assertThrows(CustomErrorException.class, + () -> tollFeeService.getTollFee(null, null)); + + // only vehicle null + List inputDates = Stream + .of(LocalDateTime.of(2013, 01, 05, 8, 8), + LocalDateTime.of(2013, 01, 12, 8, 8), + LocalDateTime.of(2013, 01, 19, 8, 8), + LocalDateTime.of(2013, 01, 26, 8, 8)) + .collect(Collectors.toList()); + + assertThrows(CustomErrorException.class, + () -> tollFeeService.getTollFee(inputDates, null)); + + List inputDatesEmpty = new ArrayList<>(); + assertThrows(CustomErrorException.class, + () -> tollFeeService.getTollFee(inputDatesEmpty, "")); + } + + /* + * Feb 2013 2,9,16,23 are saturday + */ + @Test + void testGetTollFeeSaturdayFebruary2013() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 02, 8, 8), + LocalDateTime.of(2013, 02, 16, 8, 8), + LocalDateTime.of(2013, 02, 9, 8, 8), + LocalDateTime.of(2013, 02, 23, 8, 8)) + .collect(Collectors.toList()); + assertEquals(tollFeeService.getTollFee(inputDates, "car"), 0); + } + + /* + * Feb 2013 4,11,18,25 are Monday NON Free Vehicles Test + */ + @Test + void testGetTollFeeMondayFebruary2013Car() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 8, 8), + LocalDateTime.of(2013, 02, 18, 8, 8), + LocalDateTime.of(2013, 02, 11, 8, 8), + LocalDateTime.of(2013, 02, 25, 8, 8)) + .collect(Collectors.toList()); + assertNotEquals(tollFeeService.getTollFee(inputDates, "car"), 0); + + } + + /* + * Feb 2013 4,11,18,25 are Monday Free Vehicles Test + */ + @Test + void testGetTollFeeMondayFebruary2013FreeVehicles() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 8, 8), + LocalDateTime.of(2013, 02, 18, 8, 8), + LocalDateTime.of(2013, 02, 11, 8, 8), + LocalDateTime.of(2013, 02, 25, 8, 8)) + .collect(Collectors.toList()); + + assertEquals(tollFeeService.getTollFee(inputDates, "Tractor"), 0); + assertEquals(tollFeeService.getTollFee(inputDates, "Motorbike"), 0); + assertEquals(tollFeeService.getTollFee(inputDates, "Emergency"), 0); + assertEquals(tollFeeService.getTollFee(inputDates, "Diplomat"), 0); + assertEquals(tollFeeService.getTollFee(inputDates, "Foreign"), 0); + } + + /* + * Feb 2013 Monday 4th 04-02-2013 06:10 As per the Rule it is charged 8. + */ + @Test + void testGetTollFeeMondayFebruary2013At6Hr10Min() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 06, 10)) + .collect(Collectors.toList()); + + assertEquals(tollFeeService.getTollFee(inputDates, "Car"), 8); + } + + /* + * Feb 2013 Monday 4th 04-02-2013 06:10 && 06:20 As per the Rule it is + * charged 8. if (hour == 6 && minute >= 0 && minute <= 29) return 8; else + * if (hour == 6 && minute >= 30 && minute <= 59) return 13; + */ + @Test + void testGetTollFeeMondayFebruary2013At6Hr10MinAnd20Min() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 06, 10), + LocalDateTime.of(2013, 02, 04, 06, 20)) + .collect(Collectors.toList()); + + assertEquals(tollFeeService.getTollFee(inputDates, "Car"), 8); + } + + /* + * Feb 2013 Monday 4th 04-02-2013 06:10 && 06:20 && 06:40 As per the Rule + * max within an hour is charged that is 13 max of(8,13) + */ + @Test + void testGetTollFeeMondayFebruary2013At6Hr10MinAnd20MinAnd40Min() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 06, 10), + LocalDateTime.of(2013, 02, 04, 06, 20), + LocalDateTime.of(2013, 02, 04, 06, 40)) + .collect(Collectors.toList()); + + assertEquals(tollFeeService.getTollFee(inputDates, "Car"), 13); + } + + /* + * Feb 2013 Monday 4th 04-02-2013 06:10 && 06:20 && 06:40 && 07:10 As per + * the Rule max within an hour is charged that is max of 8,13 plus 18 =31 + */ + @Test + void testGetTollFeeMondayFebruary2013At6Hr10MinAnd20MinAnd40MinAnd7Hr10Min() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 06, 10), + LocalDateTime.of(2013, 02, 04, 06, 20), + LocalDateTime.of(2013, 02, 04, 06, 40), + LocalDateTime.of(2013, 02, 04, 07, 10)) + .collect(Collectors.toList()); + + assertEquals(tollFeeService.getTollFee(inputDates, "Car"), 31); + } + + /* + * Feb 2013 Monday 4th 04-02-2013 06:10 && 06:20 && 06:40 && 07:10 && 08:10 + * As per the Rule max within an hour is charged that is max of 8,13 plus 18 + * =31 plus 13 =44 + */ + @Test + void testGetTollFeeMondayFebruary2013At6Hr10MinAnd20MinAnd40MinAnd7Hr10MinAnd8Hr10Min() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 06, 10), + LocalDateTime.of(2013, 02, 04, 06, 20), + LocalDateTime.of(2013, 02, 04, 06, 40), + LocalDateTime.of(2013, 02, 04, 07, 10), + LocalDateTime.of(2013, 02, 04, 8, 10)) + .collect(Collectors.toList()); + + assertEquals(tollFeeService.getTollFee(inputDates, "Car"), 44); + } + + /* + * Feb 2013 Monday 4th 04-02-2013 06:10 && 06:20 && 06:40 && 07:10 && 08:10 + * && 08:30 As per the Rule max within an hour is charged that is max of + * 8,13 plus 18 =31 plus 13 =44 + */ + @Test + void testGetTollFeeMondayFebruary2013At6Hr10MinAnd20MinAnd40MinAnd7Hr10MinAnd8Hr10MinAnd8Hr30Min() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 06, 10), + LocalDateTime.of(2013, 02, 04, 06, 20), + LocalDateTime.of(2013, 02, 04, 06, 40), + LocalDateTime.of(2013, 02, 04, 07, 10), + LocalDateTime.of(2013, 02, 04, 8, 10), + LocalDateTime.of(2013, 02, 04, 8, 30)) + .collect(Collectors.toList()); + + assertEquals(tollFeeService.getTollFee(inputDates, "Car"), 44); + } + + /* + * Feb 2013 Monday 4th 04-02-2013 06:10 && 06:20 && 06:40 && 07:10 && 08:10 + * && 08:30 && 15:10 As per the Rule max within an hour is charged that is + * max of 8,13 plus 18 =31 plus 13 =44 plus 13= 57 + */ + @Test + void testGetTollFeeMondayFebruary2013At6Hr10MinAnd20MinAnd40MinAnd7Hr10MinAnd8Hr10MinAnd8Hr30MinAnd15Hr10Min() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 06, 10), + LocalDateTime.of(2013, 02, 04, 06, 20), + LocalDateTime.of(2013, 02, 04, 06, 40), + LocalDateTime.of(2013, 02, 04, 07, 10), + LocalDateTime.of(2013, 02, 04, 8, 10), + LocalDateTime.of(2013, 02, 04, 8, 30), + LocalDateTime.of(2013, 02, 04, 15, 10)) + .collect(Collectors.toList()); + + assertEquals(tollFeeService.getTollFee(inputDates, "Car"), 57); + } + + /* + * Feb 2013 Monday 4th 04-02-2013 06:10 && 06:20 && 06:40 && 07:10 && 08:10 + * && 08:30 && 15:10 && 15:30 As per the Rule max within an hour is charged + * that is max of 8,13 plus 18 =31 plus 13 =44 plus max of (13,18) is 18= 62 + * but it can't go beyond 60 for a day. + */ + @Test + void testGetTollFeeMondayFebruary2013At6Hr10MinAnd20MinAnd40MinAnd7Hr10MinAnd8Hr10MinAnd8Hr30MinAnd15Hr10MinAnd15HrMin30() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 06, 10), + LocalDateTime.of(2013, 02, 04, 06, 20), + LocalDateTime.of(2013, 02, 04, 06, 40), + LocalDateTime.of(2013, 02, 04, 07, 10), + LocalDateTime.of(2013, 02, 04, 8, 10), + LocalDateTime.of(2013, 02, 04, 8, 30), + LocalDateTime.of(2013, 02, 04, 15, 10), + LocalDateTime.of(2013, 02, 04, 15, 30)) + .collect(Collectors.toList()); + + assertEquals(tollFeeService.getTollFee(inputDates, "Car"), 60); + } + + /* + * Feb 2013 Monday 4th 04-02-2013 06:10 && 06:20 && 06:40 && 07:10 && 08:10 + * && 08:30 && 15:10 && 15:30 As per the Rule max within an hour is charged + * that is max of 8,13 plus 18 =31 plus 13 =44 plus max of (13,18) is 18= 62 + * but it can't go beyond 60 for a day. + * + * And Feb 2013 Tuesday 5th 05-02-2013 06:10 + * + * Monday=60 plus Tuesday=8= 68 + */ + @Test + void testGetTollFeeMondayFebruary2013MultipleDatesMondayPlusTuesday() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 06, 10), + LocalDateTime.of(2013, 02, 04, 06, 20), + LocalDateTime.of(2013, 02, 04, 06, 40), + LocalDateTime.of(2013, 02, 04, 07, 10), + LocalDateTime.of(2013, 02, 04, 8, 10), + LocalDateTime.of(2013, 02, 04, 8, 30), + LocalDateTime.of(2013, 02, 04, 15, 10), + LocalDateTime.of(2013, 02, 04, 15, 30), + LocalDateTime.of(2013, 02, 05, 6, 10)) + .collect(Collectors.toList()); + + assertEquals(tollFeeService.getTollFee(inputDates, "Car"), 68); + } + + /* + * Feb 2013 Monday 4th 04-02-2013 06:10 && 06:20 && 06:40 && 07:10 && 08:10 + * && 08:30 && 15:10 && 15:30 As per the Rule max within an hour is charged + * that is max of 8,13 plus 18 =31 plus 13 =44 plus max of (13,18) is 18= 62 + * but it can't go beyond 60 for a day. + * + * And Feb 2013 Tuesday 5th 05-02-2013 06:10 + * + * And Feb 2013 Wednesday 6th 06-02-2013 17:10 && 18:10 + * + * Monday=60 plus Tuesday=8 plus Wednesday= 13 plus 8 =89 + */ + @Test + void testGetTollFeeMondayFebruary2013MultipleDatesMondayPlusTuesdayPlusWednesday() { + List inputDates = Stream + .of(LocalDateTime.of(2013, 02, 04, 06, 10), + LocalDateTime.of(2013, 02, 04, 06, 20), + LocalDateTime.of(2013, 02, 04, 06, 40), + LocalDateTime.of(2013, 02, 04, 07, 10), + LocalDateTime.of(2013, 02, 04, 8, 10), + LocalDateTime.of(2013, 02, 04, 8, 30), + LocalDateTime.of(2013, 02, 04, 15, 10), + LocalDateTime.of(2013, 02, 04, 15, 30), + LocalDateTime.of(2013, 02, 05, 6, 10), + LocalDateTime.of(2013, 02, 06, 17, 10), + LocalDateTime.of(2013, 02, 06, 18, 10)) + .collect(Collectors.toList()); + + assertEquals(tollFeeService.getTollFee(inputDates, "Car"), 89); + } +}