Description
Description
I noticed that there is a test class CountCuratorWatcher implements production interface curatorWatcher to assist testing production class CuratorFrameworkImpl. This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.
Current Implementation
- CountCuratorWatcher implements CuratorWatcher and creates a new variable to keep tracking of the method invocation status for process(WatchedEvent).
- In test cases, after executing test target, the new variable will be used in assertion statement to check the execution status of process(WatchedEvent).
Proposed Implementation
- Replace CountCuratorWatcher with a mocking object created by Mockito.
- Extract the AtomicLong attribute and use the extracted attribute to check method invocation status.
- Use method stub to control the behavior of the mocking object.
Motivation
- Decouple test class `CountCuratorWatcher` from production interface `CuratorWatcher`.
- Make test logic more clear by using method stub instead of method overriding.