Conversation
| @Test | ||
| void shouldNotCallUpstreamReporterIfBugSuppressed() { | ||
| // given | ||
| BugInstance suppressed = mock(BugInstance.class); |
There was a problem hiding this comment.
Why mix annotation-based and method-based mocks? This could become another annotated field.
There was a problem hiding this comment.
There are three tests, one calls the bug instance suppressed, the second calls it reported and the third one does not create a bug instance, so I think it makes sense that @mafor used a local variable here
There was a problem hiding this comment.
There is no need for the tests to use different names for the instance. As I see it, we just have 2/3 tests creating an instance mock, so it makes sense to be consistent with other values by making it an annotated field.
There was a problem hiding this comment.
I have made the change to create the instance with @Mock
| // when | ||
| matcher.addSuppressor(suppressor); | ||
| // then | ||
| assertTrue(matcher.match(bugInstance), "Should match BugInstance"); |
There was a problem hiding this comment.
Error messages should give more detail about the failed value(s) if possible, especially for assertTrue (which doesn't give much detail natively)
There was a problem hiding this comment.
I've looked into this and do not see a practical way for the matcher to return why the instance wasn't matched.
We're using the term matcher for two separate things:
- the suppression matchers we're using to filter out detected bugs
- the hamcrest matchers we're using in unit tests (these matchers do provide messages)
I think it is fine to leave the test like that, it is short enough so we can reason about it
There was a problem hiding this comment.
The message could at least specify which suppression matcher is being applied? It could be deduced anyway by tracing the test, but seeing it at a glance is better.
There was a problem hiding this comment.
The suppressor is mocked here, so there's no real reason for the instance to be suppressed besides the suppressor being mocked to return false.
| void shouldNotMatchBugInstance() { | ||
| // given | ||
| when(suppressor.match(bugInstance)).thenReturn(false); | ||
| when(suppressor.buildUselessSuppressionBugInstance()).thenReturn(uselessSuppressionBugInstance); |
There was a problem hiding this comment.
The two tests mock objects differently:
when(suppressor.match(bugInstance)).thenReturn(true);
and:
when(suppressor.match(bugInstance)).thenReturn(false);
So I think this can't be factored in init
There was a problem hiding this comment.
Those lines are different, yes, but making the suppressor return the instance is the same in both.
There was a problem hiding this comment.
Sorry, I don't follow: the suppressor does not return the instance and I don't think that it would be clearer to extract this:
OngoingStubbing<Boolean> when = when(suppressor.match(bugInstance));
There was a problem hiding this comment.
Line 57, specifically, is duplicated across multiple tests, and could be extracted to the setup method.
when(suppressor.buildUselessSuppressionBugInstance()).thenReturn(uselessSuppressionBugInstance);
There was a problem hiding this comment.
Sorry I'm still lost, I don't see duplications for that line in SuppressionMatcherMockedTest
| // when | ||
| boolean matched = matcher.match(bug); | ||
| // then | ||
| assertThat("Should match the bug", matched, is(true)); |
There was a problem hiding this comment.
This ultimately doesn't give any more information than using assertTrue. If possible the error message should say more about the bug value.
There was a problem hiding this comment.
I'm not sure how to extract the reason why the instance was matched or not, I think the test is fine like that
| <LongDescription>Suppressing annotation on the class {0} is unnecessary</LongDescription> | ||
| <Details> | ||
| <


I'm not sure why but we never answered #1054 and the PR got abandoned.
Reporting useless
@SuppressFBWarningsannotations would be useful indeed and this would fix #641This PR merges the original work from @mafor with the latest version.