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

Feature Request: ErrorCollector#checkThrows overload with Matcher<Exception> parameter #1780

Open
Ambeco opened this issue Dec 31, 2024 · 1 comment

Comments

@Ambeco
Copy link

Ambeco commented Dec 31, 2024

Right now, ErrorCollector#checkThrows has no way to make assertions about the exception that is thrown.
This can trivially be safely added, in a backwards compatible way:

	public <E extends Throwable> void checkThrows(
			Class<E> expectedThrowable, ThrowingRunnable runnable, Matcher<E> matcher)
	{
		try {
			checkThat(assertThrows(expectedThrowable, runnable), matcher);
		} catch (AssertionError e) {
			addError(e);
		}
	}

Example Usage:

	@Test public void immutableList_is_immutable() {
		ImmutableList<String> list = list.of();

		collector.checkThrows(UnsupportedOperationException.class, () -> list.add(""), notNullValue());
	}
@marcphilipp
Copy link
Member

@Ambeco Thanks for raising the issue! However, JUnit 4 is in "maintenance mode" which means we currently have no plans of adding new features to it, even if they're small.

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

2 participants