forked from serenity-bdd/serenity-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some improvements to the features
- Loading branch information
Showing
15 changed files
with
458 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
serenity-ensure/src/main/kotlin/net/serenitybdd/screenplay/ensure/DoubleEnsure.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.serenitybdd.screenplay.ensure | ||
|
||
import net.serenitybdd.screenplay.Actor | ||
|
||
|
||
class DoubleEnsure(override val value: KnowableValue<Double?>, comparator: Comparator<Double>) : ComparableEnsure<Double>(value, comparator) { | ||
|
||
companion object { | ||
fun fromKnowable(value: KnowableValue<Double?>) : DoubleEnsure = DoubleEnsure(value, naturalOrder<Double>()) | ||
} | ||
|
||
constructor(value: Double?) : this(KnownValue<Double?>(value, value.toString()), naturalOrder<Double>()) | ||
|
||
/** | ||
* Verifies that the actual {@code LocalDate} is before a specified date | ||
*/ | ||
fun isCloseTo(expected: Double, margin: Double) = PerformableExpectation(value, within(margin), expected, isNegated()) | ||
override fun not(): DoubleEnsure = negate() as DoubleEnsure | ||
override fun silently(): DoubleEnsure = silently() as DoubleEnsure | ||
|
||
fun within(margin: Double) = expectThatActualIs("close to(within a margin of " + margin + ")", | ||
fun(actor: Actor?, actual: KnowableValue<Double?>?, expected: Double): Boolean { | ||
CommonPreconditions.ensureActualNotNull(actual) | ||
val actualValue = actual!!(actor!!) ?: return false | ||
return actualValue >= (expected - margin) && actualValue <= (expected + margin) | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
serenity-ensure/src/main/kotlin/net/serenitybdd/screenplay/ensure/FloatEnsure.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.serenitybdd.screenplay.ensure | ||
|
||
import net.serenitybdd.screenplay.Actor | ||
|
||
|
||
class FloatEnsure(override val value: KnowableValue<Float?>, comparator: Comparator<Float>) : ComparableEnsure<Float>(value, comparator) { | ||
|
||
constructor(value: Float?) : this(KnownValue<Float?>(value, value.toString()), naturalOrder<Float>()) | ||
|
||
companion object { | ||
fun fromKnowable(value: KnowableValue<Float?>) : FloatEnsure = FloatEnsure(value, naturalOrder<Float>()) | ||
} | ||
|
||
/** | ||
* Verifies that the actual {@code LocalDate} is before a specified date | ||
*/ | ||
fun isCloseTo(expected: Float, margin: Float) = PerformableExpectation(value, within(margin), expected, isNegated()) | ||
override fun not(): FloatEnsure = negate() as FloatEnsure | ||
override fun silently(): FloatEnsure = silently() as FloatEnsure | ||
|
||
private fun within(margin: Float) = expectThatActualIs("close to (within a margin of " + margin + ")", | ||
fun(actor: Actor?, actual: KnowableValue<Float?>?, expected: Float): Boolean { | ||
CommonPreconditions.ensureActualNotNull(actual) | ||
val actualValue = actual!!(actor!!) ?: return false | ||
return actualValue >= (expected - margin) && actualValue <= (expected + margin) | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
serenity-ensure/src/main/kotlin/net/serenitybdd/screenplay/ensure/TimeEnsure.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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<LocalTime?>, comparator: Comparator<LocalTime>) : ComparableEnsure<LocalTime>(value, comparator) { | ||
|
||
constructor(value: LocalTime?) : this(KnownValue<LocalTime?>(value, value.toString()), naturalOrder<LocalTime>()) | ||
|
||
/** | ||
* 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 = silently() as TimeEnsure | ||
|
||
override fun usingComparator(comparator: Comparator<LocalTime>): TimeEnsure { | ||
return TimeEnsure(value, comparator) | ||
} | ||
|
||
companion object { | ||
|
||
val BEFORE = expectThatActualIs("before", | ||
fun(actor: Actor?, actual: KnowableValue<LocalTime?>?, 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<LocalTime?>?, expected: LocalTime): Boolean { | ||
ensureActualAndActorNotNull(actual, actor) | ||
val actualValue = actual!!(actor!!) ?: return false | ||
return actualValue.isAfter(expected) | ||
}) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.