net.serenitybdd.screenplay.ensure.Ensure.kt Maven / Gradle / Ivy
@file:JvmName("Ensure")
package net.serenitybdd.screenplay.ensure
import net.serenitybdd.screenplay.Actor
import net.serenitybdd.screenplay.AnonymousPerformableFunction
import net.serenitybdd.screenplay.Question
import net.serenitybdd.screenplay.ensure.web.PageObjectEnsure
import net.serenitybdd.screenplay.ensure.web.TargetEnsure
import net.serenitybdd.screenplay.targets.Target
import org.openqa.selenium.By
import java.time.LocalDate
import java.time.LocalTime
import java.util.function.Consumer
fun that(value: String?) = StringEnsure(value)
fun that(value: LocalDate?) = DateEnsure(value)
fun that(value: LocalTime?) = TimeEnsure(value)
fun that(value: Boolean?) = BooleanEnsure(value)
fun that(value: Float?) = FloatEnsure(value)
fun that(value: Double?) = DoubleEnsure(value)
fun that(value: Comparable) = ComparableEnsure(value)
fun that(value: Collection?) = CollectionEnsure(value)
@Deprecated("Use that() instead")
fun thatTheAnswerTo(description: String, question: Question) =
BooleanEnsure(KnowableBooleanAnswer(question, description))
fun that(description: String, question: Question) =
BooleanEnsure(KnowableBooleanAnswer(question, description))
@Deprecated("Use that() instead")
fun thatTheAnswerTo(question: Question) =
BooleanEnsure(KnowableBooleanAnswer(question, question.subject))
fun that(question: Question) = BooleanEnsure(KnowableBooleanAnswer(question, question.subject))
fun that(question: Question, predicate: (actual: A) -> Boolean) = that("predicate check at ${predicateLocation()}", question, predicate)
fun that(description: String, question: Question, predicate: (actual: A) -> Boolean) =
AnonymousPerformableFunction("Ensure that $description",
object : Consumer {
override fun accept(actor: Actor) {
val actual = question.answeredBy(actor)
if (!predicate.invoke(actual)) {
throw AssertionError("Expected $description but was $actual")
}
}
}
)
fun predicateLocation() : String {
val className = Throwable().stackTrace[2].className
val methodName = Throwable().stackTrace[2].methodName
val lineNumber = Throwable().stackTrace[2].lineNumber
return "$className.$methodName (line $lineNumber)"
}
@Deprecated("Use that() instead")
fun thatTheAnswerTo(description: String, question: Question) =
StringEnsure(KnowableStringAnswer(question, description))
fun that(description: String, question: Question) =
StringEnsure(KnowableStringAnswer(question, description))
@Deprecated("Use that() instead")
fun thatTheAnswerTo(question: Question) =
StringEnsure(KnowableStringAnswer(question, question.subject))
fun that(question: Question) = StringEnsure(KnowableStringAnswer(question, question.subject))
@Deprecated("Use that() instead")
fun > thatTheAnswerTo(description: String, question: Question) =
ComparableEnsure(KnowableComparableAnswer(question, description), null, description)
fun > that(description: String, question: Question) =
ComparableEnsure(KnowableComparableAnswer(question, description), null, description)
@Deprecated("Use that() instead")
fun > thatTheAnswerTo(question: Question) = that(question.subject, question)
fun > that(question: Question) = that(question.subject, question)
@Deprecated("Use that() instead")
fun thatTheAnswersTo(description: String, question: Question>) =
CollectionEnsure(KnowableCollectionAnswer(question, description), description)
fun that(description: String, question: Question>) =
CollectionEnsure(KnowableCollectionAnswer(question, description), description)
@Deprecated("Use that() instead")
fun thatTheAnswersTo(question: Question>) = that(question.subject, question)
fun that(question: Question>) = that(question.subject, question)
fun thatTheListOf(description: String, question: Question
© 2015 - 2025 Weber Informatics LLC | Privacy Policy