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

Should MappingFailed extend AssertionFailedError? #269

Open
robd opened this issue Jun 9, 2022 · 0 comments
Open

Should MappingFailed extend AssertionFailedError? #269

robd opened this issue Jun 9, 2022 · 0 comments

Comments

@robd
Copy link
Contributor

robd commented Jun 9, 2022

Currently if some code wants to handle assertion failures, this doesn't work for strikt helpers like first() because MappingException extends IncompleteExecutionException, not AssertionError. eg:

  private val failures = mutableListOf<AssertionError>()

  fun doSomethingWithFailures(runnable: Runnable) {
    try {
      runnable.run()
    } catch(assertionFailed: AssertionError) {
      failures.add(assertionFailed)
      throw assertionFailed
    }
  }

  private fun thingUnderTest() = emptyList<String>()

  // failure will be added to failures
  @Test
  fun `thingUnderTest has a catflap`() {
    doSomethingWithFailures {
      expectThat(thingUnderTest()).contains("catflap")
    }
  }

  // failure will not be added to failures
  @Test
  fun `thingUnderTest has a catflap first`() {
    doSomethingWithFailures {
      expectThat(thingUnderTest()).first().isEqualTo("catflap")
    }
  }

Would it be better to have MappingException extend org.opentest4j.AssertionFailedError instead?

@robd robd changed the title Should MappingFailed extent AssertionFailedError? Should MappingFailed extend AssertionFailedError? Jun 9, 2022
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