vavr-io / vavr

vʌvr (formerly called Javaslang) is a non-commercial, non-profit object-functional library that runs with Java 8+. It aims to reduce the lines of code and increase code quality.
https://vavr.io
Other
5.59k stars 620 forks source link

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

Open jbrains opened 2 years ago

jbrains commented 2 years ago

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.