assertArg should allow lambda to throw checked exceptions · Issue #12 · szpak/mockito-java8 · GitHub
Skip to content

assertArg should allow lambda to throw checked exceptions #12

Description

@jypma

When testing code like this (combining mockito + assertJ + mockito-java8), with some assertJ JSON psuedo-code:

    verify(myObject.someMethod(assertArg(s -> {
        assertThat(s).isJSON();
        assertThat(Jackson.parseJSON(s)).hasProperty("foo");   // throws JSONParseException
    });

If Jackson.parseJSON throws a checked exception, the compiler wants me to catch it inside the lambda. However, that exception should just fail the test, since like any other exception, it means something unexpected has gone wrong.

Hence, I suggest assertArg be widened to take a CheckedConsumer<T> type:

    @FunctionalInterface
    interface CheckedConsumer<T> {
        void accept(T value) throws Throwable;
    }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions