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

New ServiceExceptionAssert.hasArgSatisfying(...) assertion #1097

Open
ash211 opened this issue Feb 6, 2024 · 0 comments
Open

New ServiceExceptionAssert.hasArgSatisfying(...) assertion #1097

ash211 opened this issue Feb 6, 2024 · 0 comments

Comments

@ash211
Copy link
Contributor

ash211 commented Feb 6, 2024

What happened?

I have an arg that's a long, dynamically computed string (a stacktrace). I'd like to confirm that it contains a certain substring, with a syntax like:

assertThatServiceExceptionThrownBy(() -> throwIt())
  .hasType(MyErrors.MY_ERROR)
  .hasArgSatisfying(arg -> {
    assertThat(arg.getName()).isEqualTo("my-arg");
    assertThat(arg.getValue()).asString().contains("my-substring");
  });

or maybe like this:

assertThatServiceExceptionThrownBy(() -> throwIt())
  .hasType(MyErrors.MY_ERROR)
  .hasArgWithNameSatisfying("my-arg", value -> assertThat(value).asString().contains("my-substring"));

Workaround

Right now I'm doing something like this, but would love to improve it:

assertThatServiceExceptionThrownBy(() -> throwIt())
  .hasType(MyErrors.MY_ERROR)
  .satisfies(serviceException -> assertThat(serviceException.getArgs())
    .satisfiesOnlyOnce(arg -> {
      assertThat(arg.getName()).isEqualTo("my-arg");
      assertThat(arg.getValue()).asString().contains("my-substring");
    });
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant