Xiao Wang created POOL-400:
------------------------------
Summary: Refactor TestGenericObjectPoolFactoryCreateFailure to
improve test design
Key: POOL-400
URL: https://issues.apache.org/jira/browse/POOL-400
Project: Commons Pool
Issue Type: Improvement
Reporter: Xiao Wang
h3. Description
I noticed that there is a test class
[SingleObjectFactory|https://github.com/apache/commons-pool/blob/dbb4ca0bc969464f31435867a0800fc766f31068/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPoolFactoryCreateFailure.java#L38]
extends production class
[BasePooledObjectFactory|https://github.com/apache/commons-pool/blob/dbb4ca0bc969464f31435867a0800fc766f31068/src/main/java/org/apache/commons/pool2/BasePooledObjectFactory.java#L33]
to assist testing method
[GenericObjectPool.borrowObject()|https://github.com/apache/commons-pool/blob/dbb4ca0bc969464f31435867a0800fc766f31068/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java#L222].
This might not be the best priactice in unit testing and can be improved by
leveraging mocking frameworks.
h3. Current Implementation
* {{SingleObjectFactory}} extends {{BasePooledObjectFactory}} and creates a
new variable to keep tracking of the method invocation status for {{created()}}.
* In test case, the new variable will be used to check the execution status
and wait {{created()}} to be excuted.
h3. Proposed Implementation
* Replace {{SingleObjectFactory}} with a mocking object created by Mockito.
* Extract the AtomicBoolean attribute and use the extracted attribute in test
case to check method invocation status.
* Use method stub to control the behavior of the mocking object.
h3. Motivation
* Decouple test class {{SingleObjectFactory}} from production interface
{{BasePooledObjectFactory}}.
* Make test logic more clear by using method stub instead of method overriding.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)