Skip to content

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

Description

@ash211

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");
    });
  });

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions