Skip to content

MockIntegrationContext.reset() does not behave as expected #3182

Closed
@hgarus

Description

@hgarus

Affects Version(s): 5.2.3.RELEASE using spring-boot 2.2.4.RELEASE

I am developing an application containing multiple IntegrationFlows passing messages to each other using DirectChannels.

I have created several small tests which are testing a single IntegrationFlow each. I have used MockIntegrationContext.substituteMessageHandlerFor() to capture the message once it is passed to the "output channel" of a flow.

However even though I'm calling MockIntegrationContext.reset() in an @AfterEach method, the substituted MockMessageHandlers seem to stick around until the ApplicationContext is torn down.

I have created a minimal gist demonstrating the behavior: https://gist.github.com/hgarus/0ec9714f1d381bd8404c08ddc88f55e3

The assertEquals in line 80 fails because the ArgumentCaptor receives the second message. Even though I called reset() beforehand.

I did some debugging and it seems the substitution only works, when the IntegrationConsumer is stopped before the replacement MessageHandler is assigned to the it - which is done in substituteMessageHandlerFor() (with the default autoStartup = true), but not in reset().

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions