Repository navigation
Conversation
0verEngineer
left a comment
There was a problem hiding this comment.
A few remarks on the tests. The cache race in ProblemTextFilter is tracked separately in #127.
| void changedFilterListIsApplied() { | ||
| assertTrue(ProblemTextFilter.isFiltered("Field 'x' is never used", "field")); | ||
| assertFalse(ProblemTextFilter.isFiltered("Field 'x' is never used", "*fiel")); | ||
| assertFalse(ProblemTextFilter.isFiltered("Field 'x' is never used", "*fiel")); |
There was a problem hiding this comment.
This is the same assertion as the line above, so the sequence checks less than it looks like. Was this meant to use a different list or text? With only two lists that alternate, the test would also pass with a cache that is rebuilt on every call, so a third distinct list (e.g. field → *fiel → re:never → field) would make it actually exercise the invalidation.
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class ProblemTextFilterTest { |
There was a problem hiding this comment.
All tests share the static cache in ProblemTextFilter (cachedRawFilterList / cachedFilters) and never reset it, so what a test actually exercises depends on what the previous test left behind. For example, if nullFilterListIsIgnored runs first, Objects.equals(null, null) is true on the initial state and parse(null) is never called. A small package-private resetCache() (@VisibleForTesting) called from a @BeforeEach would make the tests independent of the method order.
|
|
||
| @Test | ||
| void regexMatchesTextPattern() { | ||
| assertTrue(ProblemTextFilter.isFiltered("'ThreadXsleep()' called in loop", "re:ad.sleep")); |
There was a problem hiding this comment.
There is no test for an entry that both starts with re: and contains */?, so the regex-before-glob precedence in toFilter() is not covered. If the two checks were swapped, re:foo.*bar would become a glob with a literal re: prefix and no test would fail. Something like assertTrue(ProblemTextFilter.isFiltered("foo x bar", "re:foo.*bar")) would pin it down.
|
|
||
| @ParameterizedTest | ||
| @CsvSource({ | ||
| "Field 'x' is never used,todo;fIELD", |
There was a problem hiding this comment.
Nit: ' is JUnit's default quote character in @CsvSource. It works here because the quotes are in the middle of the field, but a row whose text starts with an apostrophe (like 'Thread.sleep()' called in loop used further down) would be parsed as a quoted field. Setting quoteCharacter = '"' avoids that trap for future rows.
Follow-up to #125: this adds tests for the problem filter list.
Why the small change in
src/mainProblemTextFilter.isFiltered(String)reads the filter list viaSettingsState.getInstance(), which needs a running IntelliJ application. That makes the filter logic impossible to reach from a plain unit test.So I split it up:
isFiltered(String)still reads the setting, and then passes it toisFiltered(String problemText, String rawFilterList), marked@VisibleForTesting, which contains the existing logic.getFilters()now takes the raw filter list as a parameter instead of reading the setting itself.The behavior of the public method is unchanged, and the static cache is still keyed by the raw filter string, so a changed setting is still re-parsed as before.
What is covered
ProblemTextFilterTestcovers the cases described in the Javadoc (15 test cases in total):;;) are ignored, so they don't filter everythingre:entries match anywhere in the text, and there:prefix is case-insensitivenullproblem text is filtered,nullor empty filter lists filter nothingTesting
./gradlew testpasses locally:ListenerTest6/6,ProblemTextFilterTest15/15.The CHANGELOG has an entry under
[Unreleased]→ Added.