Use MeterRegistry.isClosed() for tests #14975
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
while working on #14972 I noticed that in quite some tests in this package we have a method called
spyOnDisposableBean
that gets duplicated and seems rather complicated - at least for the purpose of just being able to verify thatstop()
is called on MeterRegistry instances.My initial thought here was to extract this into some utility class to at least get rid of the duplication. The problem here was to find an appropriate place and name for the class. And of course, the complexity of the method remained.
So after giving this a bit more thought, I found a solution that doesn't need reflection and spying at all. We could simply check for
MeterRegistry.isClosed()
, which is slightly different tostop()
, but still gets the job done if you ask me. The destroyMethod of the underlying bean seems to point toclose()
anyway, so we should be safe here.Let me know what you think.
Cheers,
Christoph