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

Justyna Kubica-Ledzion commented on COLLECTIONS-798:
----------------------------------------------------

Hi, I’ve prepared PR for this issue: 
https://github.com/apache/commons-collections/pull/278

Proposed changes:
 * replacing TestBuilder with a mocking object using Mockito,
 * stubbing method: {_}Builder with(byte[] item){_},
 * adding ArgumentCapture to check what parameters are passed to method 
{_}Builder with(byte[] item){_},
 * adding parameterized tests instead of _for_ loops.

Could you please review and let me know if my proposition is Ok?
I would appreciate any feedback.

Justyna

> Replace TestBuilder with mocking object to improve test design
> --------------------------------------------------------------
>
>                 Key: COLLECTIONS-798
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-798
>             Project: Commons Collections
>          Issue Type: Improvement
>            Reporter: Xiao Wang
>            Priority: Minor
>
> h3. Description
> I noticed that there is a test class 
> [TestBuilder|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/HasherBuilderTest.java#L41]
>  implements production interface 
> [Builder|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java#L35]
>  to assist testing methd [Builder:with(CharacterSequence, 
> Charset)|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java#L73].
>  This might not be the best priactice in unit testing and can be improved by 
> leveraging mocking frameworks.
> h3. Current Implementation
> *  {{TestBuilder}} implements {{Builder}} and creates a new list {{items}} to 
> keep tracking of the input parameters for {{with(byte[])}}.
> * In test cases, after executing test target, the list will be used in 
> assertion statement to check the input parameters of {{with(byte[])}}.
> h3. Proposed Implementation
>  * Replace {{TestBuilder}} with a mocking object created by Mockito.
>  * Extract the attribute into test cases to keep tracking input parameters.
>  * Use method stub to control the behavior of the mocking object.
> h3. Motivation
>  * Decouple test class {{TestBuilder}} from production interface {{Builder}}.
>  * Make test logic more clear by using method stub instead of method 
> overriding.
>  * Make test condition more explict by use local variable in test case.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to