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

Introduce new ExceptionMatcher.with(...) #33

Merged
merged 3 commits into from
May 15, 2024
Merged

Conversation

oswaldobapvicjr
Copy link
Owner

This enhancement introduces a method to allow the extraction of custom exception data by accepting functions or lambda expressions. For example:

assertThat(() ->
{
    throw new MyCustomException(MESSAGE1, ERR_0001, 1910);
},
throwsException(MyCustomException.class)
        .with(MyCustomException::getCustomString, equalTo(ERR_0001))
        .with(MyCustomException::getCode, equalTo(1910))
        .with(MyCustomException::getLocalizedMessage, endsWith(MESSAGE2)));

It can be combined with existing methods. For example:

assertThat(() ->
{
    throw new MyCustomException(MESSAGE1, ERR_0001, 1910);
},
throwsException(MyCustomException.class)
        .with(MyCustomException::getCustomString, equalTo(ERR_0001))
        .with(MyCustomException::getCode, equalTo(1910))
        .withMessageContaining(MESSAGE2)
        .withCause(...));

@oswaldobapvicjr oswaldobapvicjr self-assigned this May 15, 2024
@oswaldobapvicjr oswaldobapvicjr added the enhancement New feature or request label May 15, 2024
@oswaldobapvicjr oswaldobapvicjr merged commit 10367d9 into master May 15, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant