assertj icon indicating copy to clipboard operation
assertj copied to clipboard

Suggesting a doesNotThrowAnyExceptionExcept(...) method

Open pandoras-toolbox opened this issue 1 year ago • 3 comments

Feature summary

As discussed in another issue, here is the suggestion to support being able to ignore certain exceptions when not expecting exceptions.

It would be similar to what can be done with the Selenium API:

   // Waiting 30 seconds for an element to be present on the page, checking
   // for its presence once every 5 seconds.
   Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
       .withTimeout(Duration.ofSeconds(30L))
       .pollingEvery(Duration.ofSeconds(5L))
       .ignoring(NoSuchElementException.class);

Example

That is how it can look in AssertJ:

assertThatCode(() -> { thisFunctionDoesNothing(); })
                .doesNotThrowAnyExceptionExcept(NoSuchElementException.class, IOException.class);

pandoras-toolbox avatar Nov 02 '23 08:11 pandoras-toolbox

@joel-costigliola Is this one free for taking?

pbacz avatar Nov 08 '23 16:11 pbacz

It is @pbacz :wink:

joel-costigliola avatar Nov 11 '23 22:11 joel-costigliola

@joel-costigliola Great 👍🏻 I'd like to contribute. Before I begin I'd like to clarify. When doesNotThrowAnyExceptionExcept(IOException.class) is called and a subclass of IOException is thrown, then the case should pass, shouldn't it.

pbacz avatar Nov 12 '23 10:11 pbacz