Skip to content

MockitoHamcrest#argThat does not allow "super" matchers #1817

@spjoe

Description

@spjoe

IMHO to really follow the hamcrest matchers design philosophy the argThat interface should look like this: public static <T> T argThat(Matcher<? super T> matcher), but unfortunately it is

public static <T> T argThat(Matcher<T> matcher) {

this change would allow a statement like the following:
verify(mock).aMethod(argThat(nullValue()))

I see that the default value is derived from the concrete matcher type, which of course would not work anymore. To circumvent this problem, it would be possible to provide a overload for primitives types.

Or provide a new argThat method, for example argThatSuper which always returns null, but of course would not work for primitive types. Than the existing argThat would keep its behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions