[ 
https://issues.apache.org/jira/browse/CONFIGURATION-810?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17532005#comment-17532005
 ] 

Matt Juntunen commented on CONFIGURATION-810:
---------------------------------------------

Thank you for your PR! Your rationale is good and your issue description is 
very clearly structured. However, I don't believe this change is necessary for 
the following reasons:
1. It adds a new dependency on mockito when, for better or worse, the project 
already has a dependency on [easymock|https://easymock.org/]. Having two 
mocking frameworks in the same project will be confusing.
2. I typically avoid mocking or otherwise modifying the actual object under 
test because it is not obvious how the mocking framework is modifying or 
extending the object. With {{DummyLayout}}, the modification is clear: the 
class under test is being extended, a single method is overridden, and all 
other behavior is the same. Note that I'm not saying that mockito isn't doing 
this internally; I'm saying that this fact is not clear from just looking at 
the test.
3. The use case for {{DummyLayout}} is very simple and not much longer than the 
mocked version.

> Refactor DummyLayout in TestPropertiesConfiguration to improve test design
> --------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-810
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-810
>             Project: Commons Configuration
>          Issue Type: Improvement
>            Reporter: Xiao Wang
>            Priority: Minor
>
> h3. Description
> I noticed that there is a test class 
> [DummyLayout|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java#L91]
>  implements production class 
> [PropertiesConfigurationLayout|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java#L102]
>  to assist testing method [PropertiesConfiguration.propertyLoaded(String, 
> String, 
> Deque<URL>)|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java#L1467].
>  This might not be the best priactice in unit testing and can be improved by 
> leveraging mocking frameworks.
> h3. Current Implementation
>  * {{DummyLayout}} extends {{PropertiesConfigurationLayout}} and creates a 
> new variable to keep tracking of the method invocation status for 
> {{load(PropertiesConfiguration, Reader)}}.
>  * In test cases, after executing 
> {{PropertiesConfiguration.propertyLoaded(String, String, Deque<URL>)}}, the 
> new variable will be used in assertion statement to check the execution 
> status of {{load(PropertiesConfiguration, Reader)}}.
> h3. Proposed Implementation
>  * Replace {{DummyLayout}} with a mocking object created by Mockito.
>  * Remove the {{int}} variable that used to keep tracking the invocation 
> times of {{load(PropertiesConfiguration, Reader)}}.
>  * Use {{Mockito.verify()}} to check execution status of 
> {{load(PropertiesConfiguration, Reader)}}.
> h3. Motivation
>  * Decouple test class {{DummyLayout}} from production class 
> {{PropertiesConfigurationLayout}}.
>  * Make test logic more clear by removing the overridden method in 
> {{DummyLayout}}.
>  * Make test condition more explict by directly using {{Mockito.verify()}} to 
> verify method execution status.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to