error-prone-support icon indicating copy to clipboard operation
error-prone-support copied to clipboard

BugChecker for effectively unused `PublisherProbe`s

Open werli opened this issue 1 year ago • 0 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. :slightly_smiling_face:

@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.
  • [x] 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:

  1. A PublisherProbe is declared and initialized
  2. 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

Participation

  • [ ] I am willing to submit a pull request to implement this improvement.

Most likely not within the next couple of weeks.

werli avatar Dec 20 '22 19:12 werli