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

StepVerifier expectErrorMatches() extension #34

Open
kiwisincebirth opened this issue Feb 24, 2022 · 0 comments
Open

StepVerifier expectErrorMatches() extension #34

kiwisincebirth opened this issue Feb 24, 2022 · 0 comments
Labels
❓need-triage This issue needs triage, hasn't been looked at by a team member yet

Comments

@kiwisincebirth
Copy link
Contributor

Motivation

I'm looking to ease development of testing code using Step Verifier and checking for Exception Types and messages to ensure the appropriate error was raised.

// This is how the existing test code looks
myService.myFunction().test()
    .verifyErrorMatches { it is MyException && it.message == "My Message" }

// And this is a more Kotlin idiomatic code could look like
myService.myFunction().test()
    .verifyErrorMatches<MyException> { it.message == "My Message" }

While the above is not dissimilar it does seperate out the typing from the predicate, which adds to clarity IMHO. Also note the it in the second example is typed to MyException so you can test properties with out further casting.

Desired solution

This is the functions which would implement this

inline fun <reified T : Throwable> LastStep.expectErrorMatches(crossinline predicate: (T)->Boolean = {true}): StepVerifier =
    expectErrorMatches { it is T && predicate(it) }

inline fun <reified T : Throwable> LastStep.verifyErrorMatches(crossinline predicate: (T)->Boolean = {true}): Duration = 
    verifyErrorMatches { it is T && predicate(it) }

Considered alternatives

Haven't consider other alternatives, except verifyErrorMessage() expectErrorMessage() but these dont allow checking of type. That I am aware, so dont offer the full ability of xxxErrorMatches()

@reactorbot reactorbot added the ❓need-triage This issue needs triage, hasn't been looked at by a team member yet label Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓need-triage This issue needs triage, hasn't been looked at by a team member yet
Projects
None yet
Development

No branches or pull requests

2 participants