All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.serenitybdd.screenplay.ensure.TimeEnsure.kt Maven / Gradle / Ivy

There is a newer version: 4.2.9
Show newest version
package net.serenitybdd.screenplay.ensure

import net.serenitybdd.screenplay.Actor
import net.serenitybdd.screenplay.ensure.CommonPreconditions.ensureActualAndActorNotNull

import java.time.DayOfWeek
import java.time.LocalTime
import java.time.Month


class TimeEnsure(override val value: KnowableValue, comparator: Comparator) : ComparableEnsure(value, comparator) {

    constructor(value: LocalTime?) : this(KnownValue(value, value.toString()), naturalOrder())

    /**
     * Verifies that the actual {@code LocalTime} is before a specified date
     */
    fun isBefore(expected: LocalTime) = PerformableExpectation(value, BEFORE, expected, isNegated())

    /**
     * Verifies that the actual {@code LocalTime} is after a specified date
     */
    fun isAfter(expected: LocalTime) = PerformableExpectation(value, AFTER, expected, isNegated())

    override fun not(): TimeEnsure = negate() as TimeEnsure
    override fun silently(): TimeEnsure = super.silently() as TimeEnsure

    override fun usingComparator(comparator: Comparator): TimeEnsure {
        return TimeEnsure(value, comparator)
    }

    companion object {

        val BEFORE = expectThatActualIs("before",
                fun(actor: Actor?, actual: KnowableValue?, expected: LocalTime): Boolean {
                    ensureActualAndActorNotNull(actual, actor)
                    val actualValue = actual!!(actor!!) ?: return false
                    return actualValue.isBefore(expected)
                })

        val AFTER = expectThatActualIs("after",
                fun(actor: Actor?, actual: KnowableValue?, expected: LocalTime): Boolean {
                    ensureActualAndActorNotNull(actual, actor)
                    val actualValue = actual!!(actor!!) ?: return false
                    return actualValue.isAfter(expected)
                })

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy