Skip to content

Commit

Permalink
Merge pull request #99 from IZIVIA/fix/#98-twenty-for-seven-marshalling
Browse files Browse the repository at this point in the history
fix(location) #98: twentyforseven instead of twenty_for_seven
  • Loading branch information
lilgallon authored Apr 19, 2024
2 parents d724b46 + 3305aea commit ada80ae
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.izivia.ocpi.toolkit.annotations.Partial
*
* @property regularHours Regular hours, weekday based. Should not be set for representing 24/7 as this is the most
* common case.
* @property twentyFourSeven True to represent 24 hours a day and 7 days a week, except the given exceptions.
* @property twentyfourseven True to represent 24 hours a day and 7 days a week, except the given exceptions.
* @property exceptionalOpenings Exceptions for specified calendar dates, time-range based. Periods the station is
* operating/accessible. Additional to regular hours. May overlap regular rules.
* @property exceptionalClosings Exceptions for specified calendar dates, time-range based. Periods the station is not
Expand All @@ -17,7 +17,7 @@ import com.izivia.ocpi.toolkit.annotations.Partial
@Partial
data class Hours(
val regularHours: List<RegularHours>?,
val twentyFourSeven: Boolean,
val twentyfourseven: Boolean,
val exceptionalOpenings: List<ExceptionalPeriod>?,
val exceptionalClosings: List<ExceptionalPeriod>?
)
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,24 @@ fun RegularHoursPartial.validate(): RegularHoursPartial = validate(this) { regul
}

fun HoursPartial.validate(): HoursPartial = validate(this) { hours ->
if (hours.regularHours == null && hours.twentyFourSeven == false) {
if (hours.regularHours == null && hours.twentyfourseven == false) {
constraintViolations.add(
DefaultConstraintViolation(
property = "regularHours is not set whereas twentyFourSeven is false",
constraint = RegularHoursSetWhenNotTwentyFourSevenConstraint()
)
)
} else if (hours.regularHours != null && hours.twentyFourSeven == true) {
} else if (hours.regularHours != null && hours.twentyfourseven == true) {
constraintViolations.add(
DefaultConstraintViolation(
property = "twentyFourSeven is set to true whereas regularHours are set",
property = "twentyfourseven is set to true whereas regularHours are set",
constraint = RegularHoursSetAtTheSameTimeAsTwentyFourSevenConstraint()
)
)
}

regularHours?.forEach { it.validate() }
// twentyFourSeven: nothing to validate
// twentyfourseven: nothing to validate
exceptionalOpenings?.forEach { it.validate() }
exceptionalClosings?.forEach { it.validate() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ class LocationsValidatorTest {

validHours.copy(
regularHours = null,
twentyFourSeven = true
twentyfourseven = true
).validate()

validHours.copy(
Expand All @@ -436,21 +436,21 @@ class LocationsValidatorTest {
expectCatching {
validHours.copy(
regularHours = listOf(validRegularHours),
twentyFourSeven = true
twentyfourseven = true
).toPartial().validate()
}.isFailure()

expectCatching {
validHours.copy(
regularHours = listOf(validRegularHours),
twentyFourSeven = true
twentyfourseven = true
).validate()
}.isFailure()

expectCatching {
validHours.copy(
regularHours = null,
twentyFourSeven = false
twentyfourseven = false
).validate()
}.isFailure()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ val validExceptionalPeriod = ExceptionalPeriod(

val validHours = Hours(
regularHours = listOf(validRegularHours),
twentyFourSeven = false,
twentyfourseven = false,
exceptionalOpenings = listOf(validExceptionalPeriod),
exceptionalClosings = emptyList()
)
Expand Down

0 comments on commit ada80ae

Please sign in to comment.