Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add createAndAppend to AssertionContainer expecting Translatable #1061

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ch.tutteli.atrium.core.ExperimentalNewExpectTypes
import ch.tutteli.atrium.core.None
import ch.tutteli.atrium.core.Option
import ch.tutteli.atrium.core.Some
import ch.tutteli.atrium.reporting.translating.Translatable
import ch.tutteli.atrium.reporting.translating.Untranslatable
import kotlin.reflect.KClass

Expand Down Expand Up @@ -84,8 +85,26 @@ interface AssertionContainer<T> : @kotlin.Suppress("DEPRECATION") SubjectProvide
*
* @return an [Expect] for the subject of `this` expectation.
*/
//TODO remove SUPPRESS with 0.18.0
@Suppress("UNCHECKED_CAST", "DEPRECATION")
fun createAndAppend(description: String, expected: Any?, test: (T) -> Boolean): Expect<T> =
append(assertionBuilder.createDescriptive(this as Expect<T>, Untranslatable(description),expected, test))
createAndAppend(Untranslatable(description),expected, test)

/**
* Creates a [DescriptiveAssertion] based on the given [description], [expected] and [test]
* and [append]s it to the container.
*
* @param description The description of the assertion, e.g., `is less than`.
* @param expected The expected value, e.g., `5`
* @param test Indicates whether the assertion holds or fails.
*
* @return an [Expect] for the subject of `this` expectation.
*/
//TODO remove SUPPRESS with 0.18.0/0.19.0 once the toExpect function is in core
@Suppress("UNCHECKED_CAST")
fun createAndAppend(description: Translatable, expected: Any?, test: (T) -> Boolean): Expect<T> =
append(
assertionBuilder.descriptive
.withTest(this as Expect<T>, test)
.withDescriptionAndRepresentation(description, expected)
.build()
)
}