You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@curator.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2021/08/08 04:00:11 UTC
[jira] [Work logged] (CURATOR-610) Refactor CountCuratorWatcher in
TestWatcherIdentity.java to improve test logic
[ https://issues.apache.org/jira/browse/CURATOR-610?focusedWorklogId=635670&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-635670 ]
ASF GitHub Bot logged work on CURATOR-610:
------------------------------------------
Author: ASF GitHub Bot
Created on: 08/Aug/21 04:00
Start Date: 08/Aug/21 04:00
Worklog Time Spent: 10m
Work Description: wx930910 opened a new pull request #397:
URL: https://github.com/apache/curator/pull/397
Fixes [CURATOR-610](https://issues.apache.org/jira/browse/CURATOR-610)
### Description
Refactor test class [CountCuratorWatcher](https://github.com/apache/curator/blob/4a11aaef8b190dc220d35b7a91df294bfa06250e/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java#L42) by using mocking object created by Mockito.
<hr>
##### Key changed/added classes in this PR
- Create mocking object to replace test subclass `CountCuratorWatcher`, decouple test from production code.
- Make test logic more clear by using method stub instead of method overriding.
- Extract AtomicInteger variable out of the test subclass. Use the extracted variable in assertation statement to check `process(WatchedEvent)` method invocation status.
<hr>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@curator.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Issue Time Tracking
-------------------
Worklog Id: (was: 635670)
Remaining Estimate: 0h
Time Spent: 10m
> 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
> Priority: Minor
> Time Spent: 10m
> Remaining Estimate: 0h
>
> 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)