You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by "Xiao Wang (Jira)" <ji...@apache.org> on 2021/09/06 01:42:00 UTC
[jira] [Created] (PROTON-2431) Refactor SinkHandler in
ReactorTest.java to improve test design
Xiao Wang created PROTON-2431:
---------------------------------
Summary: Refactor SinkHandler in ReactorTest.java to improve test design
Key: PROTON-2431
URL: https://issues.apache.org/jira/browse/PROTON-2431
Project: Qpid Proton
Issue Type: Improvement
Components: proton-j
Reporter: Xiao Wang
h3. Description
I noticed that there is a test class [SinkHandler|https://github.com/apache/qpid-proton-j/blob/c242c260e44d94bba1a9c82a22af3b0b2a0dc5c6/proton-j/src/test/java/org/apache/qpid/proton/reactor/ReactorTest.java#L388] implements production class [BaseHandler|https://github.com/apache/qpid-proton-j/blob/c242c260e44d94bba1a9c82a22af3b0b2a0dc5c6/proton-j/src/main/java/org/apache/qpid/proton/engine/BaseHandler.java#L32] to assist testing methd [ReactorImpl:run()|https://github.com/apache/qpid-proton-j/blob/c242c260e44d94bba1a9c82a22af3b0b2a0dc5c6/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/ReactorImpl.java#L354]. This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.
h3. Current Implementation
* {{SinkHandler}} implements {{BaseHandler}} and creates a new variable to keep tracking of the method invocation status for {{onDelivery(Devent)}}.
* In test cases, after executing test target, the new variable will be used in assertion statement to check the execution status of {{onDelivery(Devent)}}.
h3. Proposed Implementation
* Replace {{SinkHandler}} with a mocking object created by Mockito.
* Extract the attribute into {{transfer(int, int)}} to surface counting logic.
* Use method stub to control the behavior of the mocking object.
h3. Motivation
- Decouple test class `SinkHandler` from production class `BaseHandler`.
- Make test logic more clear by using method stub instead of method overriding.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org