Uploaded image for project: 'Commons Pool'
  1. Commons Pool
  2. POOL-400

Refactor TestGenericObjectPoolFactoryCreateFailure to improve test design

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • None
    • None

    Description

      Description

      I noticed that there is a test class SingleObjectFactory extends production class BasePooledObjectFactory to assist testing method GenericObjectPool.borrowObject(). This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.

      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.

      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.

      Motivation

      • Decouple test class SingleObjectFactory from production interface BasePooledObjectFactory.
      • Make test logic more clear by using method stub instead of method overriding.

      Attachments

        Activity

          People

            Unassigned Unassigned
            wx930910 Xiao Wang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: