Skip to content

Lambda in assertArg called twice #5

Description

@CalamarBicefalo

We have found an interesting issue, that seems to be caused by assertArg. For the following test

    verify(mockedService).functionThatExpectsAnInputStream(assertArg((InputStream is) -> {
            try {
                // Oh my god this thing gets invoked twice !! 
                assertThat(IOUtils.toByteArray(is),is("a,b,c".getBytes()));
            } catch (IOException e) {
                fail();
            }
        }));

The lambda block gets invoked twice, being the IS in the second execution empty.

However if the same logic is done using a regular ArgumentCaptor, it works as expected (a single execution is done):

        ArgumentCaptor<InputStream> is = ArgumentCaptor.forClass(InputStream.class);
        verify(mockedService).functionThatExpectsAnInputStream(is.capture());
        assertThat(is.getValue(),notNullValue());
        assertThat(IOUtils.toByteArray(is.getValue()),is("a,b,c".getBytes()));

We could provide further context if needed.

Thank you very much.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions