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

CheckedConsumerTests pass whether the CheckedConsumer under test behaves correctly or not #2720

Open
jbrains opened this issue Apr 29, 2022 · 0 comments

Comments

@jbrains
Copy link
Contributor

jbrains commented Apr 29, 2022

Example:

    @Test
    public void shouldApplyThrowingCheckedConsumer() {
        final CheckedConsumer<?> f = t -> { throw new Error(); };
        try {
            f.accept(null);
            fail("should have thrown");
        } catch(Throwable x) {
            // ok
        }
    }

Since AssertionError is-a Throwable, this test would pass, even if f.accept() didn't throw an error. I don't know how many instances of this problem there are throughout the code base.

On the one hand, it seems impossible to cause this problem in this context; however, the general pattern is a mistake.

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