Xiao Wang created CURATOR-610:
---------------------------------
Summary: Refactor CountCuratorWatcher in TestWatcherIdentity.java
to improve test logic
Key: CURATOR-610
URL: https://issues.apache.org/jira/browse/CURATOR-610
Project: Apache Curator
Issue Type: Improvement
Components: Framework
Reporter: Xiao Wang
h3. Description
I noticed that there is a test class
[CountCuratorWatcher|https://github.com/apache/curator/blob/4a11aaef8b190dc220d35b7a91df294bfa06250e/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java#L42]
implements production interface
[curatorWatcher|https://github.com/apache/curator/blob/4a11aaef8b190dc220d35b7a91df294bfa06250e/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorWatcher.java#L27]
to assist testing production class
[CuratorFrameworkImpl|https://github.com/apache/curator/blob/4a11aaef8b190dc220d35b7a91df294bfa06250e/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java#L66].
This might not be the best priactice in unit testing and can be improved by
leveraging mocking frameworks.
h3. 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)}}.
h3. 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.
h3. Motivation
- Decouple test class `CountCuratorWatcher` from production interface
`CuratorWatcher`.
- Make test logic more clear by using method stub instead of method overriding.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)