Skip to content

Mockito confuses varargs and single-param methods (regression) #1593

@lewisd32

Description

@lewisd32

In Mockito 2.2.5 and later, when setting expectations for mocking a varargs method, using an array doesn't work:

Mockito.when(good.call(Mockito.any(String[].class))).thenReturn(1L);

And instead the contained type must be used:

Mockito.when(good.call(Mockito.any(String.class))).thenReturn(1L);

However in the face of an overload of the varargs method that takes a single argument (of the same type):

    Long call(String value);
    Long call(String... values);

This results in being unable to set an expectation for the varargs call.
This worked previously in Mockito 2.2.4 and earlier.

Reproducer: mockito-bug.tar.gz

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions