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

Add varargs overload to Assert#hasString and Assert#doesNotHaveString #2945

Closed
wants to merge 1 commit into from

Conversation

ascopes
Copy link
Contributor

@ascopes ascopes commented Feb 4, 2023

This overload will delegate to String#format internally, similar to how StringAssert#isEqualTo allows for string templating expansion. This removes the need to write manual formatting in tests that need to consume a fixture placeholder.

Example:

@Test
void toStringReturnsTheExpectedValue() {
  // Given
  var fileRepository = someFileRepository();
  var fileManager = new FileManager(fileRepository);

  // Then
  assertThat(fileManager)
      .hasToString("FileManager{repository=%s}", repository);
}

...rather than the current solution:

@Test
void toStringReturnsTheExpectedValue() {
  // Given
  var fileRepository = someFileRepository();
  var fileManager = new FileManager(fileRepository);

  // Then
  assertThat(fileManager)
      .extracting(FileManager::toString, STRING)
      .isEqualTo("FileManager{repository=%s}", repository);
  // or
  assertThat(fileManager.toString())
      .isEqualTo("FileManager{repository=%s}", repository);
}

@ascopes ascopes force-pushed the task/to-string-format branch 2 times, most recently from 2c72cae to 78c90b5 Compare February 4, 2023 14:53
This overload will delegate to String#format internally, similar to
how StringAssert#isEqualTo allows for string templating expansion.
This removes the need to write manual formatting in tests that
need to consume a fixture placeholder.
@joel-costigliola joel-costigliola added this to the 3.25.0 milestone Feb 5, 2023
joel-costigliola pushed a commit that referenced this pull request Feb 5, 2023
This overload will delegate to String#format internally, similar to
how StringAssert#isEqualTo allows for string templating expansion.
This removes the need to write manual formatting in tests that
need to consume a fixture placeholder.

Fix #2945
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

Successfully merging this pull request may close these issues.

2 participants