[
https://issues.apache.org/jira/browse/PROTON-2431?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Xiao Wang updated PROTON-2431:
------------------------------
Description:
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.
was:
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.
> 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
> Priority: Minor
> Labels: unit-test
>
> 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: [email protected]
For additional commands, e-mail: [email protected]