Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Update unit test to avoid deprecated `ExpectedException.none()` by using `Assert.assertThrows()`

Open
#275 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
testing

Research direction

Search the repository for ExpectedException.none(), expectIllegalStateIsNotShowingComponent, and expectIllegalStateIsDisabledComponent to identify all affected unit tests and helpers. Run the relevant unit-test suite before and after the replacements; done means the deprecated usages are removed and the tests retain their existing exception and message assertions.

Written by the indexing model from the issue text.

Description

ExpectedException.none() is marked as deprecated but there are so many unit tests which depends on the function.
These cases can be rewritten by using Assert.assertThrows(Class<?> class, ThrowableRunnable run)

There are also Similar deprecation; expectIllegalStateIsNotShowingComponent and expectIllegalStateIsDisabledComponent

These can be implemented as like as followings;


  public static AbstractStringAssert<?> assertThatIllegalStateExceptionCauseIsDisabledComponent(ThrowingRunnable r) {
      Throwable t = Assert.assertThrows(IllegalStateException.class, r);
      return assertThat(t.getMessage()).contains("Expecting component").contains("to be enabled");
  }

  public static AbstractStringAssert<?> assertThatIllegalStateExceptionCauseIsNotShowingComponent(ThrowingRunnable r) {
      Throwable t = Assert.assertThrows(IllegalStateException.class, r);
      return assertThat(t.getMessage()).contains("Expecting component").contains("to be shown on the screen");
  }
  public static AbstractStringAssert<?> assertThatIllegalStateExceptionCauseIsNotResizableComponent(ThrowingRunnable runnable) {
    Throwable t = Assert.assertThrows(IllegalStateException.class, runnable);
    return assertThat(t.getMessage()).contains("Expecting component").contains("to be resizable by the user");
  }
Dominant language
Java
Stars
121
Forks
52
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from assertj/assertj-swing

All issues in assertj/assertj-swing

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.