mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
rename bigDecimalAssertion functions to new schema in api-fluent
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//TODO rename file with 0.18.0
|
||||
//TODO rename file to featureExtractors in 0.18.0
|
||||
package ch.tutteli.atrium.api.fluent.en_GB
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.creating.feature.MetaFeatureOption
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//TODO rename file to fun0Expecations.kt with 0.18.0
|
||||
//TODO rename file to fun0Expectations.kt with 0.18.0
|
||||
package ch.tutteli.atrium.api.fluent.en_GB
|
||||
|
||||
import ch.tutteli.atrium.creating.Expect
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
@file:Suppress(
|
||||
// TODO remove once https://youtrack.jetbrains.com/issue/KT-35343 is fixed
|
||||
"JAVA_MODULE_DOES_NOT_READ_UNNAMED_MODULE"
|
||||
)
|
||||
|
||||
package ch.tutteli.atrium.api.fluent.en_GB
|
||||
|
||||
import ch.tutteli.atrium.creating.Expect
|
||||
import ch.tutteli.atrium.creating.PleaseUseReplacementException
|
||||
import ch.tutteli.atrium.logic.*
|
||||
import java.math.BigDecimal
|
||||
|
||||
/**
|
||||
* Deprecated as it would compare the subject against [expected] including scale
|
||||
* -- many developers are not aware of that.
|
||||
*
|
||||
* Use [toEqualNumerically] if you expect that the following assertion holds:
|
||||
* ```
|
||||
* expect(BigDecimal("10").toEqual(BigDecimal("10.0"))
|
||||
* ```
|
||||
* However, if you expect it to be wrong (because `BigDecimal.scale` differ), then use [toEqualIncludingScale].
|
||||
*
|
||||
* @since 0.17.0
|
||||
*/
|
||||
@Deprecated(
|
||||
"Use `toEqualNumerically` if you expect that the following assertion holds:\n" +
|
||||
"`expect(BigDecimal(\"10\")).toEqual(BigDecimal(\"10.0\"))`\n" +
|
||||
"However, if you expect it to be wrong (because `BigDecimal.scale` differ), then use `toEqualIncludingScale`.",
|
||||
ReplaceWith("toEqualNumerically(expected) or toEqualIncludingScale(expected)")
|
||||
)
|
||||
@Suppress("UNUSED_PARAMETER", "unused")
|
||||
fun <T : BigDecimal> Expect<T>.toEqual(expected: T): Nothing =
|
||||
throw PleaseUseReplacementException(
|
||||
"BigDecimal.equals() compares also BigDecimal.scale, which you might not be aware of.\n" +
|
||||
"If you know it and want that `scale` is included in the comparison, then use `toEqualIncludingScale`."
|
||||
)
|
||||
|
||||
/**
|
||||
* Deprecated as it would compare the subject against [expected] including scale
|
||||
* -- many developers are not aware of that.
|
||||
*
|
||||
* Use [toEqualNumerically] if you expect that the following assertion holds:
|
||||
* ```
|
||||
* expect(BigDecimal("10").toEqual(BigDecimal("10.0"))
|
||||
* ```
|
||||
* However, if you expect it to be wrong (because `BigDecimal.scale` differ), then use [toEqualIncludingScale].
|
||||
*
|
||||
* @since 0.17.0
|
||||
*/
|
||||
@Suppress("UNUSED_PARAMETER", "unused")
|
||||
@JvmName("toBeNullable")
|
||||
@Deprecated(
|
||||
"Use `toEqualNumerically` if you expect that the following assertion holds:\n" +
|
||||
"`expect(BigDecimal(\"10\")).toEqual(BigDecimal(\"10.0\"))`\n" +
|
||||
"However, if you expect it to be wrong (because `BigDecimal.scale` differ), then use `toEqualIncludingScale`.",
|
||||
ReplaceWith("toEqualNumerically(expected) or toEqualIncludingScale(expected)")
|
||||
)
|
||||
fun <T : BigDecimal?> Expect<T>.toEqual(expected: T): Nothing =
|
||||
throw PleaseUseReplacementException(
|
||||
"BigDecimal.equals() compares also BigDecimal.scale, which you might not be aware of.\n" +
|
||||
"If you know it and want that `scale` is included in the comparison, then use `toEqualIncludingScale`."
|
||||
)
|
||||
|
||||
/**
|
||||
* Expects that the subject of `this` expectation (a [BigDecimal]) is `null`.
|
||||
*
|
||||
* @return an [Expect] for the subject of `this` expectation.
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.BigDecimalExpectationSamples.toEqual
|
||||
*
|
||||
* @since 0.17.0
|
||||
*/
|
||||
@JvmName("toBeNull")
|
||||
fun <T : BigDecimal> Expect<T?>.toEqual(expected: Nothing?): Expect<T?> =
|
||||
_logicAppend { toBe(expected) }
|
||||
|
||||
/**
|
||||
* Deprecated as it would compare the subject against [expected] including scale
|
||||
* -- many developers are not aware of that.
|
||||
*
|
||||
* Use [notToEqualNumerically] if you expect that the following assertion is wrong:
|
||||
* ```
|
||||
* expect(BigDecimal("10").notToBe(BigDecimal("10.0"))
|
||||
* ```
|
||||
* However, if you expect it to be wrong (because `BigDecimal.scale` differ), then use [notToEqualIncludingScale].
|
||||
*
|
||||
* @since 0.17.0
|
||||
*/
|
||||
@Deprecated(
|
||||
"Use `notToEqualNumerically` if you expect that the following assertion is wrong:\n" +
|
||||
"`expect(BigDecimal(\"10\")).notToBe(BigDecimal(\"10.0\"))`\n" +
|
||||
"However, if you expect it to hold (because `BigDecimal.scale` differ), then use `notToEqualIncludingScale`.",
|
||||
ReplaceWith("notToEqualNumerically(expected) or notToEqualIncludingScale(expected)")
|
||||
)
|
||||
@Suppress("UNUSED_PARAMETER", "unused")
|
||||
fun <T : BigDecimal> Expect<T>.notToEqual(expected: T): Nothing =
|
||||
throw PleaseUseReplacementException(
|
||||
"BigDecimal.equals() compares also BigDecimal.scale, which you might not be aware of.\n" +
|
||||
"If you know it and want that `scale` is included in the comparison, then use `notToEqualIncludingScale`."
|
||||
)
|
||||
|
||||
/**
|
||||
* Expects that the subject of `this` expectation (a [BigDecimal]) is numerically equal to [expected].
|
||||
*
|
||||
* By numerically is meant that it will not compare [BigDecimal.scale] (or in other words,
|
||||
* it uses `compareTo(expected) == 0`)
|
||||
*
|
||||
* Most of the time you want to use this function instead of [toEqualIncludingScale] because
|
||||
* [toEqualIncludingScale] compares [BigDecimal.scale].
|
||||
* Following the two functions compared:
|
||||
* - `expect(BigDecimal("10")).toEqualIncludingScale(BigDecimal("10.0"))` does not hold.
|
||||
* - `expect(BigDecimal("10")).toEqualNumerically(BigDecimal("10.0"))` holds.
|
||||
*
|
||||
* @return an [Expect] for the subject of `this` expectation.
|
||||
*
|
||||
* @since 0.17.0
|
||||
*/
|
||||
fun <T : BigDecimal> Expect<T>.toEqualNumerically(expected: T): Expect<T> =
|
||||
_logicAppend { isNumericallyEqualTo(expected) }
|
||||
|
||||
/**
|
||||
* Expects that the subject of `this` expectation (a [BigDecimal]) is not numerically equal to [expected].
|
||||
*
|
||||
* By numerically is meant that it will not compare [BigDecimal.scale] (or in other words,
|
||||
* it uses `compareTo(expected) != 0`)
|
||||
*
|
||||
* Most of the time you want to use this function instead of [notToEqualIncludingScale] because
|
||||
* [notToEqualIncludingScale] compares [BigDecimal.scale].
|
||||
* Following the two functions compared:
|
||||
* - `expect(BigDecimal("10")).notToEqualIncludingScale(BigDecimal("10.0"))` holds.
|
||||
* - `expect(BigDecimal("10")).notToEqualNumerically(BigDecimal("10.0"))` does not hold.
|
||||
*
|
||||
* @return an [Expect] for the subject of `this` expectation.
|
||||
*
|
||||
* @since 0.17.0
|
||||
*/
|
||||
fun <T : BigDecimal> Expect<T>.notToEqualNumerically(expected: T): Expect<T> =
|
||||
_logicAppend { isNotNumericallyEqualTo(expected) }
|
||||
|
||||
/**
|
||||
* Expects that the subject of `this` expectation (a [BigDecimal]) is equal to [expected] including [BigDecimal.scale].
|
||||
*
|
||||
* Most of the time you want to use [toEqualNumerically] which does not compare [BigDecimal.scale]
|
||||
* in contrast to this function.
|
||||
* Following the two functions compared:
|
||||
* - `expect(BigDecimal("10")).toEqualIncludingScale(BigDecimal("10.0"))` does not hold.
|
||||
* - `expect(BigDecimal("10")).toEqualNumerically(BigDecimal("10.0"))` holds.
|
||||
*
|
||||
* @return an [Expect] for the subject of `this` expectation.
|
||||
*
|
||||
* @since 0.17.0
|
||||
*/
|
||||
fun <T : BigDecimal> Expect<T>.toEqualIncludingScale(expected: T): Expect<T> =
|
||||
_logicAppend { isEqualIncludingScale(expected, Expect<BigDecimal>::toEqualNumerically.name) }
|
||||
|
||||
/**
|
||||
* Expects that the subject of `this` expectation (a [BigDecimal]) is not equal to [expected] including [BigDecimal.scale].
|
||||
*
|
||||
* Most of the time you want to use [notToEqualNumerically] which does not compare [BigDecimal.scale]
|
||||
* in contrast to this function.
|
||||
* Following the two functions compared:
|
||||
* - `expect(BigDecimal("10")).notToEqualIncludingScale(BigDecimal("10.0"))` holds.
|
||||
* - `expect(BigDecimal("10")).notToEqualNumerically(BigDecimal("10.0"))` does not hold.
|
||||
*
|
||||
* @return an [Expect] for the subject of `this` expectation.
|
||||
*
|
||||
* @since 0.17.0
|
||||
*/
|
||||
fun <T : BigDecimal> Expect<T>.notToEqualIncludingScale(expected: T): Expect<T> =
|
||||
_logicAppend { isNotEqualIncludingScale(expected) }
|
||||
@@ -10,16 +10,16 @@ import java.math.BigDecimal
|
||||
|
||||
class BigDecimalExpectationsSpec : Spek({
|
||||
include(object : ch.tutteli.atrium.specs.integration.BigDecimalExpectationsSpec(
|
||||
@Suppress("DEPRECATION") fun1<BigDecimal, BigDecimal>(Expect<BigDecimal>::toBe),
|
||||
@Suppress("DEPRECATION") fun1<BigDecimal?, BigDecimal?>(Expect<BigDecimal?>::toBe).withNullableSuffix(),
|
||||
fun1<BigDecimal?, Nothing?>(Expect<BigDecimal?>::toBe).withNullableSuffix(),
|
||||
@Suppress("DEPRECATION") fun1<BigDecimal, BigDecimal>(Expect<BigDecimal>::toEqual),
|
||||
@Suppress("DEPRECATION") fun1<BigDecimal?, BigDecimal?>(Expect<BigDecimal?>::toEqual).withNullableSuffix(),
|
||||
fun1<BigDecimal?, Nothing?>(Expect<BigDecimal?>::toEqual).withNullableSuffix(),
|
||||
Expect<Any>::toEqual,
|
||||
@Suppress("DEPRECATION") Expect<BigDecimal>::notToBe.name to @Suppress("DEPRECATION") Expect<BigDecimal>::notToBe,
|
||||
@Suppress("DEPRECATION") Expect<BigDecimal>::notToEqual.name to @Suppress("DEPRECATION") Expect<BigDecimal>::notToEqual,
|
||||
Expect<Any>::notToEqual,
|
||||
Expect<BigDecimal>::isNumericallyEqualTo.name to Expect<BigDecimal>::isNumericallyEqualTo,
|
||||
Expect<BigDecimal>::isNotNumericallyEqualTo.name to Expect<BigDecimal>::isNotNumericallyEqualTo,
|
||||
Expect<BigDecimal>::isEqualIncludingScale.name to Expect<BigDecimal>::isEqualIncludingScale,
|
||||
Expect<BigDecimal>::isNotEqualIncludingScale.name to Expect<BigDecimal>::isNotEqualIncludingScale
|
||||
Expect<BigDecimal>::toEqualNumerically.name to Expect<BigDecimal>::toEqualNumerically,
|
||||
Expect<BigDecimal>::notToEqualNumerically.name to Expect<BigDecimal>::notToEqualNumerically,
|
||||
Expect<BigDecimal>::toEqualIncludingScale.name to Expect<BigDecimal>::toEqualIncludingScale,
|
||||
Expect<BigDecimal>::notToEqualIncludingScale.name to Expect<BigDecimal>::notToEqualIncludingScale
|
||||
) {})
|
||||
|
||||
describe("fun toBe for BigDecimal? and subject is null") {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package ch.tutteli.atrium.api.fluent.en_GB.samples
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
import java.math.BigDecimal
|
||||
import kotlin.test.Test
|
||||
|
||||
class BigDecimalExpectationSamples {
|
||||
|
||||
@Test
|
||||
fun toEqual() {
|
||||
// only use toEqual to check against null, otherwise use toEqualNumerically or toEqualIncludingScale
|
||||
expect(null as BigDecimal?).toEqual(null)
|
||||
}
|
||||
}
|
||||
@@ -12,38 +12,38 @@ import org.spekframework.spek2.style.specification.Suite
|
||||
import java.math.BigDecimal
|
||||
|
||||
abstract class BigDecimalExpectationsSpec(
|
||||
toBeDontUse: Fun1<BigDecimal, BigDecimal>,
|
||||
toBeNullableDontUse: Fun1<BigDecimal?, BigDecimal?>,
|
||||
toBeNull: Fun1<BigDecimal?, Nothing?>,
|
||||
toBeAnyFun: Expect<Any>.(Any) -> Expect<Any>,
|
||||
notToBe: Fun1<BigDecimal, BigDecimal>,
|
||||
notToBeAnyFun: Expect<Any>.(Any) -> Expect<Any>,
|
||||
isNumericallyEqualTo: Fun1<BigDecimal, BigDecimal>,
|
||||
isNotNumericallyEqualTo: Fun1<BigDecimal, BigDecimal>,
|
||||
isEqualIncludingScale: Fun1<BigDecimal, BigDecimal>,
|
||||
isNotEqualIncludingScale: Fun1<BigDecimal, BigDecimal>,
|
||||
toEqualDontUse: Fun1<BigDecimal, BigDecimal>,
|
||||
toEqualNullableDontUse: Fun1<BigDecimal?, BigDecimal?>,
|
||||
toEqualNull: Fun1<BigDecimal?, Nothing?>,
|
||||
toEqualAnyFun: Expect<Any>.(Any) -> Expect<Any>,
|
||||
notToEqual: Fun1<BigDecimal, BigDecimal>,
|
||||
notToEqualAnyFun: Expect<Any>.(Any) -> Expect<Any>,
|
||||
toEqualNumerically: Fun1<BigDecimal, BigDecimal>,
|
||||
notToEqualNumerically: Fun1<BigDecimal, BigDecimal>,
|
||||
toEqualIncludingScale: Fun1<BigDecimal, BigDecimal>,
|
||||
notToEqualIncludingScale: Fun1<BigDecimal, BigDecimal>,
|
||||
describePrefix: String = "[Atrium] "
|
||||
) : Spek({
|
||||
|
||||
include(object : SubjectLessSpec<BigDecimal>(
|
||||
describePrefix,
|
||||
isNumericallyEqualTo.forSubjectLess(BigDecimal.TEN),
|
||||
isNotNumericallyEqualTo.forSubjectLess(BigDecimal.TEN),
|
||||
isEqualIncludingScale.forSubjectLess(BigDecimal.TEN),
|
||||
isNotEqualIncludingScale.forSubjectLess(BigDecimal.TEN)
|
||||
toEqualNumerically.forSubjectLess(BigDecimal.TEN),
|
||||
notToEqualNumerically.forSubjectLess(BigDecimal.TEN),
|
||||
toEqualIncludingScale.forSubjectLess(BigDecimal.TEN),
|
||||
notToEqualIncludingScale.forSubjectLess(BigDecimal.TEN)
|
||||
) {})
|
||||
|
||||
include(object : SubjectLessSpec<BigDecimal?>(
|
||||
"$describePrefix[nullable] ",
|
||||
toBeNull.forSubjectLess(null)
|
||||
toEqualNull.forSubjectLess(null)
|
||||
) {})
|
||||
|
||||
fun describeFun(vararg pairs: SpecPair<*>, body: Suite.() -> Unit) =
|
||||
describeFunTemplate(describePrefix, pairs.map { it.name }.toTypedArray(), body = body)
|
||||
|
||||
describeFun(isNumericallyEqualTo, isNotNumericallyEqualTo) {
|
||||
val isNumericallyEqualToFun = isNumericallyEqualTo.lambda
|
||||
val isNotNumericallyEqualToFun = isNotNumericallyEqualTo.lambda
|
||||
describeFun(toEqualNumerically, notToEqualNumerically) {
|
||||
val toEqualNumericallyFun = toEqualNumerically.lambda
|
||||
val notToEqualNumericallyFun = notToEqualNumerically.lambda
|
||||
|
||||
mapOf(
|
||||
BigDecimal.TEN to BigDecimal("10.00"),
|
||||
@@ -53,12 +53,12 @@ abstract class BigDecimalExpectationsSpec(
|
||||
BigDecimal.ZERO to BigDecimal("00.0")
|
||||
).forEach { (subject, expected) ->
|
||||
context("subject $subject and expected $expected") {
|
||||
it("`${isNumericallyEqualTo.name}` does not throw") {
|
||||
expect(subject).isNumericallyEqualToFun(expected)
|
||||
it("`${toEqualNumerically.name}` does not throw") {
|
||||
expect(subject).toEqualNumericallyFun(expected)
|
||||
}
|
||||
it("`${isNotNumericallyEqualTo.name}` throws AssertionError") {
|
||||
it("`${notToEqualNumerically.name}` throws AssertionError") {
|
||||
expect {
|
||||
expect(subject).isNotNumericallyEqualToFun(expected)
|
||||
expect(subject).notToEqualNumericallyFun(expected)
|
||||
}.toThrow<AssertionError> {
|
||||
messageToContain(
|
||||
subject,
|
||||
@@ -74,9 +74,9 @@ abstract class BigDecimalExpectationsSpec(
|
||||
BigDecimal.ZERO to BigDecimal("0.0000001")
|
||||
).forEach { (subject, expected) ->
|
||||
context("subject $subject and expected $expected") {
|
||||
it("`${isNumericallyEqualTo.name}` throws AssertionError") {
|
||||
it("`${toEqualNumerically.name}` throws AssertionError") {
|
||||
expect {
|
||||
expect(subject).isNumericallyEqualToFun(expected)
|
||||
expect(subject).toEqualNumericallyFun(expected)
|
||||
}.toThrow<AssertionError> {
|
||||
messageToContain(
|
||||
subject,
|
||||
@@ -84,61 +84,61 @@ abstract class BigDecimalExpectationsSpec(
|
||||
)
|
||||
}
|
||||
}
|
||||
it("`$isNotNumericallyEqualTo` does not throw") {
|
||||
expect(subject).isNotNumericallyEqualToFun(expected)
|
||||
it("`$notToEqualNumerically` does not throw") {
|
||||
expect(subject).notToEqualNumericallyFun(expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val assertTen = expect(BigDecimal.TEN as BigDecimal)
|
||||
val assertNullableTen: Expect<BigDecimal?> = expect(BigDecimal.TEN)
|
||||
val assertTenAny = expect(BigDecimal.TEN as Any)
|
||||
val expectTen = expect(BigDecimal.TEN as BigDecimal)
|
||||
val expectNullableTen: Expect<BigDecimal?> = expect(BigDecimal.TEN)
|
||||
val expectTenAsAny = expect(BigDecimal.TEN as Any)
|
||||
describeFun(
|
||||
toBeDontUse,
|
||||
toBeNullableDontUse,
|
||||
isEqualIncludingScale,
|
||||
notToBe,
|
||||
isNotEqualIncludingScale
|
||||
toEqualDontUse,
|
||||
toEqualNullableDontUse,
|
||||
toEqualIncludingScale,
|
||||
notToEqual,
|
||||
notToEqualIncludingScale
|
||||
) {
|
||||
val toBeFun = toBeDontUse.lambda
|
||||
val toBeNullableFun = toBeNullableDontUse.lambda
|
||||
val isEqualIncludingScaleFun = isEqualIncludingScale.lambda
|
||||
val notToBeFun = notToBe.lambda
|
||||
val isNotEqualIncludingScaleFun = isNotEqualIncludingScale.lambda
|
||||
val toEqualFun = toEqualDontUse.lambda
|
||||
val toEqualNullableFun = toEqualNullableDontUse.lambda
|
||||
val toEqualIncludingScaleFun = toEqualIncludingScale.lambda
|
||||
val notToEqualFun = notToEqual.lambda
|
||||
val notToEqualIncludingScaleFun = notToEqualIncludingScale.lambda
|
||||
|
||||
val failureHintNotNumerically = String.format(
|
||||
DescriptionBigDecimalAssertion.FAILURE_IS_EQUAL_INCLUDING_SCALE_BUT_NUMERICALLY_EQUAL.getDefault(),
|
||||
isNotNumericallyEqualTo.name
|
||||
notToEqualNumerically.name
|
||||
)
|
||||
context("subject is 10 and expected is 10") {
|
||||
val expected = BigDecimal("10")
|
||||
it("${toBeDontUse.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
it("${toEqualDontUse.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
expect {
|
||||
assertTen.toBeFun(expected)
|
||||
expectTen.toEqualFun(expected)
|
||||
}.toThrow<PleaseUseReplacementException>()
|
||||
}
|
||||
it("${toBeDontUse.name} with BigDecimal? overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
it("${toEqualDontUse.name} with BigDecimal? overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
expect {
|
||||
assertNullableTen.toBeNullableFun(expected)
|
||||
expectNullableTen.toEqualNullableFun(expected)
|
||||
}.toThrow<PleaseUseReplacementException>()
|
||||
}
|
||||
it("${notToBe.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
it("${notToEqual.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
expect {
|
||||
assertTen.notToBeFun(expected)
|
||||
expectTen.notToEqualFun(expected)
|
||||
}.toThrow<PleaseUseReplacementException>()
|
||||
}
|
||||
|
||||
it("${toBeDontUse.name} with Any overload does not throw") {
|
||||
assertTenAny.toBeAnyFun(expected)
|
||||
it("${toEqualDontUse.name} with Any overload does not throw") {
|
||||
expectTenAsAny.toEqualAnyFun(expected)
|
||||
}
|
||||
it("$isEqualIncludingScale does not throw") {
|
||||
assertTen.isEqualIncludingScaleFun(expected)
|
||||
it("$toEqualIncludingScale does not throw") {
|
||||
expectTen.toEqualIncludingScaleFun(expected)
|
||||
}
|
||||
|
||||
it("${notToBe.name} with Any overload throws an AssertionError and does not contain the hint") {
|
||||
it("${notToEqual.name} with Any overload throws an AssertionError and does not contain the hint") {
|
||||
expect {
|
||||
assertTenAny.notToBeAnyFun(expected)
|
||||
expectTenAsAny.notToEqualAnyFun(expected)
|
||||
}.toThrow<AssertionError> {
|
||||
message {
|
||||
toContain(BigDecimal.TEN, "${NOT_TO_BE.getDefault()}: $expected")
|
||||
@@ -146,9 +146,9 @@ abstract class BigDecimalExpectationsSpec(
|
||||
}
|
||||
}
|
||||
}
|
||||
it("${isNotEqualIncludingScale.name} throws an AssertionError and does not contain the hint") {
|
||||
it("${notToEqualIncludingScale.name} throws an AssertionError and does not contain the hint") {
|
||||
expect {
|
||||
assertTen.isNotEqualIncludingScaleFun(expected)
|
||||
expectTen.notToEqualIncludingScaleFun(expected)
|
||||
}.toThrow<AssertionError> {
|
||||
message {
|
||||
toContain(
|
||||
@@ -163,27 +163,27 @@ abstract class BigDecimalExpectationsSpec(
|
||||
|
||||
val failureHintNumerically = String.format(
|
||||
DescriptionBigDecimalAssertion.FAILURE_IS_EQUAL_INCLUDING_SCALE_BUT_NUMERICALLY_EQUAL.getDefault(),
|
||||
isNumericallyEqualTo.name
|
||||
toEqualNumerically.name
|
||||
)
|
||||
listOf(
|
||||
BigDecimal("10.0"),
|
||||
BigDecimal("10.00")
|
||||
).forEach { expected ->
|
||||
context("subject is 10 and expected is $expected") {
|
||||
it("${toBeDontUse.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
it("${toEqualDontUse.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
expect {
|
||||
assertTen.toBeFun(expected)
|
||||
expectTen.toEqualFun(expected)
|
||||
}.toThrow<PleaseUseReplacementException>()
|
||||
}
|
||||
it("${notToBe.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
it("${notToEqual.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
expect {
|
||||
assertTen.notToBeFun(expected)
|
||||
expectTen.notToEqualFun(expected)
|
||||
}.toThrow<PleaseUseReplacementException>()
|
||||
}
|
||||
|
||||
it("${toBeDontUse.name} with Any overload throws an AssertionError and does not contain the hint") {
|
||||
it("${toEqualDontUse.name} with Any overload throws an AssertionError and does not contain the hint") {
|
||||
expect {
|
||||
assertTenAny.toBeAnyFun(expected)
|
||||
expectTenAsAny.toEqualAnyFun(expected)
|
||||
}.toThrow<AssertionError> {
|
||||
message {
|
||||
toContain(BigDecimal.TEN, "$toBeDescr: $expected")
|
||||
@@ -191,9 +191,9 @@ abstract class BigDecimalExpectationsSpec(
|
||||
}
|
||||
}
|
||||
}
|
||||
it("${isEqualIncludingScale.name} throws an AssertionError mentioning that ${isNumericallyEqualTo.name} could have been used") {
|
||||
it("${toEqualIncludingScale.name} throws an AssertionError mentioning that ${toEqualNumerically.name} could have been used") {
|
||||
expect {
|
||||
assertTen.isEqualIncludingScaleFun(expected)
|
||||
expectTen.toEqualIncludingScaleFun(expected)
|
||||
}.toThrow<AssertionError> {
|
||||
messageToContain(
|
||||
BigDecimal.TEN,
|
||||
@@ -203,31 +203,31 @@ abstract class BigDecimalExpectationsSpec(
|
||||
}
|
||||
}
|
||||
|
||||
it("${notToBe.name} with Any overload does not throw") {
|
||||
assertTenAny.notToBeAnyFun(expected)
|
||||
it("${notToEqual.name} with Any overload does not throw") {
|
||||
expectTenAsAny.notToEqualAnyFun(expected)
|
||||
}
|
||||
it("${isEqualIncludingScale.name} does not throw") {
|
||||
assertTen.isNotEqualIncludingScaleFun(expected)
|
||||
it("${toEqualIncludingScale.name} does not throw") {
|
||||
expectTen.notToEqualIncludingScaleFun(expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context("subject is 10 and expected is 9") {
|
||||
val expected = BigDecimal("9.999999999999")
|
||||
it("${toBeDontUse.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
it("${toEqualDontUse.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
expect {
|
||||
assertTen.toBeFun(expected)
|
||||
expectTen.toEqualFun(expected)
|
||||
}.toThrow<PleaseUseReplacementException>()
|
||||
}
|
||||
it("${notToBe.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
it("${notToEqual.name} with BigDecimal overload throws ${PleaseUseReplacementException::class.simpleName}") {
|
||||
expect {
|
||||
assertTen.notToBeFun(expected)
|
||||
expectTen.notToEqualFun(expected)
|
||||
}.toThrow<PleaseUseReplacementException>()
|
||||
}
|
||||
|
||||
it("${toBeDontUse.name} with Any overload throws an AssertionError and does not contain the hint") {
|
||||
it("${toEqualDontUse.name} with Any overload throws an AssertionError and does not contain the hint") {
|
||||
expect {
|
||||
assertTenAny.toBeAnyFun(expected)
|
||||
expectTenAsAny.toEqualAnyFun(expected)
|
||||
}.toThrow<AssertionError> {
|
||||
message {
|
||||
toContain(BigDecimal.TEN, "$toBeDescr: $expected")
|
||||
@@ -235,9 +235,9 @@ abstract class BigDecimalExpectationsSpec(
|
||||
}
|
||||
}
|
||||
}
|
||||
it("${isEqualIncludingScale.name} throws an AssertionError and does not contain the hint") {
|
||||
it("${toEqualIncludingScale.name} throws an AssertionError and does not contain the hint") {
|
||||
expect {
|
||||
assertTen.isEqualIncludingScaleFun(expected)
|
||||
expectTen.toEqualIncludingScaleFun(expected)
|
||||
}.toThrow<AssertionError> {
|
||||
message {
|
||||
toContain(
|
||||
@@ -249,19 +249,19 @@ abstract class BigDecimalExpectationsSpec(
|
||||
}
|
||||
}
|
||||
|
||||
it("${notToBe.name} with Any overload does not throw") {
|
||||
assertTenAny.notToBeAnyFun(expected)
|
||||
it("${notToEqual.name} with Any overload does not throw") {
|
||||
expectTenAsAny.notToEqualAnyFun(expected)
|
||||
}
|
||||
it("${isEqualIncludingScale.name} does not throw") {
|
||||
assertTen.isNotEqualIncludingScaleFun(expected)
|
||||
it("${toEqualIncludingScale.name} does not throw") {
|
||||
expectTen.notToEqualIncludingScaleFun(expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describeFun(toBeNull) {
|
||||
val toBeFun = toBeNull.lambda
|
||||
describeFun(toEqualNull) {
|
||||
val toEqualFun = toEqualNull.lambda
|
||||
it("does not throw if subject is null") {
|
||||
expect(null as BigDecimal?).toBeFun(null)
|
||||
expect(null as BigDecimal?).toEqualFun(null)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user