Skip to content

argumentCaptor for multiple arguments/types #233

Open
@dsebastien

Description

@dsebastien

Is it or would it be possible to do something like this:

argumentsCaptor<Foo, Bar>().apply {
  verify(myClass, times(2)).setItems(argumentsCaptor.capture(0), argumentsCaptor.capture(1))
  assertEquals("firstArgValue", firstValue[0].propOnFirstArg)
  assertEquals("secondArgValue", firstValue[1].propOnSecondArg)
  ...
}

Thus easily create multiple KArgumentCaptor instances for different types, capturing different arguments.

Currently I have code like this that I'd like to improve:

val nameUpdatedEventCaptor = argumentCaptor<NameUpdatedV1>()
        val streamNameCaptor = argumentCaptor<String>()
        verify(eventBusMock, times(1)).post(nameUpdatedEventCaptor.capture(), streamNameCaptor.capture())

        assertNotNull(nameUpdatedEventCaptor.firstValue)
        assertEquals(command.uuid, nameUpdatedEventCaptor.firstValue.personId)
        assertEquals(command.name, nameUpdatedEventCaptor.firstValue.name)
        assertEquals(
            NameService.TOPIC_NAME,
            streamNameCaptor.firstValue,
            "Event not sent to the expected topic"
        )

As you can see above, I have to declare multiple KArgumentCaptor, which is kind pretty verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions