Allow `announce` to pass event arguments


When testing interceptors with mock events, if the interceptor method calls another interception, the announced interception called by the invoked method operates on a separate request context, other than the mock provided.

The same problem applies when running integration tests which pass in mocked methods.

Suggested improvement: Allow a convention for `announce` and `processState@InterceptorService` to pass in explicit event arguments, which would allow for test isolation of the request context.

Currently the `announce` method explicitly sets the `event` here:

It would be simple enough to add a ternary to check for its presence in the intercept data and fall back to the actual context.


Luis Majano
3 days ago

If you are doing a unit test and announcing another interception within your interceptor, then it calls for you to mock that call so it never goes out.

You don’t need to test that interception, just that it was made. So I see no point in adding more machinery to something that shouldn’t happen in a unit test scenario.

As for integration tests, what is the problem of getting the same request context? I would have to see some test code and target code to see how that can be improved.

Jon Clausen
2 days ago

From an integration standpoint, the final results of test A might depend on the results of Test B. Since setup() should clear the old event, it’s arguable that you could just use that context and then mock it.

I guess the end game on this is a way to merge the retrieved mock context so that the RequestService operates on it as the actual context

Luis Majano
4 hours ago

Sure, if you want to get into that then you would have to mock the context but you could potentially leave the actual integration service in a mocked state that could affect other integration tests later down the process.

I have found that it’s best to mock the data than the entire context when doing integration tests. It avoid side-effects where tests that execute AFTER your mocking are affected by it. If not, you get into a situation that you need to cleanup your mocks.


Luis Majano


Jon Clausen