Xiao Wang created CONFIGURATION-810: ---------------------------------------
Summary: 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 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.3.4#803005)