BugChecker for effectively unused `PublisherProbe`s
Opened this issue · 1 comments
Problem
Reactor's PublisherProbe
defines a neat API to test reactive code. However, it is only helpful when it is actually used.
Considering the following code snippet, the PublisherProbe
is initialized and asserted, but never actually used. Surely we can assert that it was never subscribed to, because we never included it in code that should be subscribed to. 🙂
@Test
void probeBugChecker() {
PublisherProbe<Void> probe = PublisherProbe.empty();
// some test code that doesn't involve `probe`
probe.assertWasNotSubscribed();
}
This looks like an unintentional human mistake that wrongfully could increase the author's confidence in their production code.
Description of the proposed new feature
- Support a stylistic preference.
- Avoid a common gotcha, or potential problem.
- Improve performance.
I'd like to have a BugChecker that identifies such a construct as a common mistake and expects changes.
Considerations
In essence, this BugChecker should flag in the following scenario:
- A
PublisherProbe
is declared and initialized - Is used exclusively in assertion calls (e.g.
PublisherProbe#assertWasNotSubscribed
).
The BugChecker should not flag if
- The
PublisherProbe
is used- as a mocked value with
PublisherProbe#{mono,flux}
- as a parameter to a method, since it could be used for mocking there
- as a mocked value with
Participation
- I am willing to submit a pull request to implement this improvement.
Most likely not within the next couple of weeks.
Something to add: We can also include the following case:
PublisherProbe
is declared and initialized- Probe is used in a mock
- Probe is not used for any assertions