Skip to content

ArgumentCaptor can't capture varargs-arrays #584

@ChristianSchwarz

Description

@ChristianSchwarz

Relates to: #439, #565, #567, #583

ArgumentCaptor can't capture varargs-arrays.

@Test
public void shouldCaptureVarArgsAsArray() throws Exception {
    ArgumentCaptor<String[]> varargCaptor = ArgumentCaptor.forClass(String[].class);

    mock.varargs("1","2");   

    verify(mock).varargs(varargCaptor.capture());

    assertThat(varargCaptor).containsExactly(new String[]{"1","2"});
}

Expected: A ArgumentCaptor<String[]> should be able to capture the varargs-array as a whole.
Actual: The ArgumentCaptor captures no arrays but every single argument passed to the varargs method. The following exception is thrown:

java.lang.AssertionError: 
Actual and expected should have same size but actual size was:
  <2>
while expected size was:
  <1>
Actual was:
  <["1", "2"]>
Expected was:
  <[["1", "2"]]>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions