Xiao Wang created BEANUTILS-551:
-----------------------------------
Summary: Refactor IntrospectionContextTestImpl in
SuppressPropertiesBeanIntrospectorTestCase.java to improve test design
Key: BEANUTILS-551
URL: https://issues.apache.org/jira/browse/BEANUTILS-551
Project: Commons BeanUtils
Issue Type: Improvement
Reporter: Xiao Wang
h3. Description
I noticed that there is a test class
[IntrospectionContextTestImpl|https://github.com/apache/commons-beanutils/blob/7196d86767e37a382329bb3b087d0f58c7301caf/src/test/java/org/apache/commons/beanutils2/SuppressPropertiesBeanIntrospectorTestCase.java#L101]
implements production interface
[IntrospectionContext|https://github.com/apache/commons-beanutils/blob/7196d86767e37a382329bb3b087d0f58c7301caf/src/main/java/org/apache/commons/beanutils2/IntrospectionContext.java#L38]
to assist testing methd
[SuppressPropertiesBeanIntrospector:introspect(IntrospectionContext)|https://github.com/apache/commons-beanutils/blob/7196d86767e37a382329bb3b087d0f58c7301caf/src/main/java/org/apache/commons/beanutils2/SuppressPropertiesBeanIntrospector.java#L86].
This might not be the best priactice in unit testing and can be improved by
leveraging mocking frameworks.
h3. Current Implementation
* {{IntrospectionContextTestImpl}} implements {{IntrospectionContext}} and
creates a new variable to keep tracking of the input parameters for
{{removePropertyDescriptor(String)}}.
* In test cases, after executing test target, a set will be used in assertion
statement to check the input parameters of {{removePropertyDescriptor(String)}}.
h3. Proposed Implementation
* Replace {{IntrospectionContextTestImpl}} with a mocking object created by
Mockito.
* Extract the attribute into test cases to surface counting logic.
* Use method stub to control the behavior of the mocking object.
h3. Motivation
- Decouple test class {{IntrospectionContextTestImpl}} from production
interface {{IntrospectionContext}}.
- Make test logic more clear by using method stub instead of method overriding.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)