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

Ship Kotlin helper functions by default #2896

Open
vlsi opened this issue Dec 29, 2022 · 0 comments
Open

Ship Kotlin helper functions by default #2896

vlsi opened this issue Dec 29, 2022 · 0 comments
Labels
language: Kotlin An issue related to using AssertJ with Kotlin

Comments

@vlsi
Copy link
Contributor

vlsi commented Dec 29, 2022

Feature summary

There's a value in shipping Kotlin-friendly API by default.

See https://github.com/junit-team/junit5/blob/main/junit-jupiter-api/src/main/kotlin/org/junit/jupiter/api/Assertions.kt

For example, the current SoftAssertions syntax is

SoftAssertions.assertSoftly { softly ->
    // ...
    softly.assertThat(...).isEqualTo(...)
    // ...
    softly.assertAll()
}

The issue is that it is verbose, and the user might fail to call assertAll.

A better variation would be

assertSoftly {
    assertThat(...).isEqualTo(...)
    // no need to call assertAll, it would be automatic
}

That is achievable with a small helper:

    fun assertSoftly(body: SoftAssertions.() -> Unit) =
        SoftAssertions.assertSoftly(body)
@scordio scordio added the language: Kotlin An issue related to using AssertJ with Kotlin label Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language: Kotlin An issue related to using AssertJ with Kotlin
Projects
None yet
Development

No branches or pull requests

2 participants