-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor tests #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor tests #35
Conversation
…ests` to `TestHelper` to enable reuse across test classes
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #35 +/- ##
=========================================
+ Coverage 80.9% 81.0% +0.1%
- Complexity 132 136 +4
=========================================
Files 16 16
Lines 567 570 +3
Branches 64 66 +2
=========================================
+ Hits 459 462 +3
+ Misses 69 68 -1
- Partials 39 40 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
sungshik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments
| // Preface: This test looks a bit hacky because there's no API to | ||
| // directly manipulate, or prevent the auto-manipulation of, the index | ||
| // inside a watch. I've added some comments below to make it make sense. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was originally written before we added the filter mechanism to simulate overflows. Now that we have that, this test can be simplified a lot (without the hacks).
| private static class Bookkeeper implements Consumer<WatchEvent> { | ||
| private final List<WatchEvent> events = Collections.synchronizedList(new ArrayList<>()); | ||
|
|
||
| public Stream<WatchEvent> events(WatchEvent.Kind... kinds) { | ||
| var list = Arrays.asList(kinds.length == 0 ? WatchEvent.Kind.values() : kinds); | ||
| return events.stream().filter(e -> list.contains(e.getKind())); | ||
| } | ||
|
|
||
| public Stream<Path> fullPaths(WatchEvent.Kind... kinds) { | ||
| return events(kinds).map(WatchEvent::calculateFullPath); | ||
| } | ||
|
|
||
| @Override | ||
| public void accept(WatchEvent e) { | ||
| events.add(e); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class was moved to TestHelper, so it can be reused across test classes. (Actually, after moving it, the class was rewritten quite a bit, but the idea remained the same.)
125ed84 to
9af3180
Compare
9af3180 to
21e1592
Compare
DavyLandman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few small things, looks good.
In #20, a number of tests were added for overflow handling. The bookkeeping code to keep track of actual events vs. expected events in those tests had two issues: (a) two tests still used counting of events, which can be unreliable; (b) a few other tests had roughly the same bookkeeping code duplicated.
This PR fixes these issues by adding a general
Bookkeepingclass that is: (a) not based on counting; (b) reused across tests.